本文整理汇总了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())));
}
示例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));
}
}
}
示例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
}
示例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);
}
}
示例5: EmitAttribute
public void EmitAttribute (FieldBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
}
示例6: SetCustomAttributes
public static void SetCustomAttributes(FieldBuilder fb, IPersistentMap attributes)
{
foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
fb.SetCustomAttribute(cab);
}
示例7: EmitCustomAttributes
private void EmitCustomAttributes(FieldBuilder fieldBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
{
foreach (var attribute in attributes)
{
fieldBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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));
}
示例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");
}
}
}
示例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);
}
示例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);
}