Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Static method in the public class
Message
De
10/08/2016 04:26:07
 
 
À
10/08/2016 04:21:21
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 5.0
OS:
Windows 10
Database:
MS SQL Server
Divers
Thread ID:
01639234
Message ID:
01639304
Vues:
37
>>>>Hi everybody,
>>>>
>>>>We have the following class:
>>>>
>>>>
>>>> [Serializable]
>>>>    public class OperatorSession
>>>>    {
>>>>        public OperatorSession()
>>>>        {
>>>>            Rights = new string[0];
>>>>            Roles = new List<SecRole>();
>>>>        }
>>>>
>>>>        public string OpCode { get; set; }'
>>>>        etc.
>>>>
>>>>
>>>>      public static bool IsAdmin(string opCode)
>>>>        {
>>>>            return !String.IsNullOrEmpty(opCode) && opCode.Trim().ToLower() == SysManagerConstants.ADMIN_OPCODE.ToLower();
>>>>        }
>>>>
>>>>
>>>>The problem here is that IsAdmin definition changed. Now in addition of the opCode being some specific code this method should also return true when the operator has the following role X_SYSADMIN.
>>>>
>>>>I am not able to add a check for Rights.contains in the static method and so I'm at loss as how can I check what I need to check.
>>>>
>>>>My other problem is that OperatorSession class is defined in the Models project. This project only contains classes definitions and it doesn't reference anything else. There is another project called Data which has Models as a reference. So, from the OperatorSession I can not even access DbSet to try to get an instance of the operator by the code to check operator's roles.
>>>>
>>>>I also checked that we do use something like this in the code:
>>>>
>>>>return OperatorSession.IsAdmin(id) || rights.Contains("SEC_OEDIT");
>>>>
>>>>
>>>>
>>>>I guess I need to create a different non static method to check if operator is an admin.
>>>>
>>>>Thanks in advance.
>>>>
>>>>UPDATE. Apparently I would have to create another static method and will have to pass operator's rights to it. Then I would need to check all calls to the original method and somehow adjust.
>>>
>>>Why do you use a static method?
>>> An instance of the class is obviously being instantiated anyway so I see no real benefit?
>>
>>Because you don't have to remember where you've kept that instance ?
>
>Hmm - but the new use of the static method requires the non-static 'rights' property so there must be an already known instance of the class.....

Maybe so, it's not clear to me whether rights is static
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform