Ejemplo n.º 1
0
        public wrapperStatic compile()
        {
            wrapperStatic _wrapperStatic;

            if (!this.compiled)
            {
                // generar un archivo  por cada tipo
                string   name = GetSHA1(this.type.AssemblyQualifiedName).ToUpper();
                string   file = environment.getCompilationFile(name);
                FileInfo f    = new FileInfo(file);

                try
                {
                    if (f.Exists)
                    {
                        string str  = "C" + GetSHA1(type.AssemblyQualifiedName);
                        string str1 = "C" + GetSHA1(type.AssemblyQualifiedName) + "_static";

                        Type            _type        = Assembly.LoadFile(file).GetType(string.Concat("jxshell.dotnet4.", str1));
                        ConstructorInfo _constructor = _type.GetConstructor(new Type[] { typeof(Type), typeof(typeDescriptor) });

                        this.compiledWrapper = (wrapperStatic)_constructor.Invoke(new object[] { this.type, this });
                        this.compiled        = true;
                    }
                    else
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        string        str           = "";
                        string        str1          = "";
                        typeDescriptor.addUsingsStatements(stringBuilder);
                        this.precompile(stringBuilder, ref str, ref str1);
                        stringBuilder.AppendLine("class program{public static void main(){}}");

                        csharplanguage _csharplanguage = typeDescriptor.language;
                        _csharplanguage.runScriptWithId(stringBuilder.ToString(), name);

                        Type            _type        = _csharplanguage.getCompiledAssembly().GetType(string.Concat("jxshell.dotnet4.", str));
                        ConstructorInfo _constructor = _type.GetConstructor(new Type[] { typeof(Type), typeof(typeDescriptor) });

                        this.compiledWrapper = (wrapperStatic)_constructor.Invoke(new object[] { this.type, this });
                        this.compiled        = true;
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    throw new Exception(string.Concat("No se puede obtener un wrapper para el tipo ", this.type.ToString(), ". ", exception.Message), exception);
                }
                _wrapperStatic = this.compiledWrapper;
            }
            else
            {
                _wrapperStatic = this.compiledWrapper;
            }
            return(_wrapperStatic);
        }
Ejemplo n.º 2
0
        public void loadManyTypes(string types)
        {
            string[] array = types.Split(new string[]
            {
                "-"
            }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder stringBuilder = new StringBuilder();

            typeDescriptor.addUsingsStatements(stringBuilder);
            Dictionary <Type, type_1> dictionary = new Dictionary <Type, type_1>();

            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string         typeName          = array2[i];
                Type           typeOrGenericType = this.getTypeOrGenericType(typeName);
                typeDescriptor typeDescriptor    = new typeDescriptor(typeOrGenericType, typeName, false);
                if (!typeDescriptor.isCompiled())
                {
                    string staticClass   = "";
                    string instanceClass = "";
                    typeDescriptor.precompile(stringBuilder, ref staticClass, ref instanceClass);
                    dictionary[typeOrGenericType] = new type_1
                    {
                        td            = typeDescriptor,
                        staticClass   = staticClass,
                        instanceClass = instanceClass,
                        t             = typeOrGenericType
                    };
                }
            }
            stringBuilder.AppendLine("class program{public static void main(){}}");
            csharplanguage csharplanguage = (csharplanguage)language.defaultLanguage.create();

            if (dictionary.Count > 0)
            {
                csharplanguage.runScript(stringBuilder.ToString(), typeDescriptor.generateInMemory);
            }
            foreach (KeyValuePair <Type, type_1> current in dictionary)
            {
                type_1          value       = current.Value;
                Type            type        = csharplanguage.getCompiledAssembly().GetType("jxshell.dotnet4." + value.staticClass);
                ConstructorInfo constructor = type.GetConstructor(new Type[]
                {
                    typeof(Type),
                    typeof(typeDescriptor)
                });
                value.td.setCompiledWrapper((wrapperStatic)constructor.Invoke(new object[]
                {
                    value.t,
                    value.td
                }));
            }
        }
Ejemplo n.º 3
0
        public wrapperStatic compile()
        {
            wrapperStatic result;

            if (this.compiled)
            {
                result = this.compiledWrapper;
            }
            else
            {
                StringBuilder stringBuilder = new StringBuilder();
                string        str           = "";
                string        text          = "";
                typeDescriptor.addUsingsStatements(stringBuilder);
                this.precompile(stringBuilder, ref str, ref text);
                stringBuilder.AppendLine("class program{public static void main(){}}");
                try
                {
                    csharplanguage csharplanguage = typeDescriptor.language;
                    //Clipboard.SetText(stringBuilder.ToString());
                    csharplanguage.runScript(stringBuilder.ToString(), typeDescriptor.generateInMemory);
                    Type            type            = csharplanguage.getCompiledAssembly().GetType("jxshell.dotnet4." + str);
                    ConstructorInfo constructorInfo = type.GetConstructor(new Type[]
                    {
                        typeof(Type),
                        typeof(typeDescriptor)
                    });
                    this.compiledWrapper = (wrapperStatic)constructorInfo.Invoke(new object[]
                    {
                        this.type,
                        this
                    });
                    this.compiled = true;
                }
                catch (Exception ex)
                {
                    throw new Exception("No se puede obtener un wrapper para el tipo " + this.type.ToString() + ". " + ex.Message, ex);
                }
                result = this.compiledWrapper;
            }
            return(result);
        }
Ejemplo n.º 4
0
 public typeDescriptor(Type t, string typeName, bool compile = true)
 {
     typeDescriptor.loadEvaluator();
     if (typeDescriptor.language == null)
     {
         typeDescriptor.language = (csharplanguage)jxshell.language.defaultLanguage.create();
     }
     this.typeString = typeName;
     MethodInfo[] array  = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
     MethodInfo[] array2 = array;
     for (int i = 0; i < array2.Length; i++)
     {
         MethodInfo methodInfo = array2[i];
         if (!methodInfo.Name.StartsWith("get_") && !methodInfo.Name.StartsWith("set_"))
         {
             methodDescriptor methodDescriptor = null;
             if (methodInfo.IsGenericMethod)
             {
                 string text = "generic_" + methodInfo.Name;
                 if (!this.instanceMethods.TryGetValue(text, out methodDescriptor))
                 {
                     methodDescriptor = new methodDescriptor();
                     methodDescriptor.isGenericMethod = true;
                     this.instanceMethods[text]       = methodDescriptor;
                     this.methods.Add(methodDescriptor);
                     methodDescriptor.methodOrder = this.methods.Count - 1;
                     methodDescriptor.name        = text;
                 }
             }
             else if (!this.instanceMethods.TryGetValue(methodInfo.Name, out methodDescriptor))
             {
                 methodDescriptor = new methodDescriptor();
                 this.instanceMethods[methodInfo.Name] = methodDescriptor;
                 this.methods.Add(methodDescriptor);
                 methodDescriptor.methodOrder = this.methods.Count - 1;
                 methodDescriptor.name        = methodInfo.Name;
             }
             methodDescriptor.baseMethods.Add(methodInfo);
             methodDescriptor.maxParameterCount = Math.Max(methodDescriptor.maxParameterCount, methodInfo.GetParameters().Length);
             if (methodInfo.IsGenericMethod)
             {
                 methodDescriptor.genericParameterCount = Math.Max(methodDescriptor.genericParameterCount, methodInfo.GetGenericArguments().Length);
             }
         }
     }
     PropertyInfo[] array3 = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     PropertyInfo[] array4 = array3;
     for (int j = 0; j < array4.Length; j++)
     {
         PropertyInfo       propertyInfo       = array4[j];
         propertyDescriptor propertyDescriptor = null;
         if (!this.instanceProperties.TryGetValue(propertyInfo.Name, out propertyDescriptor))
         {
             propertyDescriptor = new propertyDescriptor();
             this.instanceProperties[propertyInfo.Name] = propertyDescriptor;
             this.properties.Add(propertyDescriptor);
             propertyDescriptor.propertyOrder = this.properties.Count - 1;
             propertyDescriptor.name          = propertyInfo.Name;
         }
         propertyDescriptor.properties.Add(propertyInfo);
         propertyDescriptor.maxParameterCount = Math.Max(propertyDescriptor.maxParameterCount, propertyInfo.GetIndexParameters().Length);
     }
     FieldInfo[] array5 = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
     FieldInfo[] array6 = array5;
     for (int k = 0; k < array6.Length; k++)
     {
         FieldInfo       fieldInfo       = array6[k];
         fieldDescriptor fieldDescriptor = null;
         if (!this.instanceFields.TryGetValue(fieldInfo.Name, out fieldDescriptor))
         {
             fieldDescriptor = new fieldDescriptor();
             this.instanceFields[fieldInfo.Name] = fieldDescriptor;
             this.fields.Add(fieldDescriptor);
             fieldDescriptor.fieldOrder = this.fields.Count - 1;
             fieldDescriptor.name       = fieldInfo.Name;
         }
         fieldDescriptor.fieldInfo = fieldInfo;
     }
     ConstructorInfo[] constructors = t.GetConstructors();
     ConstructorInfo[] array7       = constructors;
     for (int l = 0; l < array7.Length; l++)
     {
         ConstructorInfo  constructorInfo = array7[l];
         methodDescriptor methodDescriptor2;
         if (this.constructor == null)
         {
             methodDescriptor2 = new methodDescriptor();
             this.constructor  = methodDescriptor2;
             this.methods.Add(methodDescriptor2);
             methodDescriptor2.name        = "construct";
             methodDescriptor2.methodOrder = this.methods.Count - 1;
         }
         else
         {
             methodDescriptor2 = this.constructor;
         }
         methodDescriptor2.baseMethods.Add(constructorInfo);
         methodDescriptor2.maxParameterCount = Math.Max(methodDescriptor2.maxParameterCount, constructorInfo.GetParameters().Length);
     }
     array = t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
     MethodInfo[] array8 = array;
     for (int m = 0; m < array8.Length; m++)
     {
         MethodInfo methodInfo2 = array8[m];
         if (!methodInfo2.Name.StartsWith("get_") && !methodInfo2.Name.StartsWith("set_"))
         {
             methodDescriptor methodDescriptor3 = null;
             if (methodInfo2.IsGenericMethod)
             {
                 string text2 = "generic_" + methodInfo2.Name;
                 if (!this.instanceMethods.TryGetValue(text2, out methodDescriptor3))
                 {
                     methodDescriptor3                 = new methodDescriptor();
                     this.staticMethods[text2]         = methodDescriptor3;
                     methodDescriptor3.isGenericMethod = true;
                     this.methods.Add(methodDescriptor3);
                     methodDescriptor3.methodOrder = this.methods.Count - 1;
                     methodDescriptor3.name        = text2;
                 }
             }
             else if (!this.staticMethods.TryGetValue(methodInfo2.Name, out methodDescriptor3))
             {
                 methodDescriptor3 = new methodDescriptor();
                 this.staticMethods[methodInfo2.Name] = methodDescriptor3;
                 this.methods.Add(methodDescriptor3);
                 methodDescriptor3.name        = methodInfo2.Name;
                 methodDescriptor3.methodOrder = this.methods.Count - 1;
             }
             methodDescriptor3.baseMethods.Add(methodInfo2);
             methodDescriptor3.maxParameterCount = Math.Max(methodDescriptor3.maxParameterCount, methodInfo2.GetParameters().Length);
             if (methodInfo2.IsGenericMethod)
             {
                 methodDescriptor3.genericParameterCount = Math.Max(methodDescriptor3.genericParameterCount, methodInfo2.GetGenericArguments().Length);
             }
         }
     }
     array3 = t.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     PropertyInfo[] array9 = array3;
     for (int n = 0; n < array9.Length; n++)
     {
         PropertyInfo       propertyInfo2       = array9[n];
         propertyDescriptor propertyDescriptor2 = null;
         if (!this.staticProperties.TryGetValue(propertyInfo2.Name, out propertyDescriptor2))
         {
             propertyDescriptor2 = new propertyDescriptor();
             this.staticProperties[propertyInfo2.Name] = propertyDescriptor2;
             this.properties.Add(propertyDescriptor2);
             propertyDescriptor2.propertyOrder = this.properties.Count - 1;
             propertyDescriptor2.name          = propertyInfo2.Name;
         }
         propertyDescriptor2.properties.Add(propertyInfo2);
         propertyDescriptor2.maxParameterCount = Math.Max(propertyDescriptor2.maxParameterCount, propertyInfo2.GetIndexParameters().Length);
     }
     array5 = t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
     FieldInfo[] array10 = array5;
     for (int num = 0; num < array10.Length; num++)
     {
         FieldInfo       fieldInfo2       = array10[num];
         fieldDescriptor fieldDescriptor2 = null;
         if (!this.instanceFields.TryGetValue(fieldInfo2.Name, out fieldDescriptor2))
         {
             fieldDescriptor2 = new fieldDescriptor();
             this.staticFields[fieldInfo2.Name] = fieldDescriptor2;
             this.fields.Add(fieldDescriptor2);
             fieldDescriptor2.fieldOrder = this.fields.Count - 1;
             fieldDescriptor2.name       = fieldInfo2.Name;
         }
         fieldDescriptor2.fieldInfo = fieldInfo2;
     }
     this.type = t;
     typeDescriptor.loadedTypes[t] = this;
     if (compile && typeDescriptor.gencompile)
     {
         this.compile();
     }
 }
Ejemplo n.º 5
0
 public typeDescriptor(Type t, string typeName, bool compile = true)
 {
     jxshell.dotnet4.methodDescriptor methodDescriptor;
     typeDescriptor.loadEvaluator();
     if (typeDescriptor.language == null)
     {
         typeDescriptor.language = (csharplanguage)jxshell.language.defaultLanguage.create();
     }
     this.typeString = typeName;
     MethodInfo[] methods = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
     for (int i = 0; i < (int)methods.Length; i++)
     {
         MethodInfo methodInfo = methods[i];
         if (!methodInfo.Name.StartsWith("get_") && !methodInfo.Name.StartsWith("set_"))
         {
             jxshell.dotnet4.methodDescriptor value = null;
             if (methodInfo.IsGenericMethod)
             {
                 string text = string.Concat("generic_", methodInfo.Name);
                 if (!this.instanceMethods.TryGetValue(text, out value))
                 {
                     value = new jxshell.dotnet4.methodDescriptor()
                     {
                         isGenericMethod = true
                     };
                     this.instanceMethods[text] = value;
                     this.methods.Add(value);
                     value.methodOrder = this.methods.Count - 1;
                     value.name        = text;
                 }
             }
             else if (!this.instanceMethods.TryGetValue(methodInfo.Name, out value))
             {
                 value = new jxshell.dotnet4.methodDescriptor();
                 this.instanceMethods[methodInfo.Name] = value;
                 this.methods.Add(value);
                 value.methodOrder = this.methods.Count - 1;
                 value.name        = methodInfo.Name;
             }
             value.baseMethods.Add(methodInfo);
             value.maxParameterCount = Math.Max(value.maxParameterCount, (int)methodInfo.GetParameters().Length);
             if (methodInfo.IsGenericMethod)
             {
                 value.genericParameterCount = Math.Max(value.genericParameterCount, (int)methodInfo.GetGenericArguments().Length);
             }
         }
     }
     PropertyInfo[] properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     for (int j = 0; j < (int)properties.Length; j++)
     {
         PropertyInfo       propertyInfo = properties[j];
         propertyDescriptor value2       = null;
         if (!this.instanceProperties.TryGetValue(propertyInfo.Name, out value2))
         {
             value2 = new propertyDescriptor();
             this.instanceProperties[propertyInfo.Name] = value2;
             this.properties.Add(value2);
             value2.propertyOrder = this.properties.Count - 1;
             value2.name          = propertyInfo.Name;
         }
         value2.properties.Add(propertyInfo);
         value2.maxParameterCount = Math.Max(value2.maxParameterCount, (int)propertyInfo.GetIndexParameters().Length);
     }
     FieldInfo[] fields = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
     for (int k = 0; k < (int)fields.Length; k++)
     {
         FieldInfo       fieldInfo = fields[k];
         fieldDescriptor value3    = null;
         if (!this.instanceFields.TryGetValue(fieldInfo.Name, out value3))
         {
             value3 = new fieldDescriptor();
             this.instanceFields[fieldInfo.Name] = value3;
             this.fields.Add(value3);
             value3.fieldOrder = this.fields.Count - 1;
             value3.name       = fieldInfo.Name;
         }
         value3.fieldInfo = fieldInfo;
     }
     ConstructorInfo[] constructors = t.GetConstructors();
     for (int l = 0; l < (int)constructors.Length; l++)
     {
         ConstructorInfo constructorInfo = constructors[l];
         if (this.constructor != null)
         {
             methodDescriptor = this.constructor;
         }
         else
         {
             jxshell.dotnet4.methodDescriptor _methodDescriptor  = new jxshell.dotnet4.methodDescriptor();
             jxshell.dotnet4.methodDescriptor _methodDescriptor1 = _methodDescriptor;
             this.constructor = _methodDescriptor;
             methodDescriptor = _methodDescriptor1;
             this.methods.Add(methodDescriptor);
             methodDescriptor.name        = "construct";
             methodDescriptor.methodOrder = this.methods.Count - 1;
         }
         methodDescriptor.baseMethods.Add(constructorInfo);
         methodDescriptor.maxParameterCount = Math.Max(methodDescriptor.maxParameterCount, (int)constructorInfo.GetParameters().Length);
     }
     MethodInfo[] methodInfoArray = t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
     for (int m = 0; m < (int)methodInfoArray.Length; m++)
     {
         MethodInfo methodInfo2 = methodInfoArray[m];
         if (!methodInfo2.Name.StartsWith("get_") && !methodInfo2.Name.StartsWith("set_"))
         {
             jxshell.dotnet4.methodDescriptor value4 = null;
             if (methodInfo2.IsGenericMethod)
             {
                 string text2 = string.Concat("generic_", methodInfo2.Name);
                 if (!this.instanceMethods.TryGetValue(text2, out value4))
                 {
                     value4 = new jxshell.dotnet4.methodDescriptor();
                     this.staticMethods[text2] = value4;
                     value4.isGenericMethod    = true;
                     this.methods.Add(value4);
                     value4.methodOrder = this.methods.Count - 1;
                     value4.name        = text2;
                 }
             }
             else if (!this.staticMethods.TryGetValue(methodInfo2.Name, out value4))
             {
                 value4 = new jxshell.dotnet4.methodDescriptor();
                 this.staticMethods[methodInfo2.Name] = value4;
                 this.methods.Add(value4);
                 value4.name        = methodInfo2.Name;
                 value4.methodOrder = this.methods.Count - 1;
             }
             value4.baseMethods.Add(methodInfo2);
             value4.maxParameterCount = Math.Max(value4.maxParameterCount, (int)methodInfo2.GetParameters().Length);
             if (methodInfo2.IsGenericMethod)
             {
                 value4.genericParameterCount = Math.Max(value4.genericParameterCount, (int)methodInfo2.GetGenericArguments().Length);
             }
         }
     }
     PropertyInfo[] propertyInfoArray = t.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
     for (int n = 0; n < (int)propertyInfoArray.Length; n++)
     {
         PropertyInfo       propertyInfo2 = propertyInfoArray[n];
         propertyDescriptor value5        = null;
         if (!this.staticProperties.TryGetValue(propertyInfo2.Name, out value5))
         {
             value5 = new propertyDescriptor();
             this.staticProperties[propertyInfo2.Name] = value5;
             this.properties.Add(value5);
             value5.propertyOrder = this.properties.Count - 1;
             value5.name          = propertyInfo2.Name;
         }
         value5.properties.Add(propertyInfo2);
         value5.maxParameterCount = Math.Max(value5.maxParameterCount, (int)propertyInfo2.GetIndexParameters().Length);
     }
     FieldInfo[] fieldInfoArray = t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
     for (int o = 0; o < (int)fieldInfoArray.Length; o++)
     {
         FieldInfo       fieldInfo2 = fieldInfoArray[o];
         fieldDescriptor value6     = null;
         if (!this.instanceFields.TryGetValue(fieldInfo2.Name, out value6))
         {
             value6 = new fieldDescriptor();
             this.staticFields[fieldInfo2.Name] = value6;
             this.fields.Add(value6);
             value6.fieldOrder = this.fields.Count - 1;
             value6.name       = fieldInfo2.Name;
         }
         value6.fieldInfo = fieldInfo2;
     }
     this.type = t;
     typeDescriptor.loadedTypes[t] = this;
     if (compile && typeDescriptor.gencompile)
     {
         this.compile();
     }
 }
Ejemplo n.º 6
0
 internal static void _execute(Command cmd)
 {
     try
     {
         //File.WriteAllText("/Users/james/commands.log", Newtonsoft.Json.JsonConvert.SerializeObject(cmd));
         object[] args;
         if (cmd.arguments != null)
         {
             args = new object[cmd.arguments.Count];
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 args[i] = cmd.arguments[i].getValue();
             }
         }
         else
         {
             args = new object[0];
         }
         bool emp = false;
         if (cmd.command == "assembly.add")
         {
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 Manager.lastManager.loadAssemblyPartialName(cmd.arguments[i].getValue().ToString());
             }
             emp = true;
         }
         else if (cmd.command == "assembly.addfile")
         {
             for (int i = 0; i < cmd.arguments.Count; i++)
             {
                 Manager.lastManager.loadAssemblyFile(cmd.arguments[i].getValue().ToString());
             }
             emp = true;
         }
         else if (cmd.command == "remove")
         {
             if (cmd.objectid > 0)
             {
                 Objects.remove(cmd.objectid);
             }
             emp = true;
         }
         else if (cmd.command == "compile")
         {
             string         code = cmd.arguments[0].getValue().ToString();
             csharplanguage lang = (csharplanguage)language.languages["c#"].create();
             lang.compileString(code, "");
             Assembly a = lang.getCompiledAssembly();
             if (a != null)
             {
                 Manager.lastManager.loadAssembly(a);
             }
             emp = true;
         }
         else if (cmd.command == "loadmembers")
         {
             //string code = cmd.typename;
             Type                    ty = Manager.lastManager.getTypeOrGenericType(cmd.typename);
             typeDescriptor          t2 = typeDescriptor.loadFromType(ty, "", false);
             TypeLoader.TypeResponse tr = TypeLoader.loadMembers(t2);
             cmd.command = "get";
             Response r = new Response(cmd, tr, null);
             CommandLine.write(r);
         }
         else if (cmd.objectid > 0)
         {
             object obj = Objects.getbyid(cmd.objectid);
             if (obj == null)
             {
                 throw new NullReferenceException("El objeto ha sido liberado de memoria o el id no es válido");
             }
             object result = null;
             if (cmd.getproperty)
             {
                 result = TypeLoader.getProperty(cmd, ref args, obj);
             }
             else if (cmd.getfield)
             {
                 result = TypeLoader.getField(cmd, obj);
             }
             else if (cmd.method)
             {
                 result = TypeLoader.invokeMethod(cmd, ref args, obj);
             }
             else if (cmd.setproperty)
             {
                 TypeLoader.setProperty(cmd, ref args, obj, cmd.value.getValue());
             }
             else if (cmd.setfield)
             {
                 TypeLoader.setField(cmd, obj, cmd.value.getValue());
             }
             Response r = new Response(cmd, result, null);
             CommandLine.write(r);
         }
         else
         {
             object result = null;
             if (cmd.getproperty)
             {
                 result = TypeLoader.getProperty(cmd, ref args, null);
             }
             else if (cmd.getfield)
             {
                 result = TypeLoader.getField(cmd, null);
             }
             else if (cmd.method)
             {
                 result = TypeLoader.invokeMethod(cmd, ref args, null);
             }
             else if (cmd.setproperty)
             {
                 TypeLoader.setProperty(cmd, ref args, null, cmd.value.getValue());
             }
             else if (cmd.setfield)
             {
                 TypeLoader.setField(cmd, null, cmd.value.getValue());
             }
             Response r = new Response(cmd, result, null);
             CommandLine.write(r);
         }
         if (emp)
         {
             CommandLine.write(new Response
             {
                 isnull    = true,
                 commandid = cmd.commandid
             });
         }
     }
     catch (Exception e)
     {
         if (e.InnerException != null)
         {
             throw e.InnerException;
         }
         if (e is KeyNotFoundException)
         {
             throw new MissingMemberException("El método o propiedad no existe");
         }
         throw;
     }
 }
Ejemplo n.º 7
0
        public typeDescriptor(Type t, string typeName, bool compile = true)
        {
            methodDescriptor count;

            typeDescriptor.loadEvaluator();
            if (typeDescriptor.language == null)
            {
                typeDescriptor.language = (csharplanguage)jxshell.language.defaultLanguage.create();
            }
            this.typeString = typeName;
            MethodInfo[] methods = t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
            for (int i = 0; i < (int)methods.Length; i++)
            {
                MethodInfo methodInfo = methods[i];
                if ((methodInfo.Name.StartsWith("get_") ? false : !methodInfo.Name.StartsWith("set_")))
                {
                    methodDescriptor _methodDescriptor = null;
                    if (methodInfo.IsGenericMethod)
                    {
                        string str = string.Concat("generic_", methodInfo.Name);
                        if (!this.instanceMethods.TryGetValue(str, out _methodDescriptor))
                        {
                            _methodDescriptor = new methodDescriptor()
                            {
                                isGenericMethod = true
                            };
                            this.instanceMethods[str] = _methodDescriptor;
                            this.methods.Add(_methodDescriptor);
                            _methodDescriptor.methodOrder = this.methods.Count - 1;
                            _methodDescriptor.name        = str;
                        }
                    }
                    else if (!this.instanceMethods.TryGetValue(methodInfo.Name, out _methodDescriptor))
                    {
                        _methodDescriptor = new methodDescriptor();
                        this.instanceMethods[methodInfo.Name] = _methodDescriptor;
                        this.methods.Add(_methodDescriptor);
                        _methodDescriptor.methodOrder = this.methods.Count - 1;
                        _methodDescriptor.name        = methodInfo.Name;
                    }
                    _methodDescriptor.baseMethods.Add(methodInfo);
                    _methodDescriptor.maxParameterCount = Math.Max(_methodDescriptor.maxParameterCount, (int)methodInfo.GetParameters().Length);
                    if (methodInfo.IsGenericMethod)
                    {
                        _methodDescriptor.genericParameterCount = Math.Max(_methodDescriptor.genericParameterCount, (int)methodInfo.GetGenericArguments().Length);
                    }
                }
            }
            PropertyInfo[] properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
            for (int j = 0; j < (int)properties.Length; j++)
            {
                PropertyInfo       propertyInfo        = properties[j];
                propertyDescriptor _propertyDescriptor = null;
                if (!this.instanceProperties.TryGetValue(propertyInfo.Name, out _propertyDescriptor))
                {
                    _propertyDescriptor = new propertyDescriptor();
                    this.instanceProperties[propertyInfo.Name] = _propertyDescriptor;
                    this.properties.Add(_propertyDescriptor);
                    _propertyDescriptor.propertyOrder = this.properties.Count - 1;
                    _propertyDescriptor.name          = propertyInfo.Name;
                }
                _propertyDescriptor.properties.Add(propertyInfo);
                _propertyDescriptor.maxParameterCount = Math.Max(_propertyDescriptor.maxParameterCount, (int)propertyInfo.GetIndexParameters().Length);
            }
            FieldInfo[] fields = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
            for (int k = 0; k < (int)fields.Length; k++)
            {
                FieldInfo       fieldInfo        = fields[k];
                fieldDescriptor _fieldDescriptor = null;
                if (!this.instanceFields.TryGetValue(fieldInfo.Name, out _fieldDescriptor))
                {
                    _fieldDescriptor = new fieldDescriptor();
                    this.instanceFields[fieldInfo.Name] = _fieldDescriptor;
                    this.fields.Add(_fieldDescriptor);
                    _fieldDescriptor.fieldOrder = this.fields.Count - 1;
                    _fieldDescriptor.name       = fieldInfo.Name;
                }
                _fieldDescriptor.fieldInfo = fieldInfo;
            }
            ConstructorInfo[] constructors = t.GetConstructors();
            for (int l = 0; l < (int)constructors.Length; l++)
            {
                ConstructorInfo constructorInfo = constructors[l];
                if (this.constructor == null)
                {
                    methodDescriptor _methodDescriptor1 = new methodDescriptor();
                    methodDescriptor _methodDescriptor2 = _methodDescriptor1;
                    this.constructor = _methodDescriptor1;
                    count            = _methodDescriptor2;
                    this.methods.Add(count);
                    count.name        = "construct";
                    count.methodOrder = this.methods.Count - 1;
                }
                else
                {
                    count = this.constructor;
                }
                count.baseMethods.Add(constructorInfo);
                count.maxParameterCount = Math.Max(count.maxParameterCount, (int)constructorInfo.GetParameters().Length);
            }
            MethodInfo[] methodInfoArray = t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.InvokeMethod);
            for (int m = 0; m < (int)methodInfoArray.Length; m++)
            {
                MethodInfo methodInfo1 = methodInfoArray[m];
                if ((methodInfo1.Name.StartsWith("get_") ? false : !methodInfo1.Name.StartsWith("set_")))
                {
                    methodDescriptor name = null;
                    if (methodInfo1.IsGenericMethod)
                    {
                        string str1 = string.Concat("generic_", methodInfo1.Name);
                        if (!this.instanceMethods.TryGetValue(str1, out name))
                        {
                            name = new methodDescriptor();
                            this.staticMethods[str1] = name;
                            name.isGenericMethod     = true;
                            this.methods.Add(name);
                            name.methodOrder = this.methods.Count - 1;
                            name.name        = str1;
                        }
                    }
                    else if (!this.staticMethods.TryGetValue(methodInfo1.Name, out name))
                    {
                        name = new methodDescriptor();
                        this.staticMethods[methodInfo1.Name] = name;
                        this.methods.Add(name);
                        name.name        = methodInfo1.Name;
                        name.methodOrder = this.methods.Count - 1;
                    }
                    name.baseMethods.Add(methodInfo1);
                    name.maxParameterCount = Math.Max(name.maxParameterCount, (int)methodInfo1.GetParameters().Length);
                    if (methodInfo1.IsGenericMethod)
                    {
                        name.genericParameterCount = Math.Max(name.genericParameterCount, (int)methodInfo1.GetGenericArguments().Length);
                    }
                }
            }
            PropertyInfo[] propertyInfoArray = t.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
            for (int n = 0; n < (int)propertyInfoArray.Length; n++)
            {
                PropertyInfo       propertyInfo1        = propertyInfoArray[n];
                propertyDescriptor _propertyDescriptor1 = null;
                if (!this.staticProperties.TryGetValue(propertyInfo1.Name, out _propertyDescriptor1))
                {
                    _propertyDescriptor1 = new propertyDescriptor();
                    this.staticProperties[propertyInfo1.Name] = _propertyDescriptor1;
                    this.properties.Add(_propertyDescriptor1);
                    _propertyDescriptor1.propertyOrder = this.properties.Count - 1;
                    _propertyDescriptor1.name          = propertyInfo1.Name;
                }
                _propertyDescriptor1.properties.Add(propertyInfo1);
                _propertyDescriptor1.maxParameterCount = Math.Max(_propertyDescriptor1.maxParameterCount, (int)propertyInfo1.GetIndexParameters().Length);
            }
            FieldInfo[] fieldInfoArray = t.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.SetField);
            for (int o = 0; o < (int)fieldInfoArray.Length; o++)
            {
                FieldInfo       fieldInfo1        = fieldInfoArray[o];
                fieldDescriptor _fieldDescriptor1 = null;
                if (!this.instanceFields.TryGetValue(fieldInfo1.Name, out _fieldDescriptor1))
                {
                    _fieldDescriptor1 = new fieldDescriptor();
                    this.staticFields[fieldInfo1.Name] = _fieldDescriptor1;
                    this.fields.Add(_fieldDescriptor1);
                    _fieldDescriptor1.fieldOrder = this.fields.Count - 1;
                    _fieldDescriptor1.name       = fieldInfo1.Name;
                }
                _fieldDescriptor1.fieldInfo = fieldInfo1;
            }
            this.type = t;
            typeDescriptor.loadedTypes[t] = this;
            if ((!compile ? false : typeDescriptor.gencompile))
            {
                this.compile();
            }
        }