예제 #1
0
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            Universe u = this.Module.universe;

            if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_FieldOffsetAttribute)
            {
                customBuilder = customBuilder.DecodeBlob(this.Module.Assembly);
                SetOffset((int)customBuilder.GetConstructorArgument(0));
            }
            else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute)
            {
                MarshalSpec.SetMarshalAsAttribute(typeBuilder.ModuleBuilder, pseudoToken, customBuilder);
                attribs |= FieldAttributes.HasFieldMarshal;
            }
            else if (customBuilder.Constructor.DeclaringType == u.System_NonSerializedAttribute)
            {
                attribs |= FieldAttributes.NotSerialized;
            }
            else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
            {
                attribs |= FieldAttributes.SpecialName;
            }
            else
            {
                typeBuilder.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
            }
        }
예제 #2
0
        public void SetCustomAttribute(CustomAttributeBuilder customAttributeBuilder)
        {
            Universe u = moduleBuilder.universe;

            if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_InAttribute)
            {
                flags |= (short)ParameterAttributes.In;
            }
            else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OutAttribute)
            {
                flags |= (short)ParameterAttributes.Out;
            }
            else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OptionalAttribute)
            {
                flags |= (short)ParameterAttributes.Optional;
            }
            else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute)
            {
                MarshalSpec.SetMarshalAsAttribute(moduleBuilder, PseudoToken, customAttributeBuilder);
                flags |= (short)ParameterAttributes.HasFieldMarshal;
            }
            else
            {
                moduleBuilder.SetCustomAttribute(PseudoToken, customAttributeBuilder);
            }
        }