public virtual Object GetRealObject(StreamingContext context)
{
// GetRealObject uses the data we have in m_data and m_unityType to do a lookup on the correct
// object to return. We have specific code here to handle the different types which we support.
// The reflection types (Assembly, Module, and Type) have to be looked up through their static
// accessors by name.
Assembly assembly;
switch (m_unityType)
{
case EmptyUnity:
{
return Empty.Value;
}
case NullUnity:
{
return DBNull.Value;
}
case MissingUnity:
{
return Missing.Value;
}
case PartialInstantiationTypeUnity:
{
m_unityType = RuntimeTypeUnity;
Type definition = GetRealObject(context) as Type;
m_unityType = PartialInstantiationTypeUnity;
if (m_instantiation[0] == null)
return null;
return MakeElementTypes(definition.MakeGenericType(m_instantiation));
}
case GenericParameterTypeUnity:
{
if (m_declaringMethod == null && m_declaringType == null)
ThrowInsufficientInformation("DeclaringMember");
if (m_declaringMethod != null)
return m_declaringMethod.GetGenericArguments()[m_genericParameterPosition];
return MakeElementTypes(m_declaringType.GetGenericArguments()[m_genericParameterPosition]);
}
case RuntimeTypeUnity:
{
if (m_data == null || m_data.Length == 0)
ThrowInsufficientInformation("Data");
if (m_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
if (m_assemblyName.Length == 0)
return Type.GetType(m_data, true, false);
assembly = Assembly.Load(m_assemblyName);
Type t = assembly.GetType(m_data, true, false);
return t;
}
case ModuleUnity:
{
if (m_data == null || m_data.Length == 0)
ThrowInsufficientInformation("Data");
if (m_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
assembly = Assembly.Load(m_assemblyName);
Module namedModule = assembly.GetModule(m_data);
if (namedModule == null)
throw new SerializationException(
String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_UnableToFindModule"), m_data, m_assemblyName));
return namedModule;
}
case AssemblyUnity:
{
if (m_data == null || m_data.Length == 0)
ThrowInsufficientInformation("Data");
if (m_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
assembly = Assembly.Load(m_assemblyName);
return assembly;
}
default:
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidUnity"));
}
}
#endregion