Skip to content

Instantly share code, notes, and snippets.

@jcdickinson
Created February 9, 2011 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcdickinson/819221 to your computer and use it in GitHub Desktop.
Save jcdickinson/819221 to your computer and use it in GitHub Desktop.
Simplify Cecil TypeAttributes
[Flags]
public enum CSharpTypeAttributes
{
Private = 0,
Public = 1,
Internal = 2,
Protected = 4,
ProtectedInternal = Protected | Internal,
}
public static CSharpTypeAttributes SimplifyAttributes(this TypeDefinition def)
{
if (def.IsPublic)
return CSharpTypeAttributes.Public;
if (!def.IsNested)
return CSharpTypeAttributes.Internal;
if (def.IsNestedFamilyOrAssembly)
return CSharpTypeAttributes.ProtectedInternal;
if (def.IsNestedAssembly)
return CSharpTypeAttributes.Internal;
if (def.IsNestedFamily)
return CSharpTypeAttributes.Protected;
return CSharpTypeAttributes.Private;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment