protected static object FixupArg(object arg, ref ArrayList argsToSerialize) { int count; if (arg == null) { return(null); } MarshalByRefObject proxy = arg as MarshalByRefObject; if (proxy != null) { if (!RemotingServices.IsTransparentProxy(proxy) || (RemotingServices.GetRealProxy(proxy) is RemotingProxy)) { ObjRef ref2 = RemotingServices.MarshalInternal(proxy, null, null); if (ref2.CanSmuggle()) { if (!RemotingServices.IsTransparentProxy(proxy)) { ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(proxy); identity.SetHandle(); ref2.SetServerIdentity(identity.GetHandle()); ref2.SetDomainID(AppDomain.CurrentDomain.GetId()); } ObjRef objRef = ref2.CreateSmuggleableCopy(); objRef.SetMarshaledObject(); return(new SmuggledObjRef(objRef)); } } if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } count = argsToSerialize.Count; argsToSerialize.Add(arg); return(new SerializedArg(count)); } if (CanSmuggleObjectDirectly(arg)) { return(arg); } Array array = arg as Array; if (array != null) { Type elementType = array.GetType().GetElementType(); if (elementType.IsPrimitive || (elementType == typeof(string))) { return(array.Clone()); } } if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } count = argsToSerialize.Count; argsToSerialize.Add(arg); return(new SerializedArg(count)); }
protected static object FixupArg(object arg, ref ArrayList argsToSerialize) { if (arg == null) { return((object)null); } if (arg is MarshalByRefObject marshalByRefObject) { if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject) || RemotingServices.GetRealProxy((object)marshalByRefObject) is RemotingProxy) { ObjRef objRef = RemotingServices.MarshalInternal(marshalByRefObject, (string)null, (Type)null); if (objRef.CanSmuggle()) { if (!RemotingServices.IsTransparentProxy((object)marshalByRefObject)) { ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(marshalByRefObject); identity.SetHandle(); objRef.SetServerIdentity(identity.GetHandle()); objRef.SetDomainID(AppDomain.CurrentDomain.GetId()); } ObjRef smuggleableCopy = objRef.CreateSmuggleableCopy(); smuggleableCopy.SetMarshaledObject(); return((object)new SmuggledObjRef(smuggleableCopy)); } } if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } int count = argsToSerialize.Count; argsToSerialize.Add(arg); return((object)new MessageSmuggler.SerializedArg(count)); } if (MessageSmuggler.CanSmuggleObjectDirectly(arg)) { return(arg); } if (arg is Array array) { Type elementType = array.GetType().GetElementType(); if (elementType.IsPrimitive || elementType == typeof(string)) { return(array.Clone()); } } if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } int count1 = argsToSerialize.Count; argsToSerialize.Add(arg); return((object)new MessageSmuggler.SerializedArg(count1)); }
} // FixupArgs protected static Object FixupArg(Object arg, ref ArrayList argsToSerialize) { // This method examines an argument and sees if it can be smuggled in some form. // If it can directly be smuggled (i.e. it is a primitive or string), we // just return the same object. If it's a marshal by ref object, we // see if we can smuggle the obj ref. If it's a primitive or string array, // we can smuggle a cloned copy of the array. In all other cases, // we add it to the list of args we want serialized, and return a // placeholder element (SerializedArg). if (arg == null) { return(null); } int index; // IMPORTANT!!! This should be done first because CanSmuggleObjectDirectly // calls GetType() and that would slow this down. MarshalByRefObject mbo = arg as MarshalByRefObject; if (mbo != null) { // We can only try to smuggle objref's for actual CLR objects // or for RemotingProxy's. if (!RemotingServices.IsTransparentProxy(mbo) || RemotingServices.GetRealProxy(mbo) is RemotingProxy) { ObjRef objRef = RemotingServices.MarshalInternal(mbo, null, null); if (objRef.CanSmuggle()) { ObjRef smugObjRef = objRef.CreateSmuggleableCopy(); smugObjRef.SetMarshaledObject(); return(new SmuggledObjRef(smugObjRef)); } } // Add this arg to list of one's to serialize and return a placeholder // since we couldn't smuggle the objref. if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } index = argsToSerialize.Count; argsToSerialize.Add(arg); return(new SerializedArg(index)); } if (CanSmuggleObjectDirectly(arg)) { return(arg); } // if this is a primitive array, we can just make a copy. // (IMPORTANT: We can directly use this copy from the // other app domain, there is no reason to make another // copy once we are on the other side) Array array = arg as Array; if (array != null) { Type elementType = array.GetType().GetElementType(); if (elementType.IsPrimitive || (elementType == typeof(String))) { return(array.Clone()); } } // Add this arg to list of one's to serialize and return a placeholder. if (argsToSerialize == null) { argsToSerialize = new ArrayList(); } index = argsToSerialize.Count; argsToSerialize.Add(arg); return(new SerializedArg(index)); } // FixupArg