Пример #1
0
        public TypeDefine(SilAPI.DisassembledIlClass inputType)
        {
            TypeDefinition = inputType;

            foreach (var methodDefinition in TypeDefinition.Methods)
            {
                methodDefinition.ReadBody();
                List <string> lines = methodDefinition.BodyLines;
                var           codes = ILCodeParse.ReadILCodes(lines.ToArray(), methodDefinition.LocalList,
                                                              methodDefinition.ParametersList);
                bool haseResult = methodDefinition.ReturnType.IsVoid();
                if (methodDefinition.IsCtor)
                {
                    haseResult = true;
                }
                var method = MethodDefine.Build <MethodDefine>(codes,
                                                               methodDefinition.Locals,
                                                               methodDefinition.Parameters,
                                                               haseResult,
                                                               methodDefinition.MaxStack,
                                                               methodDefinition.Static,
                                                               methodDefinition.IsCtor
                                                               );
                method.MethodDefinition = methodDefinition;
                method.TypeDefine       = this;

                Methods.Add(method);
            }
            ClrType            = new ClrType();
            ClrType.typeDefine = TypeDefinition;
        }
Пример #2
0
        protected override MethodTasks CloneOne()
        {
            var methodDefinition = MethodDefinition;

            var codes = Codes;

            if (Codes == null)
            {
                List <string> lines = MethodDefinition.BodyLines;
                Codes = codes = ILCodeParse.ReadILCodes(lines.ToArray(), methodDefinition.LocalList, methodDefinition.ParametersList);
            }

            var method = MethodDefine.Build <MethodDefine>(codes,
                                                           methodDefinition.Locals,
                                                           methodDefinition.Parameters,
                                                           methodDefinition.ReturnType.IsVoid() && !MethodDefinition.IsCtor,
                                                           methodDefinition.MaxStack,
                                                           MethodDefinition.Static,
                                                           MethodDefinition.IsCtor
                                                           );

            method.MethodDefinition = methodDefinition;
            method.TypeDefine       = TypeDefine;
            method.CompileIL();
            method.Compile(TypeDefine.MethodCompile, TypeDefine.NewCompile);

            return(method);
        }
Пример #3
0
        public TypeDefine(SilAPI.DisassembledClass inputType)
        {
            TypeDefinition = inputType;

            foreach (var methodDefinition in TypeDefinition.Methods)
            {
                methodDefinition.ReadBody();
                List <string> lines      = methodDefinition.BodyLines;
                var           codes      = ILCodeParse.ReadILCodes(lines.ToArray(), methodDefinition.LocalList, methodDefinition.ParametersList);
                bool          haseResult = methodDefinition.ReturnType.ToLower() != typeof(void).Name.ToLower();
                if (methodDefinition.ShortName == ".ctor")
                {
                    haseResult = true;
                }
                var method = MethodDefine.Build <MethodDefine>(codes,
                                                               methodDefinition.Locals,
                                                               methodDefinition.Parameters,
                                                               haseResult,
                                                               methodDefinition.MaxStack,
                                                               methodDefinition.Static
                                                               );
                method.MethodDefinition = methodDefinition;
                method.TypeDefine       = this;

                Methods.Add(method);
            }
        }
Пример #4
0
        public MethodDefine ReBuild()
        {
            var methodDefinition = MethodDefinition;

            var codes = this.Codes;

            if (Codes == null)
            {
                List <string> lines = MethodDefinition.BodyLines;
                if (GenericsArgs != null && GenericsArgs.Length > 0)
                {
                    for (int i = 0; i < lines.Count; i++)
                    {
                        var line = lines[i];
                        if (line.IndexOf("!!") >= 0)
                        {
                            int pcount = 0;
                            for (int j = 0; j < methodDefinition.ParametersList.Count; j++)
                            {
                                if (methodDefinition.ParametersList[j].StartsWith("!!"))
                                {
                                    line = line.Replace(methodDefinition.ParametersList[j], GenericsArgs[pcount]);
                                    pcount++;
                                }
                            }

                            lines[i] = line;
                        }
                    }
                }
                Codes = codes = ILCodeParse.ReadILCodes(lines.ToArray(), methodDefinition.LocalList, methodDefinition.ParametersList);
            }
            var method = MethodDefine.Build <MethodDefine>(codes,
                                                           methodDefinition.Locals,
                                                           methodDefinition.Parameters,
                                                           methodDefinition.ReturnType.IsVoid() && !MethodDefinition.IsCtor,
                                                           methodDefinition.MaxStack,
                                                           MethodDefinition.Static,
                                                           MethodDefinition.IsCtor
                                                           );

            method.MethodDefinition = methodDefinition;
            method.TypeDefine       = TypeDefine;
            method.CompileIL();
            method.Compile(TypeDefine.MethodCompile, TypeDefine.NewCompile);

            return(method);
        }