Пример #1
0
 /// <summary>
 /// Initializes a new instance of <see cref="RuntimeMember"/>.
 /// </summary>
 /// <param name="token">Holds the token of this runtime metadata.</param>
 /// <param name="module">The module.</param>
 /// <param name="declaringType">The declaring type of the member.</param>
 /// <param name="attributes">Holds the attributes of the member.</param>
 protected RuntimeMember(int token, IMetadataModule module, RuntimeType declaringType, RuntimeAttribute[] attributes)
     : base(token)
 {
     this.module = module;
     this.declaringType = declaringType;
     this.attributes = attributes;
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="RuntimeMember"/>.
 /// </summary>
 /// <param name="moduleTypeSystem">The module type system.</param>
 /// <param name="token">Holds the token of this runtime metadata.</param>
 /// <param name="declaringType">The declaring type of the member.</param>
 /// <param name="attributes">Holds the attributes of the member.</param>
 protected RuntimeMember(IModuleTypeSystem moduleTypeSystem, int token, RuntimeType declaringType, RuntimeAttribute[] attributes)
     : base(moduleTypeSystem, token)
 {
     this.declaringType = declaringType;
     this.attributes = attributes;
 }
Пример #3
0
        /// <summary>
        /// Sets the attributes of this member.
        /// </summary>
        /// <param name="attributes">The attributes.</param>
        internal void SetAttributes(RuntimeAttribute[] attributes)
        {
            if (null != this.attributes)
                throw new InvalidOperationException(@"Can't set attributes twice.");

            this.attributes = attributes;
        }
        /// <summary>
        /// Sets the attributes.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="attributes">The attributes.</param>
        private void SetAttributes(TokenTypes owner, List<CustomAttributeRow> attributes)
        {
            // Convert the custom attribute rows to RuntimeAttribute instances
            RuntimeAttribute[] ra = new RuntimeAttribute[attributes.Count];
            for (int i = 0; i < attributes.Count; i++)
                ra[i] = new RuntimeAttribute(this, attributes[i]);

            // The following switch matches the AttributeTargets enumeration against
            // metadata tables, which make valid targets for an attribute.
            switch (owner & TokenTypes.TableMask)
            {
                case TokenTypes.Assembly:
                    // AttributeTargets.Assembly
                    break;

                case TokenTypes.TypeDef:
                    // AttributeTargets.Class
                    // AttributeTargets.Delegate
                    // AttributeTargets.Enum
                    // AttributeTargets.Interface
                    // AttributeTargets.Struct
                    RuntimeType type = ((IModuleTypeSystem)this).GetType(owner);
                    type.SetAttributes(ra);
                    break;

                case TokenTypes.MethodDef:
                    // AttributeTargets.Constructor
                    // AttributeTargets.Method
                    RuntimeMethod method = ((IModuleTypeSystem)this).GetMethod(owner);
                    method.SetAttributes(ra);
                    break;

                case TokenTypes.Event:
                    // AttributeTargets.Event
                    break;

                case TokenTypes.Field:
                    // AttributeTargets.Field
                    RuntimeField field = ((IModuleTypeSystem)this).GetField(owner);
                    field.SetAttributes(ra);
                    break;

                case TokenTypes.GenericParam:
                    // AttributeTargets.GenericParameter
                    break;

                case TokenTypes.Module:
                    // AttributeTargets.Module
                    break;

                case TokenTypes.Param:
                    // AttributeTargets.Parameter
                    // AttributeTargets.ReturnValue
                    break;

                case TokenTypes.Property:
                    // AttributeTargets.StackFrameIndex
                    break;
            }
        }
Пример #5
0
        /// <summary>
        /// Sets the attributes.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="owner">The owner.</param>
        /// <param name="attributes">The attributes.</param>
        private void SetAttributes(IMetadataModule module, TokenTypes owner, List <CustomAttributeRow> attributes)
        {
            ITypeSystem ts = (ITypeSystem)this;

            // Convert the custom attribute rows to RuntimeAttribute instances
            RuntimeAttribute[] ra = new RuntimeAttribute[attributes.Count];
            for (int i = 0; i < attributes.Count; i++)
            {
                ra[i] = new RuntimeAttribute(module, attributes[i]);
            }

            // The following switch matches the AttributeTargets enumeration against
            // metadata tables, which make valid targets for an attribute.
            switch (owner & TokenTypes.TableMask)
            {
            case TokenTypes.Assembly:
                // AttributeTargets.Assembly
                break;

            case TokenTypes.TypeDef:
                // AttributeTargets.Class
                // AttributeTargets.Delegate
                // AttributeTargets.Enum
                // AttributeTargets.Interface
                // AttributeTargets.Struct
                RuntimeType type = ts.GetType(module, owner);
                type.SetAttributes(ra);
                if (rtCallTypeAttribute != null)
                {
                    if (type.IsDefined(rtCallTypeAttribute) == true)
                    {
                        this.internalTypes.Add(type);
                    }
                }
                break;

            case TokenTypes.MethodDef:
                // AttributeTargets.Constructor
                // AttributeTargets.Method
                RuntimeMethod method = ts.GetMethod(module, owner);
                method.SetAttributes(ra);
                break;

            case TokenTypes.Event:
                // AttributeTargets.Event
                break;

            case TokenTypes.Field:
                // AttributeTargets.Field
                break;

            case TokenTypes.GenericParam:
                // AttributeTargets.GenericParameter
                break;

            case TokenTypes.Module:
                // AttributeTargets.Module
                break;

            case TokenTypes.Param:
                // AttributeTargets.Parameter
                // AttributeTargets.ReturnValue
                break;

            case TokenTypes.Property:
                // AttributeTargets.StackFrameIndex
                break;
            }
        }