SetCustomAttribute() public method

public SetCustomAttribute ( System customBuilder ) : void
customBuilder System
return void
Esempio n. 1
0
 public static void SetCustomAttributes(FieldBuilder fb, IPersistentMap attributes)
 {
     for (ISeq s = RT.seq(attributes); s != null; s = s.next())
         fb.SetCustomAttribute(CreateCustomAttributeBuilder((IMapEntry)(s.first())));
 }
            private static void MarkAsNotSerializable(FieldBuilder field)
            {
                var emptyArray = new object[0];

                field.SetCustomAttribute(new CustomAttributeBuilder(_nonSerializedAttributeConstructor, emptyArray));

                if (field.IsPublic)
                {
                    field.SetCustomAttribute(new CustomAttributeBuilder(_ignoreDataMemberAttributeConstructor, emptyArray));
                    field.SetCustomAttribute(new CustomAttributeBuilder(_xmlIgnoreAttributeConstructor, emptyArray));

                    if (_scriptIgnoreAttributeConstructor != null)
                    {
                        field.SetCustomAttribute(new CustomAttributeBuilder(_scriptIgnoreAttributeConstructor, emptyArray));
                    }
                }
            }
Esempio n. 3
0
		internal static void DefineCustomAttributes(PhpMemberAttributes attrs, FieldBuilder/*!*/ fieldBuilder)
		{
			Debug.Assert(fieldBuilder != null);

			// AppStatic == Static on Silverlight
#if !SILVERLIGHT
			// static but not app-static => thread static
			if ((attrs & PhpMemberAttributes.AppStatic) == PhpMemberAttributes.Static)
				fieldBuilder.SetCustomAttribute(AttributeBuilders.ThreadStatic);
#endif
		}
Esempio n. 4
0
		public void EmitAttribute (FieldBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
Esempio n. 5
0
		public void EmitAttribute (FieldBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
Esempio n. 6
0
 public static void SetCustomAttributes(FieldBuilder fb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         fb.SetCustomAttribute(cab);
 }
Esempio n. 7
0
 private void EmitCustomAttributes(FieldBuilder fieldBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         fieldBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
Esempio n. 8
0
 private void DefinePosition()
 {
     var ctor = typeof(VaryingAttribute).GetConstructor(new[] { typeof(UsageSemantic) });
     var positionOutAttrib = new CustomAttributeBuilder(ctor, new object[] { UsageSemantic.Position0 });
     _position = _type.DefineField("position", typeof(ShaderDefinition.vec4), FieldAttributes.Public);
     _position.SetCustomAttribute(positionOutAttrib);
 }
Esempio n. 9
0
 private void add_possible_type_attribute(FieldBuilder fb, ITypeNode type)
 {
     if (comp_opt.target != TargetType.Dll)
         return;
     if (type.type_special_kind == type_special_kind.typed_file)
     {
         Type elem_type = helper.GetTypeReference(type.element_type).tp;
         CustomAttributeBuilder cust_bldr = null;
         if (type.element_type is ICompiledTypeNode || type.element_type is IRefTypeNode && (type.element_type as IRefTypeNode).pointed_type is ICompiledTypeNode)
             cust_bldr = new CustomAttributeBuilder(this.FileOfAttributeConstructor, new object[1] { elem_type });
         else
             cust_bldr = new CustomAttributeBuilder(this.FileOfAttributeConstructor, new object[1] { elem_type.FullName });
         fb.SetCustomAttribute(cust_bldr);
     }
     else if (type.type_special_kind == type_special_kind.set_type)
     {
         Type elem_type = helper.GetTypeReference(type.element_type).tp;
         CustomAttributeBuilder cust_bldr = null;
         if (type.element_type is ICompiledTypeNode || type.element_type is IRefTypeNode && (type.element_type as IRefTypeNode).pointed_type is ICompiledTypeNode)
             cust_bldr = new CustomAttributeBuilder(this.SetOfAttributeConstructor, new object[1] { elem_type });
         else
             cust_bldr = new CustomAttributeBuilder(this.SetOfAttributeConstructor, new object[1] { elem_type.FullName });
         fb.SetCustomAttribute(cust_bldr);
     }
     else if (type.type_special_kind == type_special_kind.short_string)
     {
         int len = (type as IShortStringTypeNode).Length;
         CustomAttributeBuilder cust_bldr = new CustomAttributeBuilder(this.ShortStringAttributeConstructor, new object[1] { len });
         fb.SetCustomAttribute(cust_bldr);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Apply the custom attribute to fields
        /// </summary>
        public void ApplyAttributes(FieldBuilder fieldBuilder)
        {
            if (m_attribute != null)
                fieldBuilder.SetCustomAttribute(m_attribute);

            if (m_typeInfo != null)
                ConvCommon.HandleAlias(m_info, m_typeInfo, m_typeDesc, fieldBuilder);
        }
Esempio n. 11
0
 private void DefineOutput()
 {
     var ctor = typeof(FragmentOutAttribute).GetConstructor(new[] { typeof(UsageSemantic) });
     var fragmentOutAttrib = new CustomAttributeBuilder(ctor, new object[] { UsageSemantic.Color0 });
     _output = _type.DefineField("output", typeof(ShaderDefinition.vec4), FieldAttributes.Public);
     _output.SetCustomAttribute(fragmentOutAttrib);
 }
Esempio n. 12
0
 public static void HandleAlias(ConverterInfo info, TypeInfo typeInfo, TypeDesc typeDesc, FieldBuilder builder)
 {
     string aliasName = GetAliasName(info, typeInfo, typeDesc);
     if (aliasName != null)
         builder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComAliasName(aliasName));
 }
Esempio n. 13
0
        /// <summary>
        /// Provide implementation for setting default value 
        /// </summary>
        private static void SetDefaultValueInternal(IntPtr ipVariant, Type type, ParameterBuilder paramBuilder, FieldBuilder fieldBuilder, short typeVt)
        {
            if (type == null) throw new ArgumentNullException(nameof(type));
            // Use the element type for normalization if the type is a ByRef
            while (type.IsByRef)
                type = type.GetElementType();

            short defaultValueVt = Marshal.ReadInt16(ipVariant);
            object defaultValue = GetNormalizedDefaultValueFromVariant(ipVariant, type, defaultValueVt, typeVt);

            if (type.IsEnum && (defaultValueVt == (short)VarEnum.VT_I4 || defaultValueVt == (short)VarEnum.VT_UI4))
            {
                // 1) I can't dynamically create the enum in a ReflectionOnlyContext
                // 2) In pre-4.0, SetConstant(1) won't work for enum types.
                // After talking with team members we decided that this is a minor functionality that
                // we can live without in pre-4.0
                // return;
            }

            // Currently ParameterBuilder.SetConstant doesn't emit the custom attributes so certain types of constants
            // so we need to do that by ourselves
            CustomAttributeBuilder builder = null;
            if (type == typeof(Decimal))
            {
                DECIMAL realDecimal;
                IntPtr pDecimal = IntPtr.Zero;

                // Unfortunate we cannot directly access the fields in the decimal struct and we need to rely on the fact
                // that the internal representation of decimal & DECIMAL are the same, which will most likely remain true in the future
                // because CLR internally does the same thing
                Debug.Assert(sizeof(decimal) == Marshal.SizeOf(typeof(DECIMAL)));

                try
                {
                    pDecimal = Marshal.AllocCoTaskMem(sizeof(decimal));

                    // We convert it to unmanaged then back to managed to avoid unsafe code, so that we won't crash immediately in partial trust
                    Marshal.StructureToPtr(defaultValue, pDecimal, false);
                    realDecimal = (DECIMAL)Marshal.PtrToStructure(pDecimal, typeof(DECIMAL));
                }
                finally
                {
                    if (pDecimal != IntPtr.Zero)
                        Marshal.FreeCoTaskMem(pDecimal);
                }

                builder = CustomAttributeHelper.GetBuilderForDecimalConstant(
                    realDecimal.scale,
                    realDecimal.sign,
                    realDecimal.hi32,
                    realDecimal.mid32,
                    realDecimal.low32);
            }
            else if (type == typeof(DateTime) && defaultValueVt == (short)VarEnum.VT_DATE)
            {
                builder = CustomAttributeHelper.GetBuilderForDateTimeConstant(((DateTime)defaultValue).Ticks);
            }
            else if (defaultValueVt == (short)VarEnum.VT_UNKNOWN)
            {
                // Currently ParameterBuilder.SetConstant doesn't emit the IUnknownConstantAttribute
                // for IUnknown so we need to do that by ourselves
                builder = CustomAttributeHelper.GetBuilderForIUnknownConstant();
            }
            else if (defaultValueVt == (short)VarEnum.VT_DISPATCH)
            {
                // Currently ParameterBuilder.SetConstant doesn't emit the IDispatchConstantAttribute
                // for IDispatch so we need to do that by ourselves
                builder = CustomAttributeHelper.GetBuilderForIDispatchConstant();
            }

            if (builder != null)
            {
                if (paramBuilder != null)
                    paramBuilder.SetCustomAttribute(builder);
                if (fieldBuilder != null)
                    fieldBuilder.SetCustomAttribute(builder);
            }
            else
            {
                try
                {
                    if (paramBuilder != null)
                        paramBuilder.SetConstant(defaultValue);
                    if (fieldBuilder != null)
                        fieldBuilder.SetConstant(defaultValue);
                }
                catch (Exception)
                {
                    // Debug.Assert(type.IsEnum, "We should avoid failing for non-Enum default values");
                }
            }
        }
        /// <summary>
        /// Add Metadata attribute
        /// </summary>
        /// <param name="xmlField"></param>
        /// <param name="fieldBuilder"></param>
        private void CreateRTMetadataAttribute(XmlStructFieldLayout xmlField, FieldBuilder fieldBuilder)
        {
            // Find MarshalAsAttribute's constructor by signature, then invoke
            var metadataType = typeof(MetadataHelpAttribute);
            var ctorInfo = metadataType.GetConstructor(Type.EmptyTypes);

            List<PropertyInfo> lstPropInfo = new List<PropertyInfo>();
            List<object> lstPropValues = new List<object>();
            if(string.IsNullOrEmpty(xmlField.Metadata.Description) == false)
            {
                lstPropInfo.Add(metadataType.GetProperty("Description"));
                lstPropValues.Add(xmlField.Metadata.Description);
            }
            if (string.IsNullOrEmpty(xmlField.Metadata.DisplayName) == false)
            {
                lstPropInfo.Add(metadataType.GetProperty("DisplayName"));
                lstPropValues.Add(xmlField.Metadata.DisplayName);
            }

            var fields = metadataType.GetFields(BindingFlags.Public | BindingFlags.Instance);
            var marshalAsAttr = new CustomAttributeBuilder(ctorInfo,
                new object[] { },
                lstPropInfo.ToArray(),
                lstPropValues.ToArray());

            fieldBuilder.SetCustomAttribute(marshalAsAttr);
        }
        /// <summary>
        /// Add MarshalAs attribute
        /// </summary>
        /// <param name="xmlField"></param>
        /// <param name="fieldBuilder"></param>
        private void CreateRTMarshalAsAttribute(XmlStructFieldLayout xmlField, FieldBuilder fieldBuilder)
        {
            // Find MarshalAsAttribute's constructor by signature, then invoke
            var ctorParameters = new Type[] { typeof(UnmanagedType) };
            var ctorInfo = typeof(MarshalAsAttribute).GetConstructor(ctorParameters);

            var fields = typeof(MarshalAsAttribute).GetFields(BindingFlags.Public | BindingFlags.Instance);
            var sizeConst = (from f in fields
                             where f.Name == "SizeConst"
                             select f).ToArray();
            var marshalAsAttr = new CustomAttributeBuilder(ctorInfo,
                new object[] { xmlField.MarshalAsUnmanagedType }, sizeConst, new object[] { xmlField.MarshalAsSizeConst });

            fieldBuilder.SetCustomAttribute(marshalAsAttr);
        }
Esempio n. 16
0
 private static void AddOrderAttribute(FieldBuilder fb, int order)
 {
     ConstructorInfo ci = typeof(OrderAttribute).GetConstructor(new[] { typeof(int) });
     CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(ci, new object[] { order });
     fb.SetCustomAttribute(attributeBuilder);
 }