/// <summary>Preloads the given <see cref="T:System.Type" /> based on values set in a <see cref="T:System.Runtime.Remoting.Metadata.SoapTypeAttribute" /> on the type.</summary>
/// <param name="type">The <see cref="T:System.Type" /> to preload. </param>
/// <exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
/// </PermissionSet>
public static void PreLoad(Type type)
{
SoapServices.TypeInfo typeInfo = SoapServices._typeInfos[type] as SoapServices.TypeInfo;
if (typeInfo != null)
{
return;
}
string text;
string text2;
if (SoapServices.GetXmlTypeForInteropType(type, out text, out text2))
{
SoapServices.RegisterInteropXmlType(text, text2, type);
}
if (SoapServices.GetXmlElementForInteropType(type, out text, out text2))
{
SoapServices.RegisterInteropXmlElement(text, text2, type);
}
object syncRoot = SoapServices._typeInfos.SyncRoot;
lock (syncRoot)
{
typeInfo = new SoapServices.TypeInfo();
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
SoapFieldAttribute soapFieldAttribute = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(fieldInfo);
if (soapFieldAttribute.IsInteropXmlElement())
{
string nameKey = SoapServices.GetNameKey(soapFieldAttribute.XmlElementName, soapFieldAttribute.XmlNamespace);
if (soapFieldAttribute.UseAttribute)
{
if (typeInfo.Attributes == null)
{
typeInfo.Attributes = new Hashtable();
}
typeInfo.Attributes[nameKey] = fieldInfo;
}
else
{
if (typeInfo.Elements == null)
{
typeInfo.Elements = new Hashtable();
}
typeInfo.Elements[nameKey] = fieldInfo;
}
}
}
SoapServices._typeInfos[type] = typeInfo;
}
}