本文整理汇总了C#中System.Reflection.Emit.PropertyBuilder类的典型用法代码示例。如果您正苦于以下问题:C# PropertyBuilder类的具体用法?C# PropertyBuilder怎么用?C# PropertyBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了PropertyBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateNewInstanceGetter
static MethodBuilder CreateNewInstanceGetter(TypeBuilder typeBuilder, PropertyBuilder property,
ConstructorInfo constructor, MethodAttributes accessRights)
{
var getterMethod = CodeGenerationUtils.GetterMethodFor(typeBuilder, property, accessRights);
CodeGenerationUtils.ReturnNewInstanceILInstructions(constructor, getterMethod);
return getterMethod;
}
开发者ID:gamlerhart,项目名称:db4opad,代码行数:8,代码来源:NamespaceContextGenerator.cs
示例2: GetterMethodFor
internal static MethodBuilder GetterMethodFor(TypeBuilder typeBuilder,
PropertyBuilder property, MethodAttributes access)
{
var getterMethod = typeBuilder.DefineMethod("get_" + property.Name,
access, property.PropertyType, null);
property.SetGetMethod(getterMethod);
return getterMethod;
}
开发者ID:gamlerhart,项目名称:db4opad,代码行数:9,代码来源:CodeGenerationUtils.cs
示例3: BuildSetter
private void BuildSetter(TypeBuilder typeBuilder, PropertyInfo contractProperty, PropertyBuilder builder)
{
var setMethod = contractProperty.GetSetMethod();
if (null != setMethod)
{
var setMethodBuilder = new ProxyMethodImplementationStrategy().BuildMethodProxy(typeBuilder, setMethod);
builder.SetSetMethod(setMethodBuilder);
}
}
开发者ID:fkalseth,项目名称:tinyaop,代码行数:10,代码来源:ProxyPropertyImplementationStrategy.cs
示例4: AddGetter
private void AddGetter(System.Reflection.Emit.TypeBuilder typeBuilder, FieldBuilder fieldBuilder, PropertyBuilder propertyBuilder)
{
MethodBuilder propertyGetter = typeBuilder.DefineMethod("get_" + _propertyName,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
_propertyType, Type.EmptyTypes);
var ilGenerator = propertyGetter.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(propertyGetter);
}
开发者ID:RichieYang,项目名称:NHateoas,代码行数:13,代码来源:PropertyVisitor.cs
示例5: AddSetter
private void AddSetter(System.Reflection.Emit.TypeBuilder typeBuilder, FieldBuilder fieldBuilder, PropertyBuilder propertyBuilder)
{
MethodBuilder propertySetter = typeBuilder.DefineMethod("set_" + _propertyName,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
null, new Type[] { _propertyType });
var propertySetterIl = propertySetter.GetILGenerator();
propertySetterIl.Emit(OpCodes.Ldarg_0);
propertySetterIl.Emit(OpCodes.Ldarg_1);
propertySetterIl.Emit(OpCodes.Stfld, fieldBuilder);
propertySetterIl.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(propertySetter);
}
开发者ID:RichieYang,项目名称:NHateoas,代码行数:14,代码来源:PropertyVisitor.cs
示例6: CreateGetMethod
/// <summary>
/// Creates the get method.
/// </summary>
/// <param name="typeBuilder">The type builder.</param>
/// <param name="prop">The prop.</param>
/// <param name="fieldBuilder">The field builder.</param>
/// <param name="propBuilder">The prop builder.</param>
private static void CreateGetMethod(TypeBuilder typeBuilder, PropertyInfo prop, FieldInfo fieldBuilder, PropertyBuilder propBuilder)
{
var getMethodBuilder = typeBuilder.DefineMethod(
"get_" + prop.Name,
GetSetAttributes,
prop.PropertyType,
Type.EmptyTypes);
var getIl = getMethodBuilder.GetILGenerator();
getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldfld, fieldBuilder);
getIl.Emit(OpCodes.Ret);
propBuilder.SetGetMethod(getMethodBuilder);
}
开发者ID:petxo,项目名称:HermEsb,代码行数:21,代码来源:DynamicPropertyBuilder.cs
示例7: AddGetter
private void AddGetter(System.Reflection.Emit.TypeBuilder typeBuilder, PropertyBuilder propertyBuilder)
{
MethodBuilder propertyGetter = typeBuilder.DefineMethod("get_" + _propertyInfo.Name,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
_propertyInfo.PropertyType, Type.EmptyTypes);
var ilGenerator = propertyGetter.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldfld, _aggregate);
MethodInfo getter = _propertyInfo.GetAccessors().First(accessor => accessor.ReturnType != typeof (void));
ilGenerator.Emit(OpCodes.Callvirt, getter);
ilGenerator.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(propertyGetter);
}
开发者ID:RichieYang,项目名称:NHateoas,代码行数:15,代码来源:AggregatedPropertyVisitor.cs
示例8: CreateGetter
/// <summary>
/// Creates the getter.
/// </summary>
/// <param name="typeBuilder">The type builder.</param>
/// <param name="propertyBuilder">The property builder.</param>
/// <param name="column">The column.</param>
private static void CreateGetter(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, SLDataColumn column)
{
var getMethodBuilder = typeBuilder.DefineMethod(
"get_" + column.ColumnName,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
CallingConventions.HasThis,
column.DataType, Type.EmptyTypes);
var getMethodIL = getMethodBuilder.GetILGenerator();
getMethodIL.Emit(OpCodes.Ldarg_0);
getMethodIL.Emit(OpCodes.Ldstr, column.ColumnName);
getMethodIL.Emit(OpCodes.Callvirt, GetValueMethod.MakeGenericMethod(column.DataType));
getMethodIL.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(getMethodBuilder);
}
开发者ID:K-Library-NET,项目名称:PopcornStudios,代码行数:22,代码来源:DynamicObjectBuilder.cs
示例9: CreateSetMethod
/// <summary>
/// Creates the set method.
/// </summary>
/// <param name="typeBuilder">The type builder.</param>
/// <param name="prop">The prop.</param>
/// <param name="fieldBuilder">The field builder.</param>
/// <param name="propBuilder">The prop builder.</param>
private static void CreateSetMethod(TypeBuilder typeBuilder, PropertyInfo prop, FieldInfo fieldBuilder, PropertyBuilder propBuilder)
{
var setMethodBuilder = typeBuilder.DefineMethod(
"set_" + prop.Name,
GetSetAttributes,
null,
new[] { prop.PropertyType });
var setIl = setMethodBuilder.GetILGenerator();
setIl.Emit(OpCodes.Ldarg_0);
setIl.Emit(OpCodes.Ldarg_1);
setIl.Emit(OpCodes.Stfld, fieldBuilder);
setIl.Emit(OpCodes.Ret);
propBuilder.SetSetMethod(setMethodBuilder);
}
开发者ID:petxo,项目名称:HermEsb,代码行数:23,代码来源:DynamicPropertyBuilder.cs
示例10: AddSetter
private void AddSetter(System.Reflection.Emit.TypeBuilder typeBuilder, PropertyBuilder propertyBuilder)
{
MethodBuilder propertySetter = typeBuilder.DefineMethod("set_" + _propertyInfo.Name,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
null, new Type[] { _propertyInfo.PropertyType });
var propertySetterIl = propertySetter.GetILGenerator();
propertySetterIl.Emit(OpCodes.Ldarg_0);
propertySetterIl.Emit(OpCodes.Ldfld, _aggregate);
propertySetterIl.Emit(OpCodes.Ldarg_1);
MethodInfo setter = _propertyInfo.GetAccessors().First(accessor => accessor.ReturnType == typeof(void));
propertySetterIl.Emit(OpCodes.Callvirt, setter);
propertySetterIl.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(propertySetter);
}
开发者ID:RichieYang,项目名称:NHateoas,代码行数:16,代码来源:AggregatedPropertyVisitor.cs
示例11: CreateGetter
private static void CreateGetter(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, IPropertyInfo propertyInfo)
{
MethodBuilder getMethodBuilder = typeBuilder.DefineMethod(
"get_" + propertyInfo.PropertyName,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
CallingConventions.HasThis,
propertyInfo.PropertyType, Type.EmptyTypes);
ILGenerator getMethodIL = getMethodBuilder.GetILGenerator();
getMethodIL.Emit(OpCodes.Ldarg_0);
getMethodIL.Emit(OpCodes.Ldstr, propertyInfo.PropertyName);
getMethodIL.Emit(OpCodes.Callvirt, GetValueMethod.MakeGenericMethod(propertyInfo.PropertyType));
getMethodIL.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(getMethodBuilder);
}
开发者ID:mehmetgoren,项目名称:AppX.Data,代码行数:16,代码来源:RecordBuilder.cs
示例12: CreateSetter
private static void CreateSetter(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, IPropertyInfo propertyInfo)
{
MethodBuilder setMethodBuilder = typeBuilder.DefineMethod(
"set_" + propertyInfo.PropertyName,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
CallingConventions.HasThis,
null, new[] { propertyInfo.PropertyType });
ILGenerator setMethodIL = setMethodBuilder.GetILGenerator();
setMethodIL.Emit(OpCodes.Ldarg_0);
setMethodIL.Emit(OpCodes.Ldstr, propertyInfo.PropertyName);
setMethodIL.Emit(OpCodes.Ldarg_1);
setMethodIL.Emit(OpCodes.Callvirt, SetValueMethod.MakeGenericMethod(propertyInfo.PropertyType));
setMethodIL.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(setMethodBuilder);
}
开发者ID:mehmetgoren,项目名称:AppX.Data,代码行数:17,代码来源:RecordBuilder.cs
示例13: CreateSetter
private static void CreateSetter(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, DataColumn column)
{
var setMethodBuilder = typeBuilder.DefineMethod(
"set_" + column.ColumnName,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
CallingConventions.HasThis,
null, new[] { column.DataType });
var setMethodIL = setMethodBuilder.GetILGenerator();
setMethodIL.Emit(OpCodes.Ldarg_0);
setMethodIL.Emit(OpCodes.Ldstr, column.ColumnName);
setMethodIL.Emit(OpCodes.Ldarg_1);
setMethodIL.Emit(OpCodes.Callvirt, SetValueMethod.MakeGenericMethod(column.DataType));
setMethodIL.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(setMethodBuilder);
}
开发者ID:FoundOPS,项目名称:server,代码行数:17,代码来源:DynamicObjectBuilder.cs
示例14: EmitAttribute
public void EmitAttribute (PropertyBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
}
开发者ID:alisci01,项目名称:mono,代码行数:5,代码来源:attribute.cs
示例15: 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);
}
}
开发者ID:calebjenkins,项目名称:Highway.Data,代码行数:18,代码来源:RuntimeTypeProvider.cs
示例16: DefineSetMethod
private static void DefineSetMethod(TypeBuilder newType, PropertyBuilder propertyBuilder, FieldInfo fieldBuilder, PropertyInfo property)
{
var setMethod = property.GetSetMethod();
if (setMethod == null) return;
var methodBuilder = newType.DefineMethod(setMethod.Name,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual,
null,
new[] {property.PropertyType});
var ilg = methodBuilder.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldarg_1);
ilg.Emit(OpCodes.Stfld, fieldBuilder);
ilg.Emit(OpCodes.Ret);
propertyBuilder.SetSetMethod(methodBuilder);
var methodInfo = methodBuilder.GetBaseDefinition();
newType.DefineMethodOverride(methodInfo, setMethod);
}
开发者ID:mcwatt77,项目名称:vimcontrols,代码行数:21,代码来源:ImplementationBuilder.cs
示例17: EmitBaseGetter
private static void EmitBaseGetter(TypeBuilder typeBuilder, PropertyBuilder propertyBuilder, PropertyInfo baseProperty)
{
if (CanProxyGetter(baseProperty))
{
var baseGetter = baseProperty.GetGetMethod(true);
const MethodAttributes getterAttributes =
MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;
var getterAccess = baseGetter.Attributes & MethodAttributes.MemberAccessMask;
// Define a property getter override in the proxy type
var getterBuilder = typeBuilder.DefineMethod(
"get_" + baseProperty.Name, getterAccess | getterAttributes, baseProperty.PropertyType, Type.EmptyTypes);
var gen = getterBuilder.GetILGenerator();
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Call, baseGetter);
gen.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(getterBuilder);
}
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:21,代码来源:EntityProxyFactory.cs
示例18: DefineGetMethod
private static void DefineGetMethod(TypeBuilder newType, PropertyBuilder propertyBuilder, FieldInfo fieldBuilder, PropertyInfo property)
{
var getMethod = property.GetGetMethod();
var methodBuilder = newType.DefineMethod(getMethod.Name,
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual,
property.PropertyType,
Type.EmptyTypes);
var ilg = methodBuilder.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldfld, fieldBuilder);
ilg.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(methodBuilder);
var methodInfo = methodBuilder.GetBaseDefinition();
newType.DefineMethodOverride(methodInfo, getMethod);
}
开发者ID:mcwatt77,项目名称:vimcontrols,代码行数:20,代码来源:ImplementationBuilder.cs
示例19: EmitMember
public bool EmitMember(
TypeBuilder typeBuilder, EdmMember member, PropertyBuilder propertyBuilder, PropertyInfo baseProperty,
BaseProxyImplementor baseImplementor)
{
if (_members.Contains(member))
{
var baseGetter = baseProperty.GetGetMethod(true);
const MethodAttributes getterAttributes =
MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;
var getterAccess = baseGetter.Attributes & MethodAttributes.MemberAccessMask;
// Define field to store interceptor Func
// Signature of interceptor Func delegate is as follows:
//
// bool intercept(ProxyType proxy, PropertyType propertyValue)
//
// where
// PropertyType is the type of the Property, such as ICollection<Customer>,
// ProxyType is the type of the proxy object,
// propertyValue is the value returned from the proxied type's property getter.
var interceptorType = typeof(Func<,,>).MakeGenericType(typeBuilder, baseProperty.PropertyType, typeof(bool));
var interceptorInvoke = TypeBuilder.GetMethod(interceptorType, typeof(Func<,,>).GetMethod("Invoke"));
var interceptorField = typeBuilder.DefineField(
GetInterceptorFieldName(baseProperty.Name), interceptorType, FieldAttributes.Private | FieldAttributes.Static);
// Define a property getter override in the proxy type
var getterBuilder = typeBuilder.DefineMethod(
"get_" + baseProperty.Name, getterAccess | getterAttributes, baseProperty.PropertyType, Type.EmptyTypes);
var generator = getterBuilder.GetILGenerator();
// Emit instructions for the following call:
// T value = base.SomeProperty;
// if(this._interceptorForSomeProperty(this, value))
// { return value; }
// return base.SomeProperty;
// where _interceptorForSomeProperty represents the interceptor Func field.
var lableTrue = generator.DefineLabel();
generator.DeclareLocal(baseProperty.PropertyType); // T value
generator.Emit(OpCodes.Ldarg_0); // call base.SomeProperty
generator.Emit(OpCodes.Call, baseGetter); // call to base property getter
generator.Emit(OpCodes.Stloc_0); // value = result
generator.Emit(OpCodes.Ldarg_0); // load this
generator.Emit(OpCodes.Ldfld, interceptorField); // load this._interceptor
generator.Emit(OpCodes.Ldarg_0); // load this
generator.Emit(OpCodes.Ldloc_0); // load value
generator.Emit(OpCodes.Callvirt, interceptorInvoke); // call to interceptor delegate with (this, value)
generator.Emit(OpCodes.Brtrue_S, lableTrue); // if true, just return
generator.Emit(OpCodes.Ldarg_0); // else, call the base propertty getter again
generator.Emit(OpCodes.Call, baseGetter); // call to base property getter
generator.Emit(OpCodes.Ret);
generator.MarkLabel(lableTrue);
generator.Emit(OpCodes.Ldloc_0);
generator.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(getterBuilder);
baseImplementor.AddBasePropertyGetter(baseProperty);
return true;
}
return false;
}
开发者ID:christiandpena,项目名称:entityframework,代码行数:63,代码来源:LazyLoadImplementor.cs
示例20: DefineBuilders
protected void DefineBuilders (MemberKind kind, ParametersCompiled parameters)
{
PropertyBuilder = Parent.TypeBuilder.DefineProperty (
GetFullName (MemberName), PropertyAttributes.None,
#if !BOOTSTRAP_BASIC // Requires trunk version mscorlib
IsStatic ? 0 : CallingConventions.HasThis,
#endif
MemberType.GetMetaInfo (), null, null,
parameters.GetMetaInfo (), null, null);
PropertySpec spec;
if (kind == MemberKind.Indexer)
spec = new IndexerSpec (Parent.Definition, this, MemberType, parameters, PropertyBuilder, ModFlags);
else
spec = new PropertySpec (kind, Parent.Definition, this, MemberType, PropertyBuilder, ModFlags);
if (Get != null) {
spec.Get = Get.Spec;
var method = Get.Spec.GetMetaInfo () as MethodBuilder;
if (method != null) {
PropertyBuilder.SetGetMethod (method);
Parent.MemberCache.AddMember (this, method.Name, Get.Spec);
}
} else {
CheckMissingAccessor (kind, parameters, true);
}
if (Set != null) {
spec.Set = Set.Spec;
var method = Set.Spec.GetMetaInfo () as MethodBuilder;
if (method != null) {
PropertyBuilder.SetSetMethod (method);
Parent.MemberCache.AddMember (this, method.Name, Set.Spec);
}
} else {
CheckMissingAccessor (kind, parameters, false);
}
Parent.MemberCache.AddMember (this, PropertyBuilder.Name, spec);
}
开发者ID:afaerber,项目名称:mono,代码行数:42,代码来源:property.cs
注:本文中的System.Reflection.Emit.PropertyBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论