当前位置: 首页>>代码示例>>C#>>正文


C# Cecil.FieldReference类代码示例

本文整理汇总了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;
 }
开发者ID:menozz,项目名称:mirelle,代码行数:7,代码来源:FieldNode.cs

示例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();
 }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:7,代码来源:ExprFieldAddress.cs

示例3: getField

 public MField getField(FieldReference fieldReference)
 {
     initFields();
     MField field;
     fieldReferenceToField.TryGetValue(new FieldReferenceKey(fieldReference), out field);
     return field;
 }
开发者ID:ostuda,项目名称:de4dot,代码行数:7,代码来源:MType.cs

示例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");
        }
开发者ID:poizan42,项目名称:SQLitePostProcess,代码行数:33,代码来源:Program.cs

示例5: convert

        public FieldReference convert(FieldReference fieldRef)
        {
            if (isInOurModule(fieldRef))
                return tryGetFieldDefinition(fieldRef);

            return new FieldReference(fieldRef.Name, convert(fieldRef.FieldType), convert(fieldRef.DeclaringType));
        }
开发者ID:huliang,项目名称:de4dot,代码行数:7,代码来源:MemberReferenceConverter.cs

示例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;
    }
开发者ID:dj-pgs,项目名称:PropertyChanged,代码行数:32,代码来源:HasEqualityChecker.cs

示例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;
 }
开发者ID:masroore,项目名称:db4o,代码行数:7,代码来源:MethodEmitter.cs

示例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);
        }
开发者ID:philiplaureano,项目名称:Taiji,代码行数:25,代码来源:AddAdapterConstructor.cs

示例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));
 }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:Extensions.cs

示例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));
        }
开发者ID:bling,项目名称:AOPDemo,代码行数:28,代码来源:DependencyPropertyWeaver.cs

示例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);
 }
开发者ID:adbancroft,项目名称:WeakEvents.Fody,代码行数:7,代码来源:WeakEventWeaver.cs

示例12: resolve

 public FieldInfo resolve(FieldReference fieldReference)
 {
     var resolver = getTypeResolver(fieldReference.DeclaringType);
     if (resolver != null)
         return resolver.resolve(fieldReference);
     return resolveGlobalField(fieldReference);
 }
开发者ID:ostuda,项目名称:de4dot,代码行数:7,代码来源:AssemblyResolver.cs

示例13: TryResolve

 public static FieldDefinition TryResolve(this IMetadataResolver metadataResolver, FieldReference fieldRef)
 {
     try {
         return metadataResolver.Resolve(fieldRef);
     } catch (AssemblyResolutionException) { }
     return null;
 }
开发者ID:arcanedreams,项目名称:Piranha,代码行数:7,代码来源:ResolutionExtensions.cs

示例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;
        }
开发者ID:ilkerhalil,项目名称:IL_Rewriting,代码行数:29,代码来源:Program.cs

示例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;
            }
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:25,代码来源:FieldReferenceReflectionEmitter.cs


注:本文中的Mono.Cecil.FieldReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。