static internal bool IsProtectedFieldAttributes(FieldAttributes attributes)
 {
     return
         (attributes.HasFlag(FieldAttributes.Family) ||
          attributes.HasFlag(FieldAttributes.FamANDAssem) ||
          attributes.HasFlag(FieldAttributes.FamORAssem) && !attributes.HasFlag(MethodAttributes.Assembly));
 }
Beispiel #2
0
        private string GetFieldAttributes(FieldAttributes attr)
        {
            string result = "";

            if (attr.HasFlag(FieldAttributes.Public))
            {
                result += "public ";
            }
            else
            {
                if (attr.HasFlag(FieldAttributes.Family))
                {
                    result += "protected ";
                }
                else
                {
                    result += "private";
                }
            }
            if (attr.HasFlag(FieldAttributes.Assembly))
            {
                result += "iternal ";
            }
            if (attr.HasFlag(FieldAttributes.Static))
            {
                result += "static ";
            }
            if (attr.HasFlag(FieldAttributes.Literal))
            {
                result += "const ";
            }
            return(result.Remove(result.Length - 1));
        }
Beispiel #3
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (access.HasFlag(FieldAttributes.Public))
            {
                sb.Append("public ");
            }
            else if (access.HasFlag(FieldAttributes.Family))
            {
                sb.Append("protected ");
            }
            else if (access.HasFlag(FieldAttributes.Private))
            {
                sb.Append("private ");
            }
            if (access.HasFlag(FieldAttributes.Static))
            {
                sb.Append("static ");
            }
            if (access.HasFlag(FieldAttributes.InitOnly))
            {
                sb.Append("final ");
            }
            sb.Append(Type.ClassName).Append(' ');
            if (owner != null)
            {
                sb.Append(owner.ClassName).Append('.');
            }
            sb.Append(name);
            return(sb.ToString());
        }
Beispiel #4
0
        /// <summary>
        /// The backing field of a WinRT enumeration type is not public although the backing fields
        /// of managed enumerations are. To allow managed languages to directly access this field,
        /// it is made public by the metadata adapter.
        /// </summary>
        private void ModifyFieldDefProps(FieldHandle fieldDef, string name, ref FieldAttributes flags)
        {
            if (name == "value__" && flags.HasFlag(FieldAttributes.RTSpecialName))
            {
                TypeHandle typeDef = FindContainingType(fieldDef);
                Debug.Assert(!typeDef.IsNil);

                MetadataToken extendsRef = GetTypeDefExtends(typeDef);
                if (extendsRef.HandleType == HandleType.TypeReference)
                {
                    string        extendsName, extendsNamespace;
                    MetadataToken unused;
                    GetTypeRefProps(
                        (TypeReferenceHandle)extendsRef,
                        out extendsName,
                        out extendsNamespace,
                        out unused);
                    if (extendsName == "Enum" && extendsNamespace == "System")
                    {
                        flags  = flags & ~FieldAttributes.Private;
                        flags |= FieldAttributes.Public;
                    }
                }
            }
        }
Beispiel #5
0
 public AsmFieldBuilder(IType declaringType, IType fieldType, FieldAttributes fieldAttributes, string name)
 {
     DeclaringType   = declaringType;
     Name            = name;
     FieldType       = fieldType;
     FieldAttributes = fieldAttributes;
     IsStatic        = fieldAttributes.HasFlag(FieldAttributes.Static);
 }
Beispiel #6
0
 string[] GetIcons(string b, FieldAttributes a)
 {
     if (a.HasFlag(FieldAttributes.Private))
     {
         return(GetIconsStub(b, "Private"));
     }
     return(GetIconsStub(b, string.Empty));
 }
Beispiel #7
0
 internal static bool DoNotNeedToSaveType(this Type fieldType, FieldAttributes fieldAttributes)
 {
     return(fieldAttributes.HasFlag(FieldAttributes.NotSerialized) ||
            fieldType == typeof(Action) || fieldType == typeof(Action <>) ||
            fieldType.BaseType == typeof(MulticastDelegate) || fieldType == typeof(BinaryWriter) ||
            fieldType == typeof(BinaryReader) || fieldType == typeof(Pointer) ||
            fieldType == typeof(IntPtr) || fieldType == typeof(ISerializable));
 }
Beispiel #8
0
        public FieldBuilder DefineField(string fieldName, Type fieldType, FieldAttributes attributes)
        {
            FieldBuilder fieldBuilder = typeBuilder.DefineField(fieldName, fieldType, attributes);

            if (!attributes.HasFlag(FieldAttributes.Static))
            {
                fieldBuilder.SetCustomAttribute(new CustomAttributeBuilder(Constructors.XmlIgnoreAttributeConstructor, new object[0]));
            }
            fields.Add(fieldBuilder);
            return(fieldBuilder);
        }
        private static Expression VisitFieldMemberExpression(MemberExpression node, FieldInfo fieldInfo)
        {
            FieldAttributes fieldAttributes = fieldInfo.Attributes;

            bool isPrivateField = fieldAttributes.HasFlag(FieldAttributes.Private) ||
                                  fieldAttributes.HasFlag(FieldAttributes.PrivateScope);

            if (isPrivateField)
            {
                var argument = node.Expression ?? ExpressionExtensions.Null;

                return(Expression.Call(null,
                                       typeof(AccessPrivateFieldVisitor).GetMethod("GetFieldValue"),
                                       fieldInfo.DeclaringType.AssemblyQualifiedName.Constant(),
                                       fieldInfo.Name.Constant(),
                                       argument).Convert(node.Type));
            }

            return(node);
        }
Beispiel #10
0
        public Field(FieldInfo fieldInfo)
        {
            FieldAttributes attributes = fieldInfo.Attributes;

            if (attributes.HasFlag(FieldAttributes.Public))
            {
                Signature = "public ";
            }
            else if (attributes.HasFlag(FieldAttributes.Private))
            {
                Signature = "private ";
            }
            else if (attributes.HasFlag(FieldAttributes.Family))
            {
                Signature = "protected ";
            }
            else if (attributes.HasFlag(FieldAttributes.Assembly))
            {
                Signature = "internal ";
            }

            if (attributes.HasFlag(FieldAttributes.Static))
            {
                Signature = Signature + "static ";
            }
            else if (attributes.HasFlag(FieldAttributes.InitOnly))
            {
                Signature = Signature + "readonly ";
            }

            string retType;

            retType   = Model.GetTypeName(fieldInfo.FieldType);
            Signature = Signature + retType + " " + fieldInfo.Name;
        }
        private enum_DBG_ATTRIB_FLAGS GetAttributeInfo(FieldAttributes attributes)
        {
            enum_DBG_ATTRIB_FLAGS attributeInfo = enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_NONE;

            if (attributes.HasFlag(FieldAttributes.Private))
            {
                attributeInfo |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PRIVATE;
            }
            if (attributes.HasFlag(FieldAttributes.Public))
            {
                attributeInfo |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PUBLIC;
            }
            if (attributes.HasFlag(FieldAttributes.Family))
            {
                attributeInfo |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_ACCESS_PROTECTED;
            }
            if (attributes.HasFlag(FieldAttributes.Static))
            {
                attributeInfo |= enum_DBG_ATTRIB_FLAGS.DBG_ATTRIB_STORAGE_STATIC;
            }

            return(attributeInfo);
        }
Beispiel #12
0
        private void AddModifiers(FieldAttributes attributes, MutableSymbol symbolToAdd)
        {
            SymbolModifier modifiers = symbolToAdd.Modifiers;

            // Same as Roslyn PEFieldSymbol.DeclaredAccessibility
            switch (attributes & FieldAttributes.FieldAccessMask)
            {
            case FieldAttributes.Assembly:
                modifiers = SymbolModifier.Internal;
                break;

            case FieldAttributes.FamORAssem:
            case FieldAttributes.FamANDAssem:
                modifiers = SymbolModifier.Protected | SymbolModifier.Internal;
                break;

            case FieldAttributes.Private:
            case FieldAttributes.PrivateScope:
                modifiers = SymbolModifier.Private;
                break;

            case FieldAttributes.Public:
                modifiers = SymbolModifier.Public;
                break;

            case FieldAttributes.Family:
                modifiers = SymbolModifier.Protected;
                break;
            }

            if (attributes.HasFlag(FieldAttributes.Static))
            {
                modifiers |= SymbolModifier.Static;
            }

            symbolToAdd.Modifiers = modifiers;
        }
Beispiel #13
0
        /// <summary>
        /// Defines a new field to the type.
        /// </summary>
        /// <param name="name">The name of the field. <paramref name="name"/> cannot contain embedded nulls.</param>
        /// <param name="type">The type of the field/</param>
        /// <param name="attributes">A bitwise combination of the field attributes.</param>
        /// <param name="initializer">The expression which is not reduced to be <see cref="LambdaExpression"/> for the initializer of the field, with a parameter for "this" instance, returns <paramref name="type"/> value.</param>
        /// <returns>The defined field.</returns>
        public FieldBuilder DefineField(
            String name,
            Type type,
            FieldAttributes attributes,
            Expression initializer
            )
        {
            var isStatic = attributes.HasFlag(FieldAttributes.Static);

            return(this._type.DefineField(
                       name,
                       type,
                       attributes
                       )
                   .If(_ => initializer != null, f =>
                       this._implType.DefineMethod(
                           GetName(f, "Init"),
                           MethodAttributes.Assembly | MethodAttributes.Static,
                           type,
                           isStatic ? Type.EmptyTypes : this._typeArray
                           )
                       .Apply(
                           i =>
                           (isStatic
                                ? (this._cctor ?? (this._cctor = this._type.DefineTypeInitializer())).GetILGenerator()
                                : this._prologue.GetILGenerator()
                           )
                           .Apply(
                               g => g.If(_ => !isStatic, _ => LoadArgs(g, 0, 0)),
                               g => g.Emit(OpCodes.Call, i),
                               g => g.Emit(isStatic ? OpCodes.Stsfld : OpCodes.Stfld, f)
                               ),
                           i => this.RequestInitializing(i, initializer, type, isStatic ? this._typeArray : Type.EmptyTypes)
                           )
                       )
                   .Apply(this._members.Add));
        }
Beispiel #14
0
        /// <summary>
        /// The backing field of a WinRT enumeration type is not public although the backing fields
        /// of managed enumerations are. To allow managed languages to directly access this field,
        /// it is made public by the metadata adapter.
        /// </summary>
        private void ModifyFieldDefProps(FieldHandle fieldDef, string name, ref FieldAttributes flags)
        {
            if (name == "value__" && flags.HasFlag(FieldAttributes.RTSpecialName))
            {
                TypeHandle typeDef = FindContainingType(fieldDef);
                Debug.Assert(!typeDef.IsNil);

                MetadataToken extendsRef = GetTypeDefExtends(typeDef);
                if (extendsRef.HandleType == HandleType.TypeReference)
                {
                    string extendsName, extendsNamespace;
                    MetadataToken unused;
                    GetTypeRefProps(
                        (TypeReferenceHandle)extendsRef,
                        out extendsName,
                        out extendsNamespace,
                        out unused);
                    if (extendsName == "Enum" && extendsNamespace == "System")
                    {
                        flags = flags & ~FieldAttributes.Private;
                        flags |= FieldAttributes.Public;
                    }
                }
            }
        }
 internal static bool IsStaticFieldAttributes(FieldAttributes attributes)
 {
     return(attributes.HasFlag(FieldAttributes.Static));
 }
Beispiel #16
0
 /// <summary>
 /// Defines a new field to the type.
 /// </summary>
 /// <param name="name">The name of the field. <paramref name="name"/> cannot contain embedded nulls.</param>
 /// <param name="type">The type of the field/</param>
 /// <param name="attributes">A bitwise combination of the field attributes.</param>
 /// <param name="initializer">The expression which is not reduced to be <see cref="LambdaExpression"/> for the initializer of the field, with a parameter for "this" instance, returns <paramref name="type"/> value.</param>
 /// <returns>The defined field.</returns>
 public FieldBuilder DefineField(
     String name,
     Type type,
     FieldAttributes attributes,
     Expression initializer
 )
 {
     var isStatic = attributes.HasFlag(FieldAttributes.Static);
     return this._type.DefineField(
         name,
         type,
         attributes
     )
         .If(_ => initializer != null, f =>
             this._implType.DefineMethod(
                 GetName(f, "Init"),
                 MethodAttributes.Assembly | MethodAttributes.Static,
                 type,
                 isStatic ? Type.EmptyTypes : this._typeArray
             )
             .Apply(
                 i =>
                     (isStatic
                         ? (this._cctor ?? (this._cctor = this._type.DefineTypeInitializer())).GetILGenerator()
                         : this._prologue.GetILGenerator()
                     )
                     .Apply(
                     g => g.If(_ => !isStatic, _ => LoadArgs(g, 0, 0)),
                     g => g.Emit(OpCodes.Call, i),
                     g => g.Emit(isStatic ? OpCodes.Stsfld : OpCodes.Stfld, f)
                 ),
                 i => this.RequestInitializing(i, initializer, type, isStatic ? this._typeArray : Type.EmptyTypes)
             )
         )
         .Apply(this._members.Add);
 }
Beispiel #17
0
 string[] GetIcons(string b, FieldAttributes a)
 {
     if (a.HasFlag(FieldAttributes.Private)) return GetIconsStub(b, "Private");
     return GetIconsStub(b, string.Empty);
 }