Esempio n. 1
0
 public MethodParamList(ICLRSharp_Environment env, Mono.Cecil.GenericInstanceMethod method)
 {
     {
         // foreach(var p in method.GenericArguments)
         var __enumerator4 = (method.GenericArguments).GetEnumerator();
         while (__enumerator4.MoveNext())
         {
             var p = __enumerator4.Current;
             {
                 string paramname = p.FullName;
                 if (p.IsGenericParameter)
                 {
                     var typegen = method.DeclaringType as Mono.Cecil.GenericInstanceType;
                     if (p.Name[0] == '!')
                     {
                         int index = int.Parse(p.Name.Substring(1));
                         paramname = typegen.GenericArguments[index].FullName;
                     }
                 }
                 var type = env.GetType(paramname);
                 if (type.IsEnum())
                 {
                     type = env.GetType(type.TypeForSystem);
                 }
                 this.Add(type);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Takes a Flame method and converts it to a Cecil method reference.
        /// For this to work, <paramref name="field"/> cannot reference
        /// non-Cecil types or methods.
        /// </summary>
        /// <param name="field">
        /// The method to convert to a method reference.
        /// </param>
        /// <returns>
        /// A method reference.
        /// </returns>
        public static Mono.Cecil.MethodReference ImportReference(
            this Mono.Cecil.ModuleDefinition module,
            IMethod method)
        {
            if (method is ClrMethodDefinition)
            {
                var def = ((ClrMethodDefinition)method).Definition;
                return(module == null ? def : module.ImportReference(def));
            }
            else if (method is IndirectMethodSpecialization)
            {
                var specialization = (IndirectMethodSpecialization)method;
                return(CloneMethodWithDeclaringType(
                           module.ImportReference(specialization.Declaration),
                           module.ImportReference(specialization.ParentType)));
            }
            else if (method is DirectMethodSpecialization)
            {
                var specialization = (DirectMethodSpecialization)method;
                var genInst        = new Mono.Cecil.GenericInstanceMethod(
                    module.ImportReference(specialization.Declaration));

                foreach (var item in specialization.GenericArguments)
                {
                    genInst.GenericArguments.Add(module.ImportReference(item));
                }
                return(genInst);
            }
            else
            {
                throw new NotSupportedException($"Cannot import ill-understood method '{method.FullName}'.");
            }
        }
Esempio n. 3
0
        IMethod GetMethod(object token)
        {
            Mono.Cecil.ModuleDefinition module = null;
            string          methodname         = null;
            string          typename           = null;
            MethodParamList genlist            = null;
            MethodParamList list = null;

            if (token is Mono.Cecil.MethodReference)
            {
                Mono.Cecil.MethodReference _ref = (token as Mono.Cecil.MethodReference);
                module     = _ref.Module;
                methodname = _ref.Name;
                typename   = _ref.DeclaringType.FullName;
                list       = new MethodParamList(environment, _ref);
                if (_ref.IsGenericInstance)
                {
                    Mono.Cecil.GenericInstanceMethod gmethod = _ref as Mono.Cecil.GenericInstanceMethod;
                    genlist = new MethodParamList(environment, gmethod);
                }
            }
            else if (token is Mono.Cecil.MethodDefinition)
            {
                Mono.Cecil.MethodDefinition _def = token as Mono.Cecil.MethodDefinition;
                module     = _def.Module;
                methodname = _def.Name;
                typename   = _def.DeclaringType.FullName;
                list       = new MethodParamList(environment, _def);
                if (_def.IsGenericInstance)
                {
                    throw new NotImplementedException();
                    //Mono.Cecil.GenericInstanceMethod gmethod = _def as Mono.Cecil.GenericInstanceMethod;
                    //genlist = new MethodParamList(environment, gmethod);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            var typesys = GetType(typename, module);

            if (typesys == null)
            {
                throw new Exception("type can't find:" + typename);
            }


            IMethod _method = null;

            if (genlist != null)
            {
                _method = typesys.GetMethodT(methodname, genlist, list);
            }
            else
            {
                _method = typesys.GetMethod(methodname, list);
            }

            return(_method);
        }
Esempio n. 4
0
        public MethodParamList(ICLRSharp_Environment env, Mono.Cecil.MethodReference method)
        {
            if (method.HasParameters)
            {
                Mono.Cecil.GenericInstanceType _typegen = null;
                _typegen = method.DeclaringType as Mono.Cecil.GenericInstanceType;
                Mono.Cecil.GenericInstanceMethod gm = method as Mono.Cecil.GenericInstanceMethod;
                MethodParamList _methodgen          = null;
                if (gm != null)
                {
                    _methodgen = new MethodParamList(env, gm);
                }
                foreach (var p in method.Parameters)
                {
                    string paramname = p.ParameterType.FullName;

                    if (p.ParameterType.IsGenericParameter)
                    {
                        if (p.ParameterType.Name.Contains("!!"))
                        {
                            int index = int.Parse(p.ParameterType.Name.Substring(2));
                            paramname = _methodgen[index].FullName;
                        }
                        else if (p.ParameterType.Name.Contains("!"))
                        {
                            int index = int.Parse(p.ParameterType.Name.Substring(1));
                            paramname = _typegen.GenericArguments[index].FullName;
                        }
                    }

                    if (paramname.Contains("!!"))
                    {
                        //string typename = param.ParameterType.FullName;
                        for (int i = 0; i < _methodgen.Count; i++)
                        {
                            string pp = "!!" + i.ToString();
                            paramname = paramname.Replace(pp, _methodgen[i].FullName);
                        }
                        //this.Add(GetTType(env, p, _methodgen));
                    }

                    if (paramname.Contains("!"))//函数有T
                    {
                        var gens = (method.DeclaringType as Mono.Cecil.GenericInstanceType).GenericArguments;
                        for (int i = 0; i < gens.Count; i++)
                        {
                            string pp = "!" + i.ToString();
                            paramname = paramname.Replace(pp, gens[i].FullName);
                        }
                    }
                    //else
                    {
                        this.Add(env.GetType(paramname));
                    }
                }
            }
        }
Esempio n. 5
0
 public MethodParamList(ICLRSharp_Environment env, Mono.Cecil.GenericInstanceMethod method)
 {
     foreach (var p in method.GenericArguments)
     {
         string paramname = p.FullName;
         if (p.IsGenericParameter)
         {
             var typegen = method.DeclaringType as Mono.Cecil.GenericInstanceType;
             if (p.Name[0] == '!')
             {
                 int index = int.Parse(p.Name.Substring(1));
                 paramname = typegen.GenericArguments[index].FullName;
             }
         }
         this.Add(env.GetType(paramname));
     }
 }
Esempio n. 6
0
        public MethodParamList(ICLRSharp_Environment env, Mono.Cecil.MethodReference method)
        {
            if (method.HasParameters)
            {
                Mono.Cecil.GenericInstanceType _typegen = null;
                _typegen = method.DeclaringType as Mono.Cecil.GenericInstanceType;
                Mono.Cecil.GenericInstanceMethod gm = method as Mono.Cecil.GenericInstanceMethod;
                MethodParamList _methodgen          = null;
                if (gm != null)
                {
                    _methodgen = new MethodParamList(env, gm);
                }
                foreach (var p in method.Parameters)
                {
                    string paramname = p.ParameterType.FullName;

                    if (p.ParameterType.IsGenericParameter)
                    {
                        if (p.ParameterType.Name.Contains("!!"))
                        {
                            int index = int.Parse(p.ParameterType.Name.Substring(2));
                            paramname = _methodgen[index].FullName;
                        }
                        else if (p.ParameterType.Name.Contains("!"))
                        {
                            int index = int.Parse(p.ParameterType.Name.Substring(1));
                            paramname = _typegen.GenericArguments[index].FullName;
                        }
                    }

                    if (paramname.Contains("!!"))
                    {
                        this.Add(GetTType(env, p, method, _methodgen));
                    }
                    else
                    {
                        this.Add(env.GetType(paramname, method.Module));
                    }
                }
            }
        }
Esempio n. 7
0
        public IMethod GetMethod(object token)
        {
            IMethod __method = null;

            if (methodCache.TryGetValue(token.GetHashCode(), out __method))
            {
                return(__method);
            }
            Mono.Cecil.ModuleDefinition module = null;
            string          methodname         = null;
            string          typename           = null;
            MethodParamList genlist            = null;
            MethodParamList list = null;

            if (token is Mono.Cecil.MethodReference)
            {
                Mono.Cecil.MethodReference _ref = (token as Mono.Cecil.MethodReference);
                module     = _ref.Module;
                methodname = _ref.Name;
                typename   = _ref.DeclaringType.FullName;
                list       = new MethodParamList(environment, _ref);
                if (_ref.IsGenericInstance)
                {
                    Mono.Cecil.GenericInstanceMethod gmethod = _ref as Mono.Cecil.GenericInstanceMethod;
                    genlist = new MethodParamList(environment, gmethod);
                }
            }
            else if (token is Mono.Cecil.MethodDefinition)
            {
                Mono.Cecil.MethodDefinition _def = token as Mono.Cecil.MethodDefinition;
                module     = _def.Module;
                methodname = _def.Name;
                typename   = _def.DeclaringType.FullName;
                list       = new MethodParamList(environment, _def);
                if (_def.IsGenericInstance)
                {
                    throw new NotImplementedException();
                    //Mono.Cecil.GenericInstanceMethod gmethod = _def as Mono.Cecil.GenericInstanceMethod;
                    //genlist = new MethodParamList(environment, gmethod);
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            var typesys = GetType(typename);

            if (typesys == null)
            {
                typename = typename.Replace("0...", "");
                typesys  = GetType(typename);
            }
            if (typesys == null)
            {
                throw new Exception("type can't find:" + typename);
            }

            IMethod _method = null;

            if (genlist != null)
            {
                _method = typesys.GetMethodT(methodname, genlist, list);
            }
            else
            {
                _method = typesys.GetMethod(methodname, list);
            }
            methodCache[token.GetHashCode()] = _method;
            return(_method);
        }