当前位置: 首页>>代码示例>>C#>>正文


C# FieldBuilder.SetCustomAttribute方法代码示例

本文整理汇总了C#中System.Reflection.Emit.FieldBuilder.SetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# FieldBuilder.SetCustomAttribute方法的具体用法?C# FieldBuilder.SetCustomAttribute怎么用?C# FieldBuilder.SetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.FieldBuilder的用法示例。


在下文中一共展示了FieldBuilder.SetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetCustomAttributes

 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())));
 }
开发者ID:davidadsit,项目名称:clojure-clr,代码行数:5,代码来源:GenInterface.cs

示例2: MarkAsNotSerializable

            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));
                    }
                }
            }
开发者ID:christiandpena,项目名称:entityframework,代码行数:17,代码来源:EntityProxyFactory.cs

示例3: DefineCustomAttributes

		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
		}
开发者ID:jdluzen,项目名称:Phalanger,代码行数:11,代码来源:Members.cs

示例4: EmitAttribute

		public void EmitAttribute (FieldBuilder builder, TypeSpec type)
		{
			if (ResolveTransformationCtor ()) {
				var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
				builder.SetCustomAttribute (cab);
			}
		}
开发者ID:Ein,项目名称:monodevelop,代码行数:7,代码来源:attribute.cs

示例5: EmitAttribute

		public void EmitAttribute (FieldBuilder builder)
		{
			if (ResolveBuilder ())
				builder.SetCustomAttribute (cab);
		}
开发者ID:alisci01,项目名称:mono,代码行数:5,代码来源:attribute.cs

示例6: SetCustomAttributes

 public static void SetCustomAttributes(FieldBuilder fb, IPersistentMap attributes)
 {
     foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
         fb.SetCustomAttribute(cab);
 }
开发者ID:TerabyteX,项目名称:clojure-clr,代码行数:5,代码来源:GenInterface.cs

示例7: EmitCustomAttributes

 private void EmitCustomAttributes(FieldBuilder fieldBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
 {
     foreach (var attribute in attributes)
     {
         fieldBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
     }
 }
开发者ID:furesoft,项目名称:roslyn,代码行数:7,代码来源:ReflectionEmitter.cs

示例8: DefinePosition

 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);
 }
开发者ID:hach-que,项目名称:SLSharp,代码行数:7,代码来源:ShaderBuilder.cs

示例9: add_possible_type_attribute

 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);
     }
 }
开发者ID:CSRedRat,项目名称:pascalabcnet,代码行数:31,代码来源:NETGenerator.cs

示例10: ApplyAttributes

        /// <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);
        }
开发者ID:dbremner,项目名称:clrinterop,代码行数:11,代码来源:TypeConverter.cs

示例11: DefineOutput

 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);
 }
开发者ID:hach-que,项目名称:SLSharp,代码行数:7,代码来源:ShaderBuilder.cs

示例12: HandleAlias

 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));
 }
开发者ID:dbremner,项目名称:clrinterop,代码行数:6,代码来源:ConvCommon.cs

示例13: SetDefaultValueInternal

        /// <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");
                }
            }
        }
开发者ID:dbremner,项目名称:clrinterop,代码行数:95,代码来源:ConvCommon.cs

示例14: CreateRTMetadataAttribute

        /// <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);
        }
开发者ID:subha007,项目名称:MiniFileParser,代码行数:32,代码来源:GenerateRuntimeAssembly.cs

示例15: CreateRTMarshalAsAttribute

        /// <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);
        }
开发者ID:subha007,项目名称:MiniFileParser,代码行数:20,代码来源:GenerateRuntimeAssembly.cs


注:本文中的System.Reflection.Emit.FieldBuilder.SetCustomAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。