public RemoteRunnerConnection(RemoteRunner parent, TcpClient client)
 {
     m_parent = parent;
     m_client = client;
     m_stream = m_client.GetStream();
     m_output = new ObjectDeserializer(m_stream);
     m_manager = new ClassManager();
     m_manager.AddProvider(((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(), RemoteRunner.CodePort);
     m_output.TypeProviders += (o, e) =>
     {
         if (!e.TypeFound)
         {
             var t = m_manager.RequestType(e.TypeName);
             if (t != null)
                 e.SetResult(t);
         }
     };
 }
            public AsyncCall(object o, string method, List<object[]> param, AsyncCallback callback, object state, TcpClient client)
            {
                Debug.Print("+ AsyncCall..ctor");

                m_state = state;
                m_completed = false;
                m_cb = callback;
                m_param = param;
                m_left = param.Count;
                m_obj = o;

                m_ns = client.GetStream();

                var tosend = new RunMessage()
                {
                    IsStatic = false,
                    MethodName = method,
                    NumArguments = param[0].Length,
                    NumCalls = param.Count,
                    TypeNames = param[0].Select(z => z.GetType().FullName).ToArray()
                };

                m_output = new ObjectDeserializer(m_ns);
                m_input = new ObjectSerializer(m_ns);
                m_input.BeginWrite(tosend, SendObject, null);
            }
        private void ReadCustomAttributes(dynamic target)
        {
            int num = m_br.ReadInt32();
            if (num > 0) {
                var od = new ObjectDeserializer(m_br.BaseStream);
                od.TypeProviders += (o, e) =>
                {
                    if (!e.TypeFound)
                    {
                        var t = ResolveType(e.TypeName);
                        if (t != null)
                            e.SetResult(t);
                    }
                };

                for (int i = 0; i < num; i++)
                {
                    List<object> ctorArgs = new List<object>(), fieldValues = new List<object>(), propValues = new List<object>();
                    var fis = new List<FieldInfo>();
                    var pis = new List<PropertyInfo>();

                    var type = ResolveType(m_br.ReadString());
                    int num2 = m_br.ReadInt32();
                    for (; num2 > 0; num2--)
                        ctorArgs.Add(od.Read());

                    num2 = m_br.ReadInt32();
                    for (;num2 > 0;num2--)
                    {
                        bool isField = m_br.ReadBoolean();
                        var name = m_br.ReadString();
                        var val = od.Read();

                        if (isField)
                        {
                            var fi = type.GetField(name);
                            if(fi != null)
                            {
                                fis.Add(fi);
                                fieldValues.Add(val);
                            }
                        }
                        else
                        {
                            var pi = type.GetProperty(name);
                            if(pi != null)
                            {
                                pis.Add(pi);
                                propValues.Add(val);
                            }
                        }
                    }

                    var ci = type.GetConstructor(ctorArgs.Select(o => o.GetType()).ToArray());

                    var attrBuilder = new CustomAttributeBuilder(
                        ci,
                        ctorArgs.ToArray(),
                        pis.ToArray(),
                        propValues.ToArray(),
                        fis.ToArray(),
                        fieldValues.ToArray());
                    target.SetCustomAttribute(attrBuilder);
                }
            }
        }
 public void Initialize()
 {
     stream = new MemoryStream(1024);
     input = new ObjectSerializer(stream);
     output = new ObjectDeserializer(stream);
 }
 public void Cleanup()
 {
     stream.Dispose();
     input = null;
     output = null;
 }