本文整理汇总了C#中Mono.Cecil.FieldReference类的典型用法代码示例。如果您正苦于以下问题:C# FieldReference类的具体用法?C# FieldReference怎么用?C# FieldReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldReference类属于Mono.Cecil命名空间,在下文中一共展示了FieldReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FieldNode
public FieldNode(string name, SignatureNode type, bool isStatic = false, FieldReference field = null)
{
Name = name;
Field = field;
Type = type;
Static = isStatic;
}
示例2: ExprFieldAddress
public ExprFieldAddress(Ctx ctx, Expr obj, FieldReference field)
: base(ctx) {
this.Obj = obj;
this.Field = field;
this.ElementType = field.FieldType.FullResolve(field);
this.type = this.ElementType.MakePointer();
}
示例3: getField
public MField getField(FieldReference fieldReference)
{
initFields();
MField field;
fieldReferenceToField.TryGetValue(new FieldReferenceKey(fieldReference), out field);
return field;
}
示例4: EmitArchsInit
private static void EmitArchsInit(MethodBody body, FieldReference archRef, Action<Instruction> emit)
{
var module = body.Method.Module;
GenericInstanceType dictStrStrRef = (GenericInstanceType)archRef.FieldType;
TypeReference dictOpenRef = dictStrStrRef.ElementType;
GenericInstanceType iEqCompStrRef = new GenericInstanceType(module.Import(typeof(IEqualityComparer<>)));
iEqCompStrRef.GenericArguments.Add(dictOpenRef.GenericParameters[0]);
MethodReference dictStrStrCtor = CecilUtils.ImportInstanceMethodRef(module, dictStrStrRef, ".ctor", null, iEqCompStrRef);
MethodReference dictAddRef = CecilUtils.ImportInstanceMethodRef(module, dictStrStrRef, "Add", null, dictOpenRef.GenericParameters[0], dictOpenRef.GenericParameters[1]);
// Variables
body.Variables.Add(new VariableDefinition(dictStrStrRef));
int varIdx = body.Variables.Count - 1;
Instruction varSt = CecilUtils.ShortestStloc(varIdx);
Instruction varLd = CecilUtils.ShortestLdloc(varIdx);
emit(Instruction.Create(OpCodes.Ldnull));
emit(Instruction.Create(OpCodes.Newobj, dictStrStrCtor));
emit(varSt.Clone());
emit(varLd.Clone());
emit(Instruction.Create(OpCodes.Stsfld, archRef));
Action<string, string> emitAddPair = (k, v) =>
{
emit(varLd.Clone());
emit(Instruction.Create(OpCodes.Ldstr, k));
emit(Instruction.Create(OpCodes.Ldstr, v));
emit(Instruction.Create(OpCodes.Callvirt, dictAddRef));
};
emitAddPair("x86", "Win32");
emitAddPair("AMD64", "x64");
emitAddPair("IA64", "Itanium");
emitAddPair("ARM", "WinCE");
}
示例5: convert
public FieldReference convert(FieldReference fieldRef)
{
if (isInOurModule(fieldRef))
return tryGetFieldDefinition(fieldRef);
return new FieldReference(fieldRef.Name, convert(fieldRef.FieldType), convert(fieldRef.DeclaringType));
}
示例6: AlreadyHasEquality
public static bool AlreadyHasEquality(PropertyDefinition propertyDefinition, FieldReference backingFieldReference)
{
var instructions = propertyDefinition.SetMethod.Body.Instructions;
var list = instructions.Where(IsNotNop).ToList();
if (list.Count < 4)
{
return false;
}
var firstFive = list.Take(5).ToList();
if (firstFive.All(x => x.OpCode != OpCodes.Ldarg_1))
{
return false;
}
if (firstFive.All(x => x.OpCode != OpCodes.Ldarg_0))
{
return false;
}
if (firstFive.All(x => !x.IsEquality()))
{
return false;
}
if (firstFive.Any(x => x.Operand == backingFieldReference))
{
return true;
}
if (firstFive.Any(x => x.Operand == propertyDefinition))
{
return true;
}
return false;
}
示例7: FieldReferenceFor
private static FieldReference FieldReferenceFor(FieldReference field)
{
if (!IsGeneric(field.DeclaringType)) return field;
var reference = new FieldReference(field.Name, field.FieldType);
reference.DeclaringType = GenericReferenceFor(field.DeclaringType);
return reference;
}
示例8: AddConstructor
public void AddConstructor(TypeDefinition adapterType,
FieldReference targetField)
{
var adapterCtor = adapterType.AddDefaultConstructor();
var adapterParameter = new ParameterDefinition(_targetDependency);
adapterCtor.Parameters.Add(adapterParameter);
// HACK: Remove the ret instruction from the default constructor and replace it with
// the field setter
var adapterBody = adapterCtor.Body;
var adapterInstructions = adapterBody.Instructions.Cast<Instruction>().Where(i => i.OpCode != OpCodes.Ret).ToArray();
adapterBody.Instructions.Clear();
// Copy the old instructions
var IL = adapterBody.CilWorker;
foreach (var instruction in adapterInstructions)
{
IL.Append(instruction);
}
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Ldarg, adapterParameter);
IL.Emit(OpCodes.Stfld, targetField);
IL.Emit(OpCodes.Ret);
}
示例9: FindMatchingField
public static FieldDefinition FindMatchingField(this TypeDefinition tdef, FieldReference fref, bool throwOnNotFound = false)
{
if (throwOnNotFound)
return tdef.Fields.First(fdef => fdef.FieldMatches(fref));
else
return tdef.Fields.FirstOrDefault(fdef => fdef.FieldMatches(fref));
}
示例10: WeaveDependencyProperty
private void WeaveDependencyProperty(MethodBody staticCtorBody, FieldReference field, PropertyDefinition property)
{
var assembly = property.DeclaringType.Module.Assembly;
var propertyType = assembly.ImportType(Type.GetType(property.PropertyType.FullName));
var getTypeFromHandle = assembly.ImportMethod(typeof(Type).GetMethod("GetTypeFromHandle"));
var register = assembly.ImportMethod(typeof(DependencyProperty).GetMethod("Register", new[] { typeof(string), typeof(Type), typeof(Type) }));
// ignore previously weaved DPs
if (staticCtorBody.Instructions.Any(i => i.Operand != null && i.Operand.ToString() == field.ToString()))
{
return;
}
var ret = staticCtorBody.Instructions.Last();
if (ret.OpCode != OpCodes.Ret)
throw new InvalidOperationException("The last instruction should be OpCode.Ret");
HasChanges = true;
var proc = staticCtorBody.GetILProcessor();
proc.InsertBefore(ret, proc.Create(OpCodes.Ldstr, property.Name));
proc.InsertBefore(ret, proc.Create(OpCodes.Ldtoken, propertyType));
proc.InsertBefore(ret, proc.Create(OpCodes.Call, getTypeFromHandle));
proc.InsertBefore(ret, proc.Create(OpCodes.Ldtoken, property.DeclaringType));
proc.InsertBefore(ret, proc.Create(OpCodes.Call, getTypeFromHandle));
proc.InsertBefore(ret, proc.Create(OpCodes.Call, register));
proc.InsertBefore(ret, proc.Create(OpCodes.Stsfld, field));
}
示例11: WeakEventWeaver
public WeakEventWeaver(FieldReference eventDelegate, ModuleImporter moduleimporter)
{
_eventDelegate = eventDelegate.Resolve();
_moduleimporter = moduleimporter;
_closedGenericEventHandler = moduleimporter.GetClosedEventHandlerT(eventDelegate.FieldType.GetEventArgsType());
_isGenericHandler = _closedGenericEventHandler.FullName.Equals(eventDelegate.FieldType.FullName);
}
示例12: resolve
public FieldInfo resolve(FieldReference fieldReference)
{
var resolver = getTypeResolver(fieldReference.DeclaringType);
if (resolver != null)
return resolver.resolve(fieldReference);
return resolveGlobalField(fieldReference);
}
示例13: TryResolve
public static FieldDefinition TryResolve(this IMetadataResolver metadataResolver, FieldReference fieldRef)
{
try {
return metadataResolver.Resolve(fieldRef);
} catch (AssemblyResolutionException) { }
return null;
}
示例14: CreateEventRemoveMethod
private static MethodDefinition CreateEventRemoveMethod(AssemblyDefinition assemblyDefinition,
FieldReference propertyChangedFieldDefinition)
{
var removeMethodDefinition = assemblyDefinition.MainModule.Import(typeof(Delegate).GetMethod("Remove",
new[] { typeof(Delegate), typeof(Delegate) }));
var removePropertyChanged = new MethodDefinition("remove_PropertyChanged", MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.NewSlot |
MethodAttributes.HideBySig |
MethodAttributes.Virtual |
MethodAttributes.Final
, assemblyDefinition.MainModule.Import(typeof(void)));
removePropertyChanged.Overrides.Add(
assemblyDefinition.MainModule.Import(typeof(INotifyPropertyChanged).GetMethod("remove_PropertyChanged")));
removePropertyChanged.Parameters.Add(
new ParameterDefinition(assemblyDefinition.MainModule.Import(typeof(PropertyChangedEventHandler))));
var il = removePropertyChanged.Body.GetILProcessor();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, propertyChangedFieldDefinition);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, removeMethodDefinition);
il.Emit(OpCodes.Castclass, assemblyDefinition.MainModule.Import(typeof(PropertyChangedEventHandler)));
il.Emit(OpCodes.Stfld, propertyChangedFieldDefinition);
il.Emit(OpCodes.Ret);
return removePropertyChanged;
}
示例15: FieldReferenceReflectionEmitter
internal FieldReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals,
bool isSetter = false)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {
FieldReference = MemberReference.Annotation<FieldReference>();
IsByRef = MemberReference.Parent is DirectionExpression;
Type = FieldReference.FieldType.GetActualType();
FieldInfo = FieldReference.GetActualField();
NonPublic = !((FieldInfo.Attributes & (_publicFieldAttributes)) == _publicFieldAttributes);
if (isSetter) {
_emitAction = EmitStoreFieldReference;
_emitPrivateAction = EmitPrivateStoreFieldReference;
}
else {
_emitAction = EmitLoadFieldReference;
_emitPrivateAction = EmitPrivateLoadFieldReference;
}
}