Esempio n. 1
0
        public static void MakeAccessible(this FieldDef field, AccessLevel level)
        {
            if (field.IsAccessible(level))
            {
                return;
            }
            FieldAttributes attributes = field.Attributes & ~FieldAttributes.FieldAccessMask;

            switch (level)
            {
            default:
                return;

            case AccessLevel.Private:
                attributes |= FieldAttributes.Private;
                break;

            case AccessLevel.FamilyAndAssembly:
                attributes |= FieldAttributes.FamANDAssem;
                break;

            case AccessLevel.Family:
                attributes |= field.IsAssembly ? FieldAttributes.FamORAssem : FieldAttributes.Family;
                break;

            case AccessLevel.Assembly:
                attributes |= field.IsFamily ? FieldAttributes.FamORAssem : FieldAttributes.Assembly;
                break;

            case AccessLevel.FamilyOrAssembly:
                attributes |= FieldAttributes.FamORAssem;
                break;

            case AccessLevel.Public:
                attributes |= FieldAttributes.Public;
                break;
            }
            field.Attributes = attributes;
        }