本文整理汇总了C#中System.Reflection.Emit.PropertyBuilder类的典型用法代码示例。如果您正苦于以下问题:C# PropertyBuilder类的具体用法?C# PropertyBuilder怎么用?C# PropertyBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了PropertyBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例14: EmitAttribute
public void EmitAttribute (PropertyBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
}
示例15: PropertyEmitter
// private ParameterInfo[] indexParameters;
public PropertyEmitter(AbstractTypeEmitter parentTypeEmitter, String name, PropertyAttributes attributes,
Type propertyType)
{
this.parentTypeEmitter = parentTypeEmitter;
builder = parentTypeEmitter.TypeBuilder.DefineProperty(name, attributes, propertyType, new Type[0]);
}