本文整理汇总了C#中System.Reflection.Emit.PropertyBuilder.SetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBuilder.SetCustomAttribute方法的具体用法?C# PropertyBuilder.SetCustomAttribute怎么用?C# PropertyBuilder.SetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.PropertyBuilder
的用法示例。
在下文中一共展示了PropertyBuilder.SetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneCustomAttributes
private void CloneCustomAttributes(PropertyBuilder property, EntityMemberInfo member)
{
foreach(var attr in member.Attributes) {
CustomAttributeHandler handler;
if (!_model.App.AttributeHandlers.TryGetValue(attr.GetType(), out handler)) continue;
var attrBuilder = handler.Clone(attr);
if (attrBuilder != null)
property.SetCustomAttribute(attrBuilder);
}
}
示例2: AddCustomAttributeToProperty
/// <summary>
/// Given a custom attribute and property builder, adds an instance of custom attribute
/// to the property builder
/// </summary>
void AddCustomAttributeToProperty(object customAttribute, PropertyBuilder propBuilder)
{
var customAttributeBuilder = BuildCustomAttribute(customAttribute);
if (customAttributeBuilder != null)
{
propBuilder.SetCustomAttribute(customAttributeBuilder);
}
}
示例3: SetAttributes
private static void SetAttributes(PropertyBuilder propertyBuilder, MemberInfo memberInfo)
{
var customAttributeBuilders = PropertyAttributeBuilders
.GetOrAdd(
memberInfo,
p =>
{
var customAttributes = p.GetCustomAttributesData();
return CreateCustomAttributeBuilders(customAttributes).ToArray();
});
Contract.Assume(customAttributeBuilders != null);
foreach (var attribute in customAttributeBuilders)
{
propertyBuilder.SetCustomAttribute(attribute);
}
}
示例4: EmitAttribute
public void EmitAttribute (PropertyBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
}
示例5: SetDataMemberAttribute
private static void SetDataMemberAttribute(PropertyBuilder typeBuilder)
{
var dmbType = typeof(DataMemberAttribute);
var dataMemberBuilder = new CustomAttributeBuilder(
dmbType.GetConstructor(Type.EmptyTypes), new object[0]);
typeBuilder.SetCustomAttribute(dataMemberBuilder);
}
示例6: EmitAttribute
public void EmitAttribute (PropertyBuilder builder, TypeSpec type)
{
if (ResolveTransformationCtor ()) {
var cab = new CustomAttributeBuilder ((ConstructorInfo) tctor.GetMetaInfo (), new object[] { GetTransformationFlags (type) });
builder.SetCustomAttribute (cab);
}
}
示例7: EmitCustomAttributes
private void EmitCustomAttributes(PropertyBuilder propertyBuilder, IEnumerable<Cci.ICustomAttribute> attributes)
{
foreach (var attribute in attributes)
{
propertyBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute));
}
}
示例8: createHashMethod
private void createHashMethod(PropertyBuilder propBuild,TypeBuilder typeBuild,FieldBuilder hash)
{
// First, we'll define the behavior of the "get" property for Hash as a method.
MethodBuilder typeHashGet = typeBuild.DefineMethod("GetHash",
MethodAttributes.Public,
typeof(Hashtable),
new Type[] { });
ILGenerator ilg = typeHashGet.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldfld, hash);
ilg.Emit(OpCodes.Ret);
// Now, we'll define the behavior of the "set" property for Hash.
MethodBuilder typeHashSet = typeBuild.DefineMethod("SetHash",
MethodAttributes.Public,
null,
new Type[] { typeof(Hashtable) });
ilg = typeHashSet.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldarg_1);
ilg.Emit(OpCodes.Stfld, hash);
ilg.Emit(OpCodes.Ret);
// map the two methods created above to their property
propBuild.SetGetMethod(typeHashGet);
propBuild.SetSetMethod(typeHashSet);
//add the [Browsable(false)] property to the Hash property so it doesnt show up on the property list
ConstructorInfo ci = typeof(BrowsableAttribute).GetConstructor(new Type[]{typeof(bool)});
CustomAttributeBuilder cab = new CustomAttributeBuilder(ci,new object[]{false});
propBuild.SetCustomAttribute(cab);
}
示例9: SetAttributes
/// <summary>
/// Establece los atributos para la propiedad indicada
/// </summary>
/// <param name="propertyBuilder">Constructor de propiedades</param>
/// <param name="propertyInfo">Información de la propiedad</param>
private void SetAttributes( PropertyBuilder propertyBuilder, PropertyInfo propertyInfo )
{
Verify.ArgumentNotNull(propertyBuilder, "propertyBuilder");
Verify.ArgumentNotNull(propertyInfo, "propertyInfo");
var propBuilders = PropertyAttributeBuilders
.GetOrAdd(propertyInfo,
p =>
{
var customAttr = p.GetCustomAttributesData();
return CreateCustomAttributeBuilders(customAttr);
})
.ToList();
propBuilders.ForEach(pb => propertyBuilder.SetCustomAttribute(pb));
}
示例10: SetAttributes
private static void SetAttributes(KeyValuePair<string, IMetadataDefinition> pair, PropertyBuilder prop)
{
prop.SetCustomAttribute(
new CustomAttributeBuilder(
JsonPropertyAttributeCtor,
new object[] { pair.Key },
new[] { JsonPropertyAttribute_Required },
new object[] { pair.Value.IsRequired ? Required.Always : Required.Default }));
prop.SetCustomAttribute(
new CustomAttributeBuilder(
DisplayNameAttribute_Ctor,
new object[] { pair.Value.DisplayName }));
if (pair.Value.IsQueryable)
{
prop.SetCustomAttribute(
new CustomAttributeBuilder(
QueryNameAttribute_Ctor,
new object[] { pair.Value.QueryName }));
}
}
示例11: AddFromIdlNameAttribute
private void AddFromIdlNameAttribute(PropertyBuilder propBuild, string forIdlAttributeName) {
propBuild.SetCustomAttribute(
new FromIdlNameAttribute(forIdlAttributeName).CreateAttributeBuilder());
}
示例12: AssociateAttribute
private void AssociateAttribute(PropertyBuilder propertyBuilder, Type attributeType, string value)
{
CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(
attributeType.GetConstructor(new Type[] { typeof(string) }),
new object[] { value });
propertyBuilder.SetCustomAttribute(attributeBuilder);
}
示例13: DefineCustomAttributes
internal static void DefineCustomAttributes(PropertyBuilder member, ReadOnlyCollection<AttributeAst> attributes, Parser parser, AttributeTargets attributeTargets)
{
if (attributes != null)
{
foreach (var attr in attributes)
{
var cabuilder = GetAttributeBuilder(parser, attr, attributeTargets);
if (cabuilder != null)
{
member.SetCustomAttribute(cabuilder);
}
}
}
}
示例14: CreateAttribute
//public virtual Descr CreateAttribute()
//{
//}
public CustomAttributeBuilder CreateAttribute(PropertyBuilder Property, Type Attribute, Type[] Parameters, Object[] Values)
{
ConstructorInfo attributeConstructor = Attribute.GetConstructor(Parameters);
CustomAttributeBuilder newAttribute = new CustomAttributeBuilder(attributeConstructor,Values);
Property.SetCustomAttribute(newAttribute);
return newAttribute;
}
示例15: HandleAlias
public static void HandleAlias(ConverterInfo info, TypeInfo typeInfo, TypeDesc typeDesc, PropertyBuilder builder)
{
string aliasName = GetAliasName(info, typeInfo, typeDesc);
if (aliasName != null)
builder.SetCustomAttribute(CustomAttributeHelper.GetBuilderForComAliasName(aliasName));
}