internal static object GetObjectData(object serObj, out string typeName, out string assemName, out string[] fieldNames, out object[] fieldValues)
{
Type objectType = null;
object retObj = null;
if (RemotingServices.IsTransparentProxy(serObj))
objectType = typeof(MarshalByRefObject);
else
objectType = serObj.GetType();
SerializationInfo si = new SerializationInfo(objectType, s_converter);
if (serObj is ObjRef)
{
s_ObjRefRemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
}
else if (RemotingServices.IsTransparentProxy(serObj) || serObj is MarshalByRefObject)
{
// We can only try to smuggle objref's for actual CLR objects
// or for RemotingProxy's.
if (!RemotingServices.IsTransparentProxy(serObj) ||
RemotingServices.GetRealProxy(serObj) is RemotingProxy)
{
ObjRef objRef = RemotingServices.MarshalInternal((MarshalByRefObject)serObj, null, null);
if (objRef.CanSmuggle())
{
if (RemotingServices.IsTransparentProxy(serObj))
{
RealProxy rp = RemotingServices.GetRealProxy(serObj);
objRef.SetServerIdentity(rp._srvIdentity);
objRef.SetDomainID(rp._domainID);
}
else
{
ServerIdentity srvId = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)serObj);
srvId.SetHandle();
objRef.SetServerIdentity(srvId.GetHandle());
objRef.SetDomainID(AppDomain.CurrentDomain.GetId());
}
objRef.SetMarshaledObject();
retObj = objRef;
}
}
if (retObj == null)
{
// Deal with the non-smugglable remoting objects
s_RemotingSurrogate.GetObjectData(serObj, si, s_cloneContext);
}
}
else if (serObj is ISerializable)
{
((ISerializable)serObj).GetObjectData(si, s_cloneContext);
}
else
{
// Getting here means a bug in cloner
throw new ArgumentException(Environment.GetResourceString("Arg_SerializationException"));
}
if (retObj == null)
{
typeName = si.FullTypeName;
assemName = si.AssemblyName;
fieldNames = si.MemberNames;
fieldValues = si.MemberValues;
}
else
{
typeName = null;
assemName = null;
fieldNames = null;
fieldValues = null;
}
return retObj;
}