Wednesday, 15 September 2010

.net - How does Type.Attributes of C# work? -



.net - How does Type.Attributes of C# work? -

so system.type has instance method called attributes.

public typeattributes attributes { get; }

which returns enum of type typeattributes. here members of enum:

public enum typeattributes { ansiclass = 0, class = 0, autolayout = 0, notpublic = 0, public = 1, nestedpublic = 2, nestedprivate = 3, nestedfamily = 4, nestedassembly = 5, nestedfamandassem = 6, visibilitymask = 7, nestedfamorassem = 7, sequentiallayout = 8, explicitlayout = 16, layoutmask = 24, ... }

but on other hand, type class has provides many properties of stuff appear in enum:

ispublic isclass isnestedfamandassem isautolayout ...

so type.attributes for? guess not bitmasked value, since enum , returns single fellow member of enum. , not static property on type class,so do?

type.attributes bitmasked value. says in documentation.

enums commonly used flag info types decorating them flags attribute.

and properties of type, ispublic, isclass etc. check flags , homecoming boolean value. can see looking @ definitions using reflector.

ispublic, illustration this:

public bool ispublic { { homecoming ((this.attributes & typeattributes.visibilitymask) == typeattributes.public); } }

not properties of type represent 1 of flags though (like isenum).

c# .net system.reflection

No comments:

Post a Comment