本文整理汇总了C#中DexTargetPackage.GetOrCreateGeneratedCodeClass方法的典型用法代码示例。如果您正苦于以下问题:C# DexTargetPackage.GetOrCreateGeneratedCodeClass方法的具体用法?C# DexTargetPackage.GetOrCreateGeneratedCodeClass怎么用?C# DexTargetPackage.GetOrCreateGeneratedCodeClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DexTargetPackage
的用法示例。
在下文中一共展示了DexTargetPackage.GetOrCreateGeneratedCodeClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFieldToDeclaringClass
/// <summary>
/// Add the given field to its declaring class.
/// </summary>
protected override void AddFieldToDeclaringClass(ClassDefinition declaringClass, DexLib.FieldDefinition dfield, DexTargetPackage targetPackage)
{
var generatedCodeClass = targetPackage.GetOrCreateGeneratedCodeClass();
UpdateName(dfield, generatedCodeClass);
dfield.Owner = generatedCodeClass;
generatedCodeClass.Fields.Add(dfield);
}
示例2: AddMethodToDeclaringClass
/// <summary>
/// Add the given method to its declaring class.
/// </summary>
protected override void AddMethodToDeclaringClass(ClassDefinition declaringClass, DexLib.MethodDefinition dmethod, DexTargetPackage targetPackage)
{
var generatedCodeClass = targetPackage.GetOrCreateGeneratedCodeClass();
UpdateName(dmethod, generatedCodeClass);
dmethod.Owner = generatedCodeClass;
generatedCodeClass.Methods.Add(dmethod);
}
示例3: Create
/// <summary>
/// Create the current type as class definition.
/// </summary>
internal static DelegateInstanceType Create(
ISourceLocation sequencePoint,
AssemblyCompiler compiler,
DexTargetPackage targetPackage,
ClassDefinition delegateClass,
XMethodDefinition invokeMethod,
Prototype invokePrototype,
XMethodDefinition equalsMethod,
Prototype equalsPrototype,
XMethodDefinition calledMethod)
{
// Prepare called method
var target = targetPackage.DexFile;
var owner = target.GetClass(calledMethod.DeclaringType.GetClassReference(targetPackage).Fullname) ??
targetPackage.GetOrCreateGeneratedCodeClass();
var calledMethodPrototype = PrototypeBuilder.BuildPrototype(compiler, targetPackage, owner, calledMethod);
var calledMethodRef = calledMethod.GetReference(targetPackage);
if (calledMethod.DeclaringType.HasDexImportAttribute())
{
// Delegate method is a Dex import method
}
else
{
// Delegate method is a .NET method
var calledDexMethod = owner.Methods.Single(x => (x.Name == calledMethodRef.Name) && (x.Prototype.Equals(calledMethodRef.Prototype)));
if (calledDexMethod.IsPrivate)
{
calledDexMethod.IsPrivate = false;
calledDexMethod.IsProtected = true;
}
}
var @class = new ClassDefinition();
@class.Name = CreateInstanceTypeName(owner);
@class.Namespace = owner.Namespace;
@class.AccessFlags = AccessFlags.Public | AccessFlags.Final;
owner.InnerClasses.Add(@class);
// Set super class
@class.SuperClass = delegateClass;
// Implement delegate interface
//@class.Interfaces.Add(delegateInterface);
// Get type of instance
XTypeDefinition instanceType = calledMethod.DeclaringType;
TypeReference instanceTypeRef = instanceType.GetReference(targetPackage);
// Add instance field
FieldDefinition instanceField = null;
if (!calledMethod.IsStatic)
{
instanceField = new FieldDefinition();
instanceField.Name = "instance";
instanceField.Owner = @class;
instanceField.Type = instanceTypeRef;
instanceField.AccessFlags = AccessFlags.Private | AccessFlags.Final;
@class.Fields.Add(instanceField);
}
// Add ctor
var ctor = new Dot42.DexLib.MethodDefinition();
ctor.Owner = @class;
ctor.Name = "<init>";
ctor.AccessFlags = AccessFlags.Public | AccessFlags.Constructor;
ctor.Prototype = new Prototype(PrimitiveType.Void);
if (!calledMethod.IsStatic)
{
ctor.Prototype.Parameters.Add(new Parameter(instanceTypeRef, "this"));
}
@class.Methods.Add(ctor);
// Create ctor body
var ctorBody = CreateCtorBody(calledMethod, instanceField, delegateClass);
targetPackage.Record(new CompiledMethod() { DexMethod = ctor, RLBody = ctorBody });
// Add Invoke method
var invoke = new Dot42.DexLib.MethodDefinition(@class, "Invoke", invokePrototype) { AccessFlags = AccessFlags.Public };
@class.Methods.Add(invoke);
// Create body
var invokeBody = CreateInvokeBody(sequencePoint, compiler, targetPackage, calledMethod, invokeMethod, invokePrototype, calledMethodPrototype, instanceField, delegateClass);
targetPackage.Record(new CompiledMethod() { DexMethod = invoke, RLBody = invokeBody });
// Add Equals method
if (null != equalsMethod)
{
var equals = new Dot42.DexLib.MethodDefinition(@class, "equals", equalsPrototype) { AccessFlags = AccessFlags.Public };
@class.Methods.Add(equals);
// Create body
if (!calledMethod.IsStatic)
{
var equalsBody = CreateEqualsBody(sequencePoint, compiler, targetPackage, equalsMethod, equalsPrototype, instanceField, @class);
targetPackage.Record(new CompiledMethod() { DexMethod = equals, RLBody = equalsBody });
}
else
{
var equalsBody = CreateEqualsBody();
//.........这里部分代码省略.........