Esempio n. 1
0
 public static TypeLoader.TypeResponse loadMembers(typeDescriptor t)
 {
     TypeLoader.TypeResponse tr = new TypeLoader.TypeResponse();
     for (int i = 0; i < t.fields.Count; i++)
     {
         fieldDescriptor field    = t.fields[i];
         bool            isStatic = field.fieldInfo.IsStatic;
         List <object[]> fld;
         if (isStatic)
         {
             if (tr.staticFields == null)
             {
                 tr.staticFields = new List <object[]>();
             }
             fld = tr.staticFields;
         }
         else
         {
             if (tr.fields == null)
             {
                 tr.fields = new List <object[]>();
             }
             fld = tr.fields;
         }
         fld.Add(new object[]
         {
             field.name,
             i
         });
     }
     for (int i = 0; i < t.properties.Count; i++)
     {
         propertyDescriptor  property = t.properties[i];
         List <PropertyInfo> pInfo    = property.properties;
         bool p = false;
         for (int y = 0; y < pInfo.Count; y++)
         {
             PropertyInfo p2 = pInfo[y];
             if (null != p2)
             {
                 MethodBase gm;
                 if (p2.CanRead)
                 {
                     gm = p2.GetGetMethod();
                 }
                 else if (p2.CanWrite)
                 {
                     gm = p2.GetSetMethod();
                 }
                 else
                 {
                     gm = null;
                 }
                 if (gm != null)
                 {
                     bool            isStatic = gm.IsStatic;
                     List <object[]> fld;
                     if (isStatic)
                     {
                         if (tr.staticProperties == null)
                         {
                             tr.staticProperties = new List <object[]>();
                         }
                         fld = tr.staticProperties;
                     }
                     else
                     {
                         if (tr.properties == null)
                         {
                             tr.properties = new List <object[]>();
                         }
                         fld = tr.properties;
                     }
                     fld.Add(new object[]
                     {
                         property.name,
                         i
                     });
                     p = true;
                 }
             }
             if (p)
             {
                 break;
             }
         }
     }
     for (int i = 0; i < t.methods.Count; i++)
     {
         methodDescriptor  method = t.methods[i];
         List <MethodBase> pInfo2 = method.baseMethods;
         for (int y = 0; y < pInfo2.Count; y++)
         {
             MethodBase      p3       = pInfo2[y];
             bool            isStatic = p3.IsStatic;
             List <object[]> fld;
             if (isStatic)
             {
                 if (tr.staticMethods == null)
                 {
                     tr.staticMethods = new List <object[]>();
                 }
                 fld = tr.staticMethods;
             }
             else
             {
                 if (tr.methods == null)
                 {
                     tr.methods = new List <object[]>();
                 }
                 fld = tr.methods;
             }
             fld.Add(new object[]
             {
                 method.name,
                 i
             });
             if (y == 0)
             {
                 break;
             }
         }
     }
     return(tr);
 }
Esempio n. 2
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;
     }
 }