-2

I was looking for information about this structure but I could't found it; so if someone have time to explain this or point to some URl where it's explained.

I found this definition at function sin web C# applications as for example:

  public static class PrincipalExtensions
{
    public static Site.Web.Models.SiteIdentity SiteIdentity(this System.Security.Principal.IPrincipal principal)
    {
       .....
       }

 }
BenMorel
  • 34,448
  • 50
  • 182
  • 322
jlsfernandez
  • 160
  • 3
  • 16

2 Answers2

6

This is an extension method. See the following article for detailed information : http://msdn.microsoft.com/en-us/library/bb383977.aspx

Short version : this constructs enables you to make some methods available to be called on a class instance, even if you cannot (or do not) want to inherit from the class. It will not give you access to protected or private members/fields/methods.

Most notable usage : extension methods on IEnumerable / IQueryable in System.Linq namespace.

mathieu
  • 30,974
  • 4
  • 64
  • 90
  • Also his question has a lot to do with ASP, hence the "Site.Web.Models.SiteIdentity" – tcables Aug 16 '12 at 13:56
  • 1
    It's worth noting that it doesn't actually add methods to a class, it just provides syntax that makes it appear as if the method was added to the class. The method itself is just a static method, even when it's an extension method. (While this doesn't seem meaningful, it really is significant.) – Servy Aug 16 '12 at 13:58
2

This is an extension method for IPrincipal which returns an object of a custom type Site.Web.Models.SiteIdentity.

A principal object represents the security context of the user on whose behalf the code is running, including that user's identity (IIdentity) and any roles to which they belong.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348