本文整理汇总了C#中System.Reflection.Emit.PropertyBuilder.GetGetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyBuilder.GetGetMethod方法的具体用法?C# PropertyBuilder.GetGetMethod怎么用?C# PropertyBuilder.GetGetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.PropertyBuilder
的用法示例。
在下文中一共展示了PropertyBuilder.GetGetMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitFieldExportStubs
public void EmitFieldExportStubs(PhpField/*!*/ field, PropertyBuilder/*!*/ property)
{
Debug.Assert(field != null && property != null);
MethodBuilder getter = (MethodBuilder)property.GetGetMethod(true);
MethodBuilder setter = (MethodBuilder)property.GetSetMethod(true);
// emit getter:
if (getter != null) EmitFieldExportGetter(field, property, getter);
// emit setter:
if (setter != null) EmitFieldExportSetter(field, property, setter);
}
示例2: OnGeneratePropertyMethods
protected override void OnGeneratePropertyMethods(PropertyInfo targetProp,
PropertyDefinition proxyProp,
TypeReference proxyBaseType,
TypeReference proxyTargetType,
TypeReference rootProxyTargetType)
{
var propWrapperTypeRef = this.propertyWrapperType.MakeGenericType(proxyTargetType, proxyProp.PropertyType);
var proxyType = (TypeDefinition)proxyProp.DeclaringType;
if (proxyType == null)
throw new InvalidOperationException($"{proxyProp} has no declaring type.");
var propWrapperCtor = propWrapperTypeRef.GetConstructor(typeof(string));
var propertyWrapperField = proxyType.DefineField("_pwrap_" + targetProp.Name,
propWrapperTypeRef,
FieldAttributes.Private | FieldAttributes.Static);
this.initPropertyWrapperIlAction.Add(il =>
{
il.Emit(OpCodes.Ldstr, targetProp.Name);
il.Emit(OpCodes.Newobj, propWrapperCtor);
il.Emit(OpCodes.Stsfld, propertyWrapperField);
});
/*
var initPropertyWrappersMethod = GetInitPropertyWrappersMethod(proxyProp);
var initIl = initPropertyWrappersMethod.Body.GetILProcessor();
var lastInstruction = initPropertyWrappersMethod.Body.Instructions.Last();
if (lastInstruction.OpCode != OpCodes.Ret)
throw new InvalidOperationException("Expected to find ret instruction as last instruction");
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Ldstr, targetProp.Name));
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Newobj, propWrapperCtor));
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Stsfld, propertyWrapperField));
*/
var baseDef = proxyBaseType;
var proxyOnGetMethod = baseDef.GetGenericInstanceMethod("OnGet", proxyTargetType, proxyProp.PropertyType);
var proxyOnGetMethodInstance = proxyOnGetMethod.MakeGenericMethod(proxyTargetType, proxyProp.PropertyType);
var proxyOnSetMethod = baseDef.GetGenericInstanceMethod("OnSet", proxyTargetType, proxyProp.PropertyType);
var proxyOnSetMethodInstance = proxyOnSetMethod.MakeGenericMethod(proxyTargetType, proxyProp.PropertyType);
var getMethod = (MethodDefinition)proxyProp.GetGetMethod(true);
if (getMethod != null)
{
var getIl = getMethod.GetILGenerator();
getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldsfld, propertyWrapperField);
getIl.Emit(OpCodes.Callvirt, proxyOnGetMethodInstance);
getIl.Emit(OpCodes.Ret);
}
var setMethod = (MethodDefinition)proxyProp.GetSetMethod(true);
if (setMethod != null)
{
var setIl = setMethod.GetILGenerator();
setIl.Emit(OpCodes.Ldarg_0);
setIl.Emit(OpCodes.Ldsfld, propertyWrapperField);
setIl.Emit(OpCodes.Ldarg_1);
setIl.Emit(OpCodes.Callvirt, proxyOnSetMethodInstance);
setIl.Emit(OpCodes.Ret);
}
}
示例3: EmitConstantExportStub
public void EmitConstantExportStub(ClassConstant/*!*/ constant, PropertyBuilder/*!*/ property)
{
Debug.Assert(constant != null && constant.IsExported && property != null);
MethodBuilder getter = (MethodBuilder)property.GetGetMethod(true);
// emit getter:
if (getter != null)
{
EmissionContext emission_context = SetupStubPlaces(constant.DeclaringPhpType, getter.IsStatic);
il = new ILEmitter(getter);
try
{
// read the field
PhpTypeCode type_code = constant.EmitGet(this, null, false, null);
// convert it to the return type
//ClrOverloadBuilder.EmitConvertToClr(
// il,
// type_code,
// getter.ReturnType);
il.EmitBoxing(type_code);
il.Emit(OpCodes.Ret);
}
finally
{
RestorePlaces(emission_context);
}
}
}
示例4: OnGeneratePropertyMethods
protected override void OnGeneratePropertyMethods(
PropertyInfo targetProp,
PropertyDefinition proxyProp,
TypeReference proxyBaseType,
TypeReference proxyTargetType,
TypeReference rootProxyTargetType)
{
var propWrapperTypeDef = propertyWrapperType;
var propWrapperTypeRef = propertyWrapperType.MakeGenericType(proxyTargetType, proxyProp.PropertyType);
var proxyType = (TypeDefinition) proxyProp.DeclaringType;
var propWrapperCtor =
propWrapperTypeRef.GetConstructors().First(x => x.GetParameters().Length == 1 &&
x.GetParameters()[0].ParameterType == typeof (string));
var propertyWrapperField = proxyType.DefineField(
"_pwrap_" + targetProp.Name, propWrapperTypeRef, FieldAttributes.Private | FieldAttributes.Static);
initPropertyWrapperIlAction.Add(il =>
{
il.Emit(OpCodes.Ldstr, targetProp.Name);
il.Emit(OpCodes.Newobj, propWrapperCtor);
il.Emit(OpCodes.Stsfld, propertyWrapperField);
});
/*
var initPropertyWrappersMethod = GetInitPropertyWrappersMethod(proxyProp);
var initIl = initPropertyWrappersMethod.Body.GetILProcessor();
var lastInstruction = initPropertyWrappersMethod.Body.Instructions.Last();
if (lastInstruction.OpCode != OpCodes.Ret)
throw new InvalidOperationException("Expected to find ret instruction as last instruction");
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Ldstr, targetProp.Name));
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Newobj, propWrapperCtor));
initIl.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Stsfld, propertyWrapperField));
*/
var baseDef = proxyBaseType;
var proxyOnGetMethod =
baseDef.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
.First(x => x.Name == "OnGet");
if (proxyOnGetMethod.GetGenericArguments().Length != 2)
{
throw new InvalidOperationException(
"OnGet method of base class is required to have two generic parameters.");
}
var proxyOnGetMethodInstance = proxyOnGetMethod.MakeGenericMethod(proxyTargetType, proxyProp.PropertyType);
var proxyOnSetMethod =
baseDef.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
.First(x => x.Name == "OnSet");
;
if (proxyOnGetMethod.GetGenericArguments().Length != 2)
{
throw new InvalidOperationException(
"OnSet method of base class is required to have two generic parameters.");
}
var proxyOnSetMethodInstance = proxyOnSetMethod.MakeGenericMethod(proxyTargetType, proxyProp.PropertyType);
var getMethod = (MethodDefinition) proxyProp.GetGetMethod(true);
if (getMethod != null)
{
var getIl = getMethod.GetILGenerator();
getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldsfld, propertyWrapperField);
getIl.Emit(OpCodes.Callvirt, proxyOnGetMethodInstance);
getIl.Emit(OpCodes.Ret);
}
var setMethod = (MethodDefinition) proxyProp.GetSetMethod(true);
if (setMethod != null)
{
var setIl = setMethod.GetILGenerator();
setIl.Emit(OpCodes.Ldarg_0);
setIl.Emit(OpCodes.Ldsfld, propertyWrapperField);
setIl.Emit(OpCodes.Ldarg_1);
setIl.Emit(OpCodes.Callvirt, proxyOnSetMethodInstance);
setIl.Emit(OpCodes.Ret);
}
}