本文整理汇总了C#中Mono.GetReference方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.GetReference方法的具体用法?C# Mono.GetReference怎么用?C# Mono.GetReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono
的用法示例。
在下文中一共展示了Mono.GetReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBuildMethod
/// <summary>
/// Create a method definition for the builder method that builds a custom attribute from an annotation.
/// </summary>
private static MethodDefinition CreateBuildMethod(
ISourceLocation seqp,
Mono.Cecil.MethodDefinition ctor,
List<Tuple<MethodDefinition, Mono.Cecil.TypeReference>> paramGetMethods,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
ClassDefinition attributeClass,
AttributeAnnotationInterface mapping)
{
// Create method definition
string name = CreateBuildMethodName(attributeClass);
TypeReference attributeTypeRef = ctor.DeclaringType.GetReference(targetPackage, compiler.Module);
MethodDefinition method = new MethodDefinition(attributeClass, name, new Prototype(attributeTypeRef, new Parameter(mapping.AnnotationInterfaceClass, "ann")));
method.AccessFlags = AccessFlags.Public | AccessFlags.Static | AccessFlags.Synthetic;
attributeClass.Methods.Add(method);
// Create method body
MethodBody body = new MethodBody(null);
Register annotationReg = body.AllocateRegister(RCategory.Argument, RType.Object);
//body.Instructions.Add(seqp, RCode.Check_cast, mapping.AnnotationInterfaceClass, annotationReg);
// Allocate attribute
Register attributeReg = body.AllocateRegister(RCategory.Temp, RType.Object);
body.Instructions.Add(seqp, RCode.New_instance, attributeClass, attributeReg);
// Get ctor arguments
List<Register> ctorArgRegs = new List<Register>();
foreach (var p in paramGetMethods)
{
Instruction branchIfNotSet; // this can not happen, but lets keep the code below simple.
XModel.XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, p.Item2);
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xType, annotationReg, p.Item1, compiler, targetPackage, out branchIfNotSet);
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
ctorArgRegs.AddRange(valueRegs);
}
// Invoke ctor
DexLib.MethodReference dctor = ctor.GetReference(targetPackage, compiler.Module);
body.Instructions.Add(seqp, RCode.Invoke_direct, dctor, new[] { attributeReg }.Concat(ctorArgRegs).ToArray());
// Get field values
foreach (var fieldMap in mapping.FieldToGetMethodMap)
{
var field = fieldMap.Key;
XModel.XTypeReference xFieldType = XBuilder.AsTypeReference(compiler.Module, field.FieldType);
MethodDefinition getter = fieldMap.Value;
Instruction branchIfNotSet;
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xFieldType, annotationReg, getter, compiler, targetPackage, out branchIfNotSet);
var put = body.Instructions.Add(seqp, xFieldType.IPut(), valueRegs[0], attributeReg);
mapping.FixOperands.Add(Tuple.Create(put, (MemberReference)field));
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
}
// Get property values
foreach (var propertyMap in mapping.PropertyToGetMethodMap)
{
PropertyDefinition property = propertyMap.Key;
XTypeReference xType = XBuilder.AsTypeReference(compiler.Module, property.PropertyType);
MethodDefinition getter = propertyMap.Value;
Instruction branchIfNotSet;
Register[] valueRegs = CreateLoadValueSequence(seqp, body, xType, annotationReg, getter, compiler, targetPackage, out branchIfNotSet);
XModel.XMethodDefinition xSetMethod = XBuilder.AsMethodDefinition(compiler.Module, property.SetMethod);
var set = body.Instructions.Add(seqp, xSetMethod.Invoke(xSetMethod, null), null, new[] { attributeReg }.Concat(valueRegs).ToArray());
mapping.FixOperands.Add(Tuple.Create(set, (MemberReference)property.SetMethod));
branchIfNotSet.Operand = body.Instructions.Add(seqp, RCode.Nop);
}
// Return attribute
body.Instructions.Add(seqp, RCode.Return_object, attributeReg);
// Register method body
targetPackage.Record(new CompiledMethod() { DexMethod = method, RLBody = body });
// Return method
return method;
}