asp.net - Static and non-static version of the same function in C# -
i have own implementation of getuserid()
function made static able retrieve id in static context. have many places use standard getuserid()
function built asp.net usermanager library. fix not using different logic same thing overriding non-static method , using static 1 inside (this inside usermanagerservice class):
public override string getuserid(claimsprincipal user) { return getuseridstatic(user); } public static string getuseridstatic(claimsprincipal user) { return user.findfirst(claimtypes.nameidentifier).value; }
i did because prefer call non-static method in non-static context (generally it's on 90% of calls). prefer call _usermanagerservice.getuserid(user)
usermanagerservice.getuseridstatic(user)
whenever can.
from readability , maintainability perspective (and eventual harmful consequences can't foresee right now) better way described above; switch calls static version; or other way didn't think of?
making static , non-static versions of method same thing highly questionable.
you should replace static method user id static method or static property user manager service. let obtain user id in static context calling non-static method:
var userid = staticgetusermanagerserice().getuseridstatic(user);
or
var userid = usermanagerserice.instance.getuseridstatic(user);
Comments
Post a Comment