Beispiel #1
0
 public IMethod GetMethod(string funcname, MethodParamList types)
 {
     if (type_CLRSharp.HasMethods)
     {
         foreach (var m in type_CLRSharp.Methods)
         {
             if (m.Name != funcname)
             {
                 continue;
             }
             if ((types == null) ? !m.HasParameters : (m.Parameters.Count == types.Count))
             {
                 bool match = true;
                 for (int i = 0; i < ((types == null) ? 0 : types.Count); i++)
                 {
                     if (m.Parameters[i].ParameterType.FullName != types[i].FullName)
                     {
                         match = false;
                         break;
                     }
                 }
                 if (match)
                 {
                     return(new Method_Common_CLRSharp(this, m));
                 }
             }
         }
     }
     return(null);
 }
Beispiel #2
0
        IMethod GetNewForArray(object token)
        {
            Mono.Cecil.ModuleDefinition module = null;
            string typename = null;

            if (token is Mono.Cecil.TypeDefinition)
            {
                Mono.Cecil.TypeDefinition _def = (token as Mono.Cecil.TypeDefinition);
                module   = _def.Module;
                typename = _def.FullName;
            }
            else if (token is Mono.Cecil.TypeReference)
            {
                Mono.Cecil.TypeReference _ref = (token as Mono.Cecil.TypeReference);
                module   = _ref.Module;
                typename = _ref.FullName;
            }
            else
            {
                throw new NotImplementedException();
            }

            ICLRType _Itype = GetType(typename, module);

            typename += "[]";
            //var _type = context.environment.GetType(typename, type.Module);
            var _type = GetType(typename, module);

            MethodParamList tlist = MethodParamList.MakeList_OneParam_Int(environment);
            var             m     = _type.GetMethod(".ctor", tlist);

            return(m);
        }
            public Base_IEnumerator(CLRSharp_Instance inst)
            {
                ThreadContext activeContext = ThreadContext.activeContext;

                this.inst = inst;
                string[] methodNames = this.inst.type.GetMethodNames();
                string[] array       = methodNames;
                for (int i = 0; i < array.Length; i++)
                {
                    string text = array[i];
                    bool   flag = text.Contains("MoveNext");
                    if (flag)
                    {
                        this._MoveNext = this.inst.type.GetMethod(text, MethodParamList.constEmpty());
                    }
                    bool flag2 = text.Contains(".get_Current");
                    if (flag2)
                    {
                        this._get_Current = this.inst.type.GetMethod(text, MethodParamList.constEmpty());
                    }
                    bool flag3 = text.Contains(".Reset");
                    if (flag3)
                    {
                        this._Reset = this.inst.type.GetMethod(text, MethodParamList.constEmpty());
                    }
                }
            }
Beispiel #4
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);
        }
Beispiel #5
0
            public Base_IEnumerator(CLRSharp_Instance inst)
            {
                var context = ThreadContext.activeContext;

                this.inst = inst;
                var ms = this.inst.type.GetMethodNames();
                {
                    var __array1       = ms;
                    var __arrayLength1 = __array1.Length;
                    for (int __i1 = 0; __i1 < __arrayLength1; ++__i1)
                    {
                        var name = (string)__array1[__i1];
                        {
                            if (name.Contains("MoveNext"))
                            {
                                _MoveNext = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                            }
                            if (name.Contains(".get_Current"))
                            {
                                _get_Current = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                            }
                            if (name.Contains(".Reset"))
                            {
                                _Reset = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                            }
                        }
                    }
                }
            }
Beispiel #6
0
 public void Dispose()
 {
     var    context = ThreadContext.activeContext;
     var    _type   = context.environment.GetType(typeof(IDisposable));
     var    _method = this.inst.type.GetMethod("Dispose", MethodParamList.constEmpty());
     object obj     = _method.Invoke(context, inst, null);
 }
Beispiel #7
0
        public IMethod GetMethodT(string funcname, MethodParamList ttypes, MethodParamList types)
        {
            //这个实现还不完全
            //有个别重构下,判定比这个要复杂
            System.Reflection.MethodInfo _method = null;
            var ms = TypeForSystem.GetMethods();

            foreach (var m in ms)
            {
                if (m.Name == funcname && m.IsGenericMethodDefinition)
                {
                    var ts = m.GetGenericArguments();
                    var ps = m.GetParameters();
                    if (ts.Length == ttypes.Count && ps.Length == types.Count)
                    {
                        _method = m;
                        break;
                    }
                }
            }

            // _method = TypeForSystem.GetMethod(funcname, types.ToArraySystem());

            return(new Method_Common_System(this, _method.MakeGenericMethod(ttypes.ToArraySystem())));
        }
Beispiel #8
0
 public static MethodParamList constEmpty()
 {
     if (_ZeroParam == null)
     {
         _ZeroParam = new MethodParamList(new ICLRType[] { });
     }
     return(_ZeroParam);
 }
Beispiel #9
0
 public static MethodParamList MakeEmpty()
 {
     if (_ZeroParam == null)
     {
         _ZeroParam = new MethodParamList();
     }
     return(_ZeroParam);
 }
Beispiel #10
0
        public static MethodParamList const_OneParam_Int(ICLRSharp_Environment env)
        {
            if (_OneParam_Int == null)
            {
                _OneParam_Int = new MethodParamList(new ICLRType[] { env.GetType(typeof(int)) });
            }

            return(_OneParam_Int);
        }
Beispiel #11
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));
                    }
                }
            }
        }
Beispiel #12
0
        public static MethodParamList constEmpty()
        {
            bool flag = MethodParamList._ZeroParam == null;

            if (flag)
            {
                MethodParamList._ZeroParam = new MethodParamList(new ICLRType[0]);
            }
            return(MethodParamList._ZeroParam);
        }
Beispiel #13
0
        public static MethodParamList MakeList_OneParam_Int(ICLRSharp_Environment env)
        {
            if (_OneParam_Int == null)
            {
                _OneParam_Int = new MethodParamList();
                _OneParam_Int.Add(env.GetType(typeof(int).FullName, null));
            }

            return(_OneParam_Int);
        }
Beispiel #14
0
 public void Init(CLRSharp.ICLRSharp_Environment env)
 {
     if (bInited)
     {
         return;
     }
     if (bodyNative.HasVariables)
     {
         typelistForLoc = new MethodParamList(env, bodyNative.Variables);
     }
 }
Beispiel #15
0
        public IMethod GetMethod(string funcname, MethodParamList types)
        {
            if (funcname == ".ctor")
            {
                var con = TypeForSystem.GetConstructor(types.ToArraySystem());
                return(new Method_Common_System(this, con));
            }
            var method = TypeForSystem.GetMethod(funcname, types.ToArraySystem());

            return(new Method_Common_System(this, method));
        }
Beispiel #16
0
        public Method_Common_CLRSharp(Type_Common_CLRSharp type, Mono.Cecil.MethodDefinition method)
        {
            if (method == null)
            {
                throw new Exception("not allow null method.");
            }
            this._DeclaringType = type;

            method_CLRSharp = method;
            ReturnType      = type.env.GetType(method.ReturnType.FullName, null);
            ParamList       = new MethodParamList(type.env, method);
        }
Beispiel #17
0
        public IMethod GetMethod(string funcname, MethodParamList types)
        {
            bool    hasMethods = this.type_CLRSharp.HasMethods;
            IMethod result;

            if (hasMethods)
            {
                foreach (MethodDefinition current in this.type_CLRSharp.Methods)
                {
                    bool flag = current.Name != funcname;
                    if (!flag)
                    {
                        bool flag2 = (types == null) ? (!current.HasParameters) : (current.Parameters.Count == types.Count);
                        if (flag2)
                        {
                            bool flag3 = true;
                            for (int i = 0; i < ((types == null) ? 0 : types.Count); i++)
                            {
                                ICLRType type  = this.env.GetType(current.Parameters[i].ParameterType.FullName);
                                bool     flag4 = type.IsEnum();
                                if (flag4)
                                {
                                    bool flag5 = type.TypeForSystem != types[i].TypeForSystem;
                                    if (flag5)
                                    {
                                        flag3 = false;
                                        break;
                                    }
                                }
                                else
                                {
                                    bool flag6 = type != types[i];
                                    if (flag6)
                                    {
                                        flag3 = false;
                                        break;
                                    }
                                }
                            }
                            bool flag7 = flag3;
                            if (flag7)
                            {
                                result = new Method_Common_CLRSharp(this, current);
                                return(result);
                            }
                        }
                    }
                }
            }
            result = null;
            return(result);
        }
Beispiel #18
0
        public static MethodParamList const_OneParam_Int(ICLRSharp_Environment env)
        {
            bool flag = MethodParamList._OneParam_Int == null;

            if (flag)
            {
                MethodParamList._OneParam_Int = new MethodParamList(new ICLRType[]
                {
                    env.GetType(typeof(int))
                });
            }
            return(MethodParamList._OneParam_Int);
        }
Beispiel #19
0
 public Method_Common_System(ICLRType DeclaringType, System.Reflection.MethodBase method)
 {
     if (method == null)
     {
         throw new Exception("not allow null method.");
     }
     method_System      = method;
     this.DeclaringType = DeclaringType;
     if (method is System.Reflection.MethodInfo)
     {
         System.Reflection.MethodInfo info = method as System.Reflection.MethodInfo;
         ReturnType = DeclaringType.env.GetType(info.ReturnType);
     }
     ParamList = new MethodParamList(DeclaringType.env, method);
 }
Beispiel #20
0
        IMethod GetNewForArray(object token)
        {
            IMethod __method = null;

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

            if (token is Mono.Cecil.TypeDefinition)
            {
                Mono.Cecil.TypeDefinition _def = (token as Mono.Cecil.TypeDefinition);
                module   = _def.Module;
                typename = _def.FullName;
            }
            else if (token is Mono.Cecil.TypeReference)
            {
                Mono.Cecil.TypeReference _ref = (token as Mono.Cecil.TypeReference);
                module   = _ref.Module;
                typename = _ref.FullName;
            }
            else
            {
                throw new NotImplementedException();
            }

            ICLRType _type  = null;
            ICLRType _Itype = GetType(typename);

            if (_Itype is ICLRType_Sharp)
            {
                _type = environment.GetType(typeof(CLRSharp.CLRSharp_Instance[]));
            }
            else
            {
                typename += "[]";
                //var _type = context.environment.GetType(typename, type.Module);
                _type = GetType(typename);
            }
            MethodParamList tlist = MethodParamList.const_OneParam_Int(environment);
            var             m     = _type.GetMethod(".ctor", tlist);

            methodCache[token.GetHashCode()] = m;
            return(m);
        }
        public virtual IMethod GetMethod(string funcname, MethodParamList types)
        {
            bool    flag = funcname == ".ctor";
            IMethod result;

            if (flag)
            {
                ConstructorInfo constructor = this.TypeForSystem.GetConstructor(types.ToArraySystem());
                result = new Method_Common_System(this, constructor);
            }
            else
            {
                MethodInfo method = this.TypeForSystem.GetMethod(funcname, types.ToArraySystem());
                result = new Method_Common_System(this, method);
            }
            return(result);
        }
Beispiel #22
0
        public void Init(ICLRSharp_Environment env)
        {
            bool flag = this.bInited;

            if (!flag)
            {
                bool hasVariables = this.bodyNative.HasVariables;
                if (hasVariables)
                {
                    this.typelistForLoc = new MethodParamList(env, this.bodyNative.Variables);
                }
                for (int i = 0; i < this.bodyNative.Instructions.Count; i++)
                {
                    Instruction     instruction = this.bodyNative.Instructions[i];
                    CodeBody.OpCode opCode      = new CodeBody.OpCode();
                    opCode.code = (CodeEx)instruction.OpCode.Code;
                    opCode.addr = instruction.Offset;
                    bool flag2 = instruction.SequencePoint != null;
                    if (flag2)
                    {
                        bool flag3 = this.debugDoc == null;
                        if (flag3)
                        {
                            this.debugDoc = new Dictionary <string, int>();
                        }
                        bool flag4 = !this.debugDoc.ContainsKey(instruction.SequencePoint.Document.Url);
                        if (flag4)
                        {
                            this.debugDoc.Add(instruction.SequencePoint.Document.Url, instruction.SequencePoint.StartLine);
                        }
                        opCode.debugline = instruction.SequencePoint.StartLine;
                    }
                    this.opCodes.Add(opCode);
                    this.addr[opCode.addr] = i;
                }
                ThreadContext activeContext = ThreadContext.activeContext;
                for (int j = 0; j < this.bodyNative.Instructions.Count; j++)
                {
                    CodeBody.OpCode opCode2      = this.opCodes[j];
                    Instruction     instruction2 = this.bodyNative.Instructions[j];
                    opCode2.InitToken(activeContext, this, instruction2.Operand);
                }
                this.bInited = true;
            }
        }
Beispiel #23
0
        public void Init(CLRSharp.ICLRSharp_Environment env)
        {
            if (bInited)
            {
                return;
            }
            if (bodyNative.HasVariables)
            {
                typelistForLoc = new MethodParamList(env, bodyNative.Variables);
            }
            for (int i = 0; i < bodyNative.Instructions.Count; i++)
            {
                var    code = bodyNative.Instructions[i];
                OpCode c    = new OpCode();
                c.code = (CodeEx)(int)code.OpCode.Code;
                c.addr = code.Offset;
                if (code.SequencePoint != null)
                {
                    if (debugDoc == null)
                    {
                        debugDoc = new Dictionary <string, int>();
                    }
                    if (debugDoc.ContainsKey(code.SequencePoint.Document.Url) == false)
                    {
                        debugDoc.Add(code.SequencePoint.Document.Url, code.SequencePoint.StartLine);
                    }
                    c.debugline = code.SequencePoint.StartLine;
                }

                this.opCodes.Add(c);
                addr[c.addr] = i;;
            }
            var context = ThreadContext.activeContext;

            for (int i = 0; i < bodyNative.Instructions.Count; i++)
            {
                OpCode c    = opCodes[i];
                var    code = bodyNative.Instructions[i];
                c.InitToken(context, this, code.Operand);
            }
            bInited = true;
        }
Beispiel #24
0
 public IMethod GetMethod(string funcname, MethodParamList types)
 {
     if (type_CLRSharp.HasMethods)
     {
         foreach (var m in Methods)
         {
             if (m.Name != funcname)
             {
                 continue;
             }
             if ((types == null) ? !m.method_CLRSharp.HasParameters : (m.method_CLRSharp.Parameters.Count == types.Count))
             {
                 bool match = true;
                 for (int i = 0; i < ((types == null) ? 0 : types.Count); i++)
                 {
                     var envtype = env.GetType(m.method_CLRSharp.Parameters[i].ParameterType.FullName);
                     if (envtype.IsEnum())
                     {
                         if (envtype.TypeForSystem != types[i].TypeForSystem)
                         {
                             match = false;
                             break;
                         }
                     }
                     else
                     {
                         if (envtype != types[i])
                         {
                             match = false;
                             break;
                         }
                     }
                 }
                 if (match)
                 {
                     return(m);
                 }
             }
         }
     }
     return(null);
 }
Beispiel #25
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));
                    }
                }
            }
        }
Beispiel #26
0
        public virtual IMethod GetMethod(string funcname, MethodParamList types)
        {
            if (funcname == ".ctor")
            {
                var con = TypeForSystem.GetConstructor(types.ToArraySystem());
                return(new Method_Common_System(this, con));
            }
            else if (funcname == "Get" && TypeForSystem == typeof(int[, ]) && types.Count == 2 && types[0].TypeForSystem == typeof(int) && types[1].TypeForSystem == typeof(int))
            {
                return(new Method_Common_System(this, typeof(CustomMethod).GetMethod("GetTwoDimesionArray")));
            }
            var method = TypeForSystem.GetMethod(funcname, types.ToArraySystem());
            var ret    = new Method_Common_System(this, method);

            Func <object, object[], object> fastCall;

            if (FastCalls.TryGetValue(method, out fastCall))
            {
                ret.SetFastCall(fastCall);
            }

            return(ret);
        }
Beispiel #27
0
            public Base_IEnumerator(CLRSharp_Instance inst)
            {
                var context = ThreadContext.activeContext;

                this.inst = inst;
                var ms = this.inst.type.GetMethodNames();

                foreach (string name in ms)
                {
                    if (name.Contains("MoveNext"))
                    {
                        _MoveNext = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                    }
                    if (name.Contains(".get_Current"))
                    {
                        _get_Current = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                    }
                    if (name.Contains(".Reset"))
                    {
                        _Reset = this.inst.type.GetMethod(name, MethodParamList.constEmpty());
                    }
                }
            }
Beispiel #28
0
        public virtual IMethod GetMethodT(string funcname, MethodParamList ttypes, MethodParamList types)
        {
            if (funcname == "CompareExchange")
            {
                return(new Method_Common_System(this, typeof(CustomMethod).GetMethod("CompareExchange")));
            }

            //这个实现还不完全
            //有个别重构下,判定比这个要复杂
            System.Reflection.MethodInfo _method = null;
            var ms = TypeForSystem.GetMethods();

            {
                var __array4       = ms;
                var __arrayLength4 = __array4.Length;
                for (int __i4 = 0; __i4 < __arrayLength4; ++__i4)
                {
                    var m = __array4[__i4];
                    {
                        if (m.Name == funcname && m.IsGenericMethodDefinition)
                        {
                            var ts = m.GetGenericArguments();
                            var ps = m.GetParameters();
                            if (ts.Length == ttypes.Count && ps.Length == types.Count)
                            {
                                _method = m;
                                break;
                            }
                        }
                    }
                }
            }
            // _method = TypeForSystem.GetMethod(funcname, types.ToArraySystem());

            return(new Method_Common_System(this, _method.MakeGenericMethod(ttypes.ToArraySystem())));
        }
        public virtual IMethod GetMethodT(string funcname, MethodParamList ttypes, MethodParamList types)
        {
            MethodInfo methodInfo = null;

            MethodInfo[] methods = this.TypeForSystem.GetMethods();
            MethodInfo[] array   = methods;
            for (int i = 0; i < array.Length; i++)
            {
                MethodInfo methodInfo2 = array[i];
                bool       flag        = methodInfo2.Name == funcname && methodInfo2.IsGenericMethodDefinition;
                if (flag)
                {
                    Type[]          genericArguments = methodInfo2.GetGenericArguments();
                    ParameterInfo[] parameters       = methodInfo2.GetParameters();
                    bool            flag2            = genericArguments.Length == ttypes.Count && parameters.Length == types.Count;
                    if (flag2)
                    {
                        methodInfo = methodInfo2;
                        break;
                    }
                }
            }
            return(new Method_Common_System(this, methodInfo.MakeGenericMethod(ttypes.ToArraySystem())));
        }
Beispiel #30
0
 public IMethod GetMethodT(string funcname, MethodParamList ttypes, MethodParamList types)
 {
     return(null);
 }