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


C# MethodReference.Resolve方法代码示例

本文整理汇总了C#中Mono.Cecil.MethodReference.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# MethodReference.Resolve方法的具体用法?C# MethodReference.Resolve怎么用?C# MethodReference.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Cecil.MethodReference的用法示例。


在下文中一共展示了MethodReference.Resolve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsSetup

 public bool IsSetup(MethodReference target)
 {
     if (!IsInFixture(target)) return false;
     var field = MSpecTranslator.TranslateGeneratedMethod(target.Resolve());
     if (field == null) return false;
     return field.FieldType.Name == "Establish" || field.FieldType.Name == "Because";
 }
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:7,代码来源:mSpecTestIdentifier.cs

示例2: MethodMatch

        static bool MethodMatch(MethodReference candidate, MethodReference method)
        {
            var candidateResolved = candidate.Resolve();

            // Check overrides
            if (candidateResolved.HasOverrides)
            {
                foreach (var @override in candidateResolved.Overrides)
                {
                    var resolvedOverride = ResolveGenericsVisitor.Process(candidate, @override);
                    return MemberEqualityComparer.Default.Equals(resolvedOverride, method);
                }
            }

            if (!candidateResolved.IsVirtual)
                return false;

            if (candidate.Name != method.Name)
                return false;

            if (!TypeMatch(ResolveGenericsVisitor.Process(candidate, candidate.ReturnType), ResolveGenericsVisitor.Process(method, method.ReturnType)))
                return false;

            if (candidate.Parameters.Count != method.Parameters.Count)
                return false;

            for (int i = 0; i < candidate.Parameters.Count; i++)
                if (!TypeMatch(ResolveGenericsVisitor.Process(candidate, candidate.Parameters[i].ParameterType), ResolveGenericsVisitor.Process(method, method.Parameters[i].ParameterType)))
                    return false;

            return true;
        }
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:32,代码来源:CecilExtensions.TypeMap.cs

示例3: DoesMatchMethod

 private static bool DoesMatchMethod(MethodReference mInternal, MethodReference m) {
     var mInternalDef = mInternal.Resolve();
     if (mInternalDef.GetCustomAttribute<JsRedirectAttribute>() != null) {
         // Can never return a redirected method
         return false;
     }
     // Look for methods with custom signatures
     var detailsAttr = mInternalDef.GetCustomAttribute<JsDetailAttribute>(true);
     if (detailsAttr != null) {
         var signature = detailsAttr.Properties.FirstOrDefault(x => x.Name == "Signature");
         if (signature.Name != null) {
             if (mInternal.Name != m.Name) {
                 return false;
             }
             var sigTypes = ((CustomAttributeArgument[])signature.Argument.Value)
                 .Select(x => ((TypeReference)x.Value).FullResolve(m))
                 .ToArray();
             var mReturnType = m.ReturnType.FullResolve(m);
             if (!mReturnType.IsSame(sigTypes[0])) {
                 return false;
             }
             for (int i = 0; i < m.Parameters.Count; i++) {
                 var mParameterType = m.Parameters[i].ParameterType.FullResolve(m);
                 if (!mParameterType.IsSame(sigTypes[i + 1])) {
                     return false;
                 }
             }
             return true;
         }
     }
     // Look for C# method that matches with custom 'this'
     Func<bool> isFakeThis = () => {
         if (mInternal.HasThis) {
             return false;
         }
         if (mInternal.Name != m.Name) {
             return false;
         }
         if (mInternal.Parameters.Count != m.Parameters.Count + 1) {
             return false;
         }
         if (mInternal.Parameters[0].GetCustomAttribute<JsFakeThisAttribute>() == null) {
             return false;
         }
         if (!mInternal.ReturnType.IsSame(m.ReturnType)) {
             return false;
         }
         for (int i = 1; i < mInternal.Parameters.Count; i++) {
             if (!mInternal.Parameters[i].ParameterType.IsSame(m.Parameters[i - 1].ParameterType)) {
                 return false;
             }
         }
         return true;
     };
     if (isFakeThis()) {
         return true;
     }
     // Look for C# method that match signature
     return mInternal.MatchMethodOnly(m);
 }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:60,代码来源:JsResolver.cs

示例4: FindGetLogger

    void FindGetLogger(TypeDefinition typeDefinition)
    {
        if (!typeDefinition.IsPublic)
        {
            var message = $"The logger factory type '{typeDefinition.FullName}' needs to be public.";
            throw new WeavingException(message);
        }
        GetLoggerMethod = typeDefinition
            .Methods
            .FirstOrDefault(x =>
                x.Name ==  "GetLogger" && 
                x.IsStatic &&
                x.HasGenericParameters &&
                x.GenericParameters.Count == 1 &&
                x.Parameters.Count == 0);

        if (GetLoggerMethod == null)
        {
            throw new WeavingException("Found 'LoggerFactory' but it did not have a static 'GetLogger' method that takes 'string' as a parameter");
        }
        if (!GetLoggerMethod.Resolve().IsPublic)
        {
            var message = $"The logger factory method '{GetLoggerMethod.FullName}' needs to be public.";
            throw new WeavingException(message);
        }
    }
开发者ID:AndreGleichner,项目名称:Anotar,代码行数:26,代码来源:LoggerFactoryFinder.cs

示例5: Function

        public Function(Type declaringType, MethodReference methodReference, TypeRef functionType, ValueRef generatedValue, FunctionSignature signature)
        {
            Signature = signature;
            DeclaringType = declaringType;
            MethodReference = methodReference;
            FunctionType = functionType;
            GeneratedValue = generatedValue;
            VirtualSlot = -1;

            MethodDefinition = methodReference.Resolve();

            ParameterTypes = signature.ParameterTypes.Select(x => x.Type).ToArray();

            // Generate function type when being called from vtable/IMT (if it applies)
            // If declaring type is a value type, needs to unbox "this" for virtual method
            if (DeclaringType.TypeDefinitionCecil.IsValueType
                && (MethodDefinition.Attributes & MethodAttributes.Virtual) != 0)
            {
                bool hasStructValueReturn = signature.ReturnType.ABIParameterInfo.Kind == ABIParameterInfoKind.Indirect;

                // Create function type with boxed "this"
                var argumentCount = LLVM.CountParamTypes(FunctionType);
                var argumentTypes = new TypeRef[argumentCount];
                LLVM.GetParamTypes(FunctionType, argumentTypes);
                // Change first type to boxed "this"
                var thisIndex = hasStructValueReturn ? 1 : 0;
                argumentTypes[thisIndex] = LLVM.PointerType(DeclaringType.ObjectTypeLLVM, 0);
                VirtualFunctionType = LLVM.FunctionType(LLVM.GetReturnType(FunctionType), argumentTypes, LLVM.IsFunctionVarArg(FunctionType));
            }
            else
            {
                VirtualFunctionType = FunctionType;
            }
        }
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:34,代码来源:Function.cs

示例6: Method

        public Method(MethodReference methodReference, ComponentCache componentCache)
        {
            Contract.Requires<ArgumentNullException>(methodReference != null);
            Contract.Requires<ArgumentNullException>(componentCache != null);

            method = methodReference.Resolve();
            cache = componentCache;
        }
开发者ID:artur02,项目名称:Dependency,代码行数:8,代码来源:Method.cs

示例7: Create

        public static string Create(MethodReference mRef, Resolver resolver, ICode ast) {
            if (mRef.ContainsGenericParameters()) {
                throw new ArgumentException("Cannot create JS for method with open generic parameters");
            }
            var mDef = mRef.Resolve();
            if (mDef.IsAbstract) {
                throw new ArgumentException("Should never need to transcode an abstract method");
            }
            var tRef = mRef.DeclaringType;
            var tDef = tRef.Resolve();

            var v = new JsMethod(resolver);
            v.Visit(ast);
            var js = v.js.ToString();

            var sb = new StringBuilder();
            // Method declaration
            var methodName = resolver.MethodNames[mRef];
            //var parameterNames = mRef.Parameters.Select(x => v.parameters.ValueOrDefault(x).NullThru(y => resolver.LocalVarNames[y])).ToArray();
            // Match parameters, but have to do by position, as method built may be a custom method replacing a BCL method,
            // so parameters are not the same.
            var parameterNames = mRef.Parameters.Select(x => v.parameters.FirstOrDefault(y => y.Key.Sequence == x.Sequence).Value.NullThru(y => resolver.LocalVarNames[y])).ToArray();
            if (!mDef.IsStatic) {
                var thisName = v.vars.FirstOrDefault(x => x.ExprType == Expr.NodeType.VarThis).NullThru(x => resolver.LocalVarNames[x]);
                parameterNames = parameterNames.Prepend(thisName).ToArray();
            }
            var unusedParameterNameGen = new NameGenerator();
            parameterNames = parameterNames.Select(x => x ?? ("_" + unusedParameterNameGen.GetNewName())).ToArray();
            sb.AppendFormat("// {0}", mRef.FullName);
            sb.AppendLine();
            sb.AppendFormat("var {0} = function({1}) {{", methodName, string.Join(", ", parameterNames));
            // Variable declarations
            var declVars = v.vars
                .Select(x => new { name = resolver.LocalVarNames[x], type = x.Type })
                .Where(x => !parameterNames.Contains(x.name))
                .Select(x => {
                    var name = x.name;
                    if (x.type.IsValueType) {
                        name += " = " + DefaultValuer.Get(x.type, resolver.FieldNames);
                    }
                    return name;
                })
                .Distinct() // Bit of a hack, but works for now
                .ToArray();
            if (declVars.Any()) {
                sb.AppendLine();
                sb.Append(' ', tabSize);
                sb.AppendFormat("var {0};", string.Join(", ", declVars));
            }
            // Method body
            sb.AppendLine(js);
            // Method ending
            sb.AppendLine("};");

            var sbStr = sb.ToString();
            return sbStr;
        }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:57,代码来源:JsMethod.cs

示例8: HasMethod

 private bool HasMethod(MethodReference method)
 {
     foreach (var baseMethod in _baseMethodsSet) {
     if (baseMethod.Class == method.DeclaringType && baseMethod.Definition == method.Resolve()) {
       return true;
     }
       }
       return false;
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:9,代码来源:BaseClassCallsMutator.cs

示例9: CloneMethodAttributes

 private static void CloneMethodAttributes(MethodReference sourceMethod, MethodReference clonedMethod)
 {
     var s = sourceMethod.Resolve();
     var c = clonedMethod.Resolve();
     c.CallingConvention = s.CallingConvention;
     c.SemanticsAttributes = s.SemanticsAttributes;
     s.CustomAttributes.ToList().ForEach(a => c.CustomAttributes.Add(a));
     s.SecurityDeclarations.ToList().ForEach(sd => c.SecurityDeclarations.Add(sd));
 }
开发者ID:fir3pho3nixx,项目名称:cryo-aop,代码行数:9,代码来源:MethodCloneFactory.cs

示例10: GetFactoryMethod

 public MethodDefinition GetFactoryMethod(MethodReference ctor, AssemblyDefinition assembly, IAssemblyTracker tracker)
 {
     if (!_factoryMethods.ContainsKey (ctor))
       {
     var memberId = CecilResolver.CreateMemberID (ctor.Resolve());
     AssemblyNameReference containingTrackedAssembly;
     _factoryMethods[ctor] = CecilResolver.ResolveToMethodDefinition (_infoProvider.GetFactoryMethodFunc (memberId), tracker, out containingTrackedAssembly);
     if (containingTrackedAssembly != null)
       tracker.TrackNewReference (assembly, containingTrackedAssembly);
       }
       return _factoryMethods[ctor];
 }
开发者ID:rubicon-oss,项目名称:AssemblyTransformer,代码行数:12,代码来源:NewTransformerInfoWrapper.cs

示例11: IsAssertMethod

 protected virtual bool IsAssertMethod(MethodReference methodReference)
 {
     var resolved = methodReference.Resolve();
     var name = resolved.DeclaringType.Name;
     if (!resolved.IsStatic || !name.EndsWith("Assert"))
     {
         return false;
     }
     else
     {
         return true;
     }
 }
开发者ID:jason-roberts,项目名称:AssertMessage,代码行数:13,代码来源:ProcessorBase.cs

示例12: CloneIntoType

        public MethodDefinition CloneIntoType(MethodReference sourceMethod, TypeDefinition type)
        {
            var s = sourceMethod.Resolve();
            var c = new MethodDefinition(s.Name, s.Attributes, s.ReturnType);
            type.Methods.Add(c);

            CloneMethodProperties(c, s);
            CloneMethodAttributes(c, s);
            CloneMethodParameters(s, c);
            CloneGenericParameters(s, c);

            return c;
        }
开发者ID:fir3pho3nixx,项目名称:cryo-aop,代码行数:13,代码来源:MethodCloneFactory.cs

示例13: ResolveMethod

 private MethodDefinition ResolveMethod(MethodReference aRef)
 {
     var xDef = aRef as MethodDefinition;
     if (xDef != null)
     {
         return xDef;
     }
     var xSpec = aRef as GenericInstanceMethod;
     if (xSpec != null)
     {
         throw new Exception("Queueing generic methods not yet(?) supported!");
     }
     return aRef.Resolve();
 }
开发者ID:Orvid,项目名称:Cosmos,代码行数:14,代码来源:Reader.MonoHelpers.cs

示例14: Ctx

 public Ctx(TypeReference tRef, MethodReference mRef, Ctx fromCtx = null) {
     this.TRef = tRef;
     this.TDef = tRef.Resolve();
     this.MRef = mRef;
     this.MDef = mRef.Resolve();
     this.HasFakeThis = mRef.Parameters.FirstOrDefault().NullThru(x => x.GetCustomAttribute<JsFakeThisAttribute>() != null);
     this.Module = mRef.Module;
     this.TypeSystem = mRef.Module.TypeSystem;
     this.ExprGen = Expr.CreateExprGen(this);
     this.This = fromCtx == null ? (this.MDef.IsStatic ? null : new ExprVarThis(this, tRef)) : fromCtx.This;
     this.type = new Lazy<TypeReference>(() => this.Module.Import(typeof(Type)));
     this._int64 = new Lazy<TypeReference>(() => this.Module.Import(typeof(Cls._Int64)));
     this._uint64 = new Lazy<TypeReference>(() => this.Module.Import(typeof(Cls._UInt64)));
 }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:14,代码来源:Ctx.cs

示例15: GetOrCreateIndex

 public uint GetOrCreateIndex(MethodReference method, IMetadataCollection metadataCollection)
 {
     if (method == null)
     {
         return 0;
     }
     if (method.IsGenericInstance || method.DeclaringType.IsGenericInstance)
     {
         Il2CppGenericMethodCollectorWrite.Add(method);
         if (Il2CppGenericMethodCollectorRead.HasIndex(method))
         {
             return (Il2CppGenericMethodCollectorRead.GetIndex(method) | 0xc0000000);
         }
         return 0xc0000000;
     }
     return (uint) (metadataCollection.GetMethodIndex(method.Resolve()) | 0x60000000);
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:17,代码来源:Il2CppMethodReferenceCollectorComponent.cs


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