本文整理汇总了C#中Mono.Cecil.FieldDefinition类的典型用法代码示例。如果您正苦于以下问题:C# FieldDefinition类的具体用法?C# FieldDefinition怎么用?C# FieldDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDefinition类属于Mono.Cecil命名空间,在下文中一共展示了FieldDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Field
public Field(FieldDefinition fieldDefinition, Class declaringClass, Type type, int structIndex)
{
FieldDefinition = fieldDefinition;
DeclaringClass = declaringClass;
Type = type;
StructIndex = structIndex;
}
示例2: GetWeaver
public override IWeaver GetWeaver(MethodDefinition method, FieldDefinition mixin)
{
if (method.CustomAttributes.Any (a => a.AttributeType.FullName == Constants.AsyncStateMachineAttribute))
return GetAsyncMethodWeaver (method, mixin);
return new FakeWeaver ();
throw new NotImplementedException ();
}
示例3: AnalyzedFieldNode
public AnalyzedFieldNode(FieldDefinition analyzedField)
{
if (analyzedField == null)
throw new ArgumentNullException("analyzedField");
this.analyzedField = analyzedField;
this.LazyLoading = true;
}
示例4: Field
public Field(FieldDefinition fieldDefinition, Type declaringType, Type type, int structIndex)
{
FieldDefinition = fieldDefinition;
DeclaringType = declaringType;
Type = type;
StructIndex = structIndex;
}
示例5: WeaveInterceptionCall
private void WeaveInterceptionCall(
MethodDefinition methodToExtend,
MethodDefinition decoratedMethodParameter,
MethodDefinition implementationMethodParameter,
FieldDefinition interceptorManager)
{
methodToExtend.Body.InitLocals = true;
ILProcessor processor = methodToExtend.Body.GetILProcessor();
processor.Emit(OpCodes.Nop);
var decoratedMethodVar = methodToExtend.AddVariableDefinition("__fody$originalMethod", this.methodBaseTypeRef);
var implementationMethodVar = methodToExtend.AddVariableDefinition("__fody$implementationMethod", this.methodBaseTypeRef);
var parametersVar = methodToExtend.AddVariableDefinition("__fody$parameters", this.objectArrayTypeRef);
this.SaveMethodBaseToVariable(processor, decoratedMethodParameter, decoratedMethodVar);
if (implementationMethodParameter != null)
{
this.SaveMethodBaseToVariable(processor, implementationMethodParameter, implementationMethodVar);
}
processor.SaveParametersToNewObjectArray(parametersVar, methodToExtend.Parameters.ToArray());
this.CallInterceptMethod(interceptorManager, processor, decoratedMethodVar, implementationMethodVar, parametersVar);
HandleInterceptReturnValue(methodToExtend, processor);
// write method end
processor.Emit(OpCodes.Ret);
methodToExtend.Body.OptimizeMacros();
}
示例6: StateControllerRemover
public StateControllerRemover(MethodSpecificContext methodContext, FieldDefinition stateField = null)
{
this.methodContext = methodContext;
this.theCFG = methodContext.ControlFlowGraph;
this.stateField = stateField;
this.stateToStartBlock = new InstructionBlock[this.theCFG.Blocks.Length];
}
示例7: InjectLoadHook
static void InjectLoadHook()
{
// only hooking to V2 shouldn't be bad: V1 worlds won't have mod data in them, because 1.3 (and prism) only write as V2
var loadWorld = typeDef_WorldFile.GetMethod("loadWorld");
var lwb = loadWorld.Body;
var lwbproc = lwb.GetILProcessor();
MethodDefinition invokeLoadWorld;
var loadWorldDel = context.CreateDelegate("Terraria.PrismInjections", "WorldFile_OnLoadWorldDel", typeSys.Void, out invokeLoadWorld, typeSys.Boolean);
var onLoadWorld = new FieldDefinition("P_OnLoadWorld", FieldAttributes.Public | FieldAttributes.Static, loadWorldDel);
typeDef_WorldFile.Fields.Add(onLoadWorld);
OpCode[] toFind =
{
OpCodes.Br_S,
OpCodes.Ldloc_S,
OpCodes.Call, // wtf?
OpCodes.Stloc_S
};
Instruction[] toInject =
{
Instruction.Create(OpCodes.Ldsfld, onLoadWorld),
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Callvirt, invokeLoadWorld)
};
var instr = lwb.FindInstrSeqStart(toFind).Next.Next.Next.Next;
for (int i = 0; i < toInject.Length; i++)
lwbproc.InsertBefore(instr, toInject[i]);
}
示例8: FieldVisitor
//public FieldVisitor(ClassInfo classInfo, string name, string descriptor, string signature, object value,
// bool isFinal, bool isStatic, bool isPrivate)
//{
// Type type = ClrType.FromDescriptor(descriptor);
// classInfo.AddField(new FieldInfo(classInfo, name, type, isFinal, isStatic, isPrivate));
//}
public FieldVisitor(ClassInfo classInfo, FieldDefinition fieldDefinition)
{
//classInfo.AddField();
//Type type = ClrType.FromName(fieldDefinition.FieldType.FullName);
Type type = ClrType.FromDescriptor(fieldDefinition.FieldType.FullName);
classInfo.AddField(new FieldInfo(classInfo, fieldDefinition.Name, type, false, fieldDefinition.IsStatic, fieldDefinition.IsPrivate));
}
示例9: YieldFieldsInformation
public YieldFieldsInformation(FieldDefinition stateHolderField, FieldDefinition currentItemField,
VariableReference returnFlagVariable)
{
this.stateHolderField = stateHolderField;
this.currentItemField = currentItemField;
this.returnFlagVariable = returnFlagVariable;
}
示例10: ProcessField
protected override void ProcessField(FieldDefinition fieldDef)
{
if (fieldDef.IsPublic || fieldDef.IsFamily || fieldDef.IsFamilyOrAssembly) {
_members.Add(fieldDef);
}
base.ProcessField(fieldDef);
}
示例11: AsyncMethodWeaver
public AsyncMethodWeaver(IEngine engine, MethodDefinition method, FieldDefinition actorMixin, FieldDefinition stateMachineMixin)
{
_engine = engine;
_method = method;
_actorMixin = actorMixin;
_stateMachineMixin = stateMachineMixin;
}
示例12: Visit
protected override void Visit(FieldDefinition fieldDefinition, Unity.Cecil.Visitor.Context context)
{
if (!GenericsUtilities.CheckForMaximumRecursion(this._genericContext.Type))
{
base.Visit(fieldDefinition, context);
}
}
示例13: AddPropertyGetter
public static MethodDefinition AddPropertyGetter(
PropertyDefinition property
, MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.NewSlot | MethodAttributes.Virtual
, FieldDefinition backingField = null)
{
if (backingField == null)
{
// TODO: Try and find existing friendly named backingFields first.
backingField = AddPropertyBackingField(property);
}
var methodName = "get_" + property.Name;
var getter = new MethodDefinition(methodName, methodAttributes, property.PropertyType)
{
IsGetter = true,
Body = {InitLocals = true},
};
getter.Body.Variables.Add(new VariableDefinition(property.PropertyType));
var returnStart = Instruction.Create(OpCodes.Ldloc_0);
getter.Body.Instructions.Append(
Instruction.Create(OpCodes.Ldarg_0),
Instruction.Create(OpCodes.Ldfld, backingField),
Instruction.Create(OpCodes.Stloc_0),
Instruction.Create(OpCodes.Br_S, returnStart),
returnStart,
Instruction.Create(OpCodes.Ret)
);
property.GetMethod = getter;
property.DeclaringType.Methods.Add(getter);
return getter;
}
示例14: CreateNewField
/// <summary>
/// Creates a new field in the target assembly, for the specified type.
/// </summary>
/// <param name="targetDeclaringType">The target declaring type.</param>
/// <param name="yourField">Your field.</param>
/// <param name="attr">The action attribute.</param>
/// <exception cref="PatchDeclerationException">Thrown if this member collides with another member, and the error cannot be resolved.</exception>
/// <returns></returns>
private NewMemberStatus CreateNewField(TypeDefinition targetDeclaringType, FieldDefinition yourField,
NewMemberAttribute attr)
{
if (attr.IsImplicit) {
Log_implicitly_creating_member("field", yourField);
} else {
Log_creating_member("field", yourField);
}
var maybeDuplicate = targetDeclaringType.GetField(yourField.Name);
if (maybeDuplicate != null) {
Log_duplicate_member("field", yourField, maybeDuplicate);
if ((DebugOptions & DebugFlags.CreationOverwrites) != 0) {
Log_overwriting();
return NewMemberStatus.Continue;
}
if (attr.IsImplicit) {
return NewMemberStatus.InvalidItem;
}
throw Errors.Duplicate_member("type", yourField.FullName, maybeDuplicate.FullName);
}
var targetField =
new FieldDefinition(yourField.Name, yourField.Resolve().Attributes, FixTypeReference(yourField.FieldType)) {
InitialValue = yourField.InitialValue, //probably for string consts
Constant = yourField.Constant
};
targetDeclaringType.Fields.Add(targetField);
return NewMemberStatus.Continue;
}
示例15: Add
public void Add(FieldDefinition value)
{
if (!Contains (value))
Attach (value);
List.Add (value);
}