using System;
using System.Collections;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Lifetime;
using System.Runtime.Serialization.Formatters;
using System.Security;
namespace System.Runtime.Serialization
{
/// Provides static methods to aid with the implementation of a for serialization. This class cannot be inherited.
// Token: 0x0200047A RID: 1146
[ComVisible(true)]
public sealed class FormatterServices
{
// Token: 0x06002BD6 RID: 11222 RVA: 0x000907EC File Offset: 0x0008E9EC
private FormatterServices()
{
}
/// Extracts the data from the specified object and returns it as an array of objects.
/// An array of that contains data stored in and associated with .
/// The object to write to the formatter.
/// The members to extract from the object.
/// The or parameter is null.An element of is null.
/// An element of does not represent a field.
///
///
///
// Token: 0x06002BD7 RID: 11223 RVA: 0x000907F4 File Offset: 0x0008E9F4
public static object[] GetObjectData(object obj, MemberInfo[] members)
{
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (members == null)
{
throw new ArgumentNullException("members");
}
int num = members.Length;
object[] array = new object[num];
for (int i = 0; i < num; i++)
{
MemberInfo memberInfo = members[i];
if (memberInfo == null)
{
throw new ArgumentNullException(string.Format("members[{0}]", i));
}
if (memberInfo.MemberType != MemberTypes.Field)
{
throw new SerializationException(string.Format("members [{0}] is not a field.", i));
}
FieldInfo fieldInfo = memberInfo as FieldInfo;
array[i] = fieldInfo.GetValue(obj);
}
return array;
}
/// Gets all the serializable members for a class of the specified .
/// An array of type of the non-transient, non-static members.
/// The type being serialized.
/// The parameter is null.
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BD8 RID: 11224 RVA: 0x00090898 File Offset: 0x0008EA98
public static MemberInfo[] GetSerializableMembers(Type type)
{
StreamingContext streamingContext = new StreamingContext(StreamingContextStates.All);
return FormatterServices.GetSerializableMembers(type, streamingContext);
}
/// Gets all the serializable members for a class of the specified and in the provided .
/// An array of type of the non-transient, non-static members.
/// The type being serialized or cloned.
/// The context where the serialization occurs.
/// The parameter is null.
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BD9 RID: 11225 RVA: 0x000908B8 File Offset: 0x0008EAB8
public static MemberInfo[] GetSerializableMembers(Type type, StreamingContext context)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
ArrayList arrayList = new ArrayList();
for (Type type2 = type; type2 != null; type2 = type2.BaseType)
{
if (!type2.IsSerializable)
{
string text = string.Format("Type {0} in assembly {1} is not marked as serializable.", type2, type2.Assembly.FullName);
throw new SerializationException(text);
}
FormatterServices.GetFields(type, type2, arrayList);
}
MemberInfo[] array = new MemberInfo[arrayList.Count];
arrayList.CopyTo(array);
return array;
}
// Token: 0x06002BDA RID: 11226 RVA: 0x00090938 File Offset: 0x0008EB38
private static void GetFields(Type reflectedType, Type type, ArrayList fields)
{
FieldInfo[] fields2 = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields2)
{
if (!fieldInfo.IsNotSerialized)
{
MonoField monoField = fieldInfo as MonoField;
if (monoField != null && reflectedType != type && !monoField.IsPublic)
{
string text = type.Name + "+" + monoField.Name;
fields.Add(monoField.Clone(text));
}
else
{
fields.Add(fieldInfo);
}
}
}
}
/// Looks up the of the specified object in the provided .
/// The of the object.
/// The assembly where you want to look up the object.
/// The name of the object.
/// The parameter is null.
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BDB RID: 11227 RVA: 0x000909CC File Offset: 0x0008EBCC
public static Type GetTypeFromAssembly(Assembly assem, string name)
{
if (assem == null)
{
throw new ArgumentNullException("assem");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
return assem.GetType(name);
}
/// Creates a new instance of the specified object type.
/// A zeroed object of the specified type.
/// The type of object to create.
/// The parameter is null.
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BDC RID: 11228 RVA: 0x000909F8 File Offset: 0x0008EBF8
public static object GetUninitializedObject(Type type)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (type == typeof(string))
{
throw new ArgumentException("Uninitialized Strings cannot be created.");
}
return ActivationServices.AllocateUninitializedClassInstance(type);
}
/// Populates the specified object with values for each field drawn from the data array of objects.
/// The newly populated object.
/// The object to populate.
/// An array of that describes which fields and properties to populate.
/// An array of that specifies the values for each field and property to populate.
/// The , , or parameter is null.An element of is null.
/// The length of does not match the length of .
/// An element of is not an instance of .
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BDD RID: 11229 RVA: 0x00090A38 File Offset: 0x0008EC38
public static object PopulateObjectMembers(object obj, MemberInfo[] members, object[] data)
{
if (obj == null)
{
throw new ArgumentNullException("obj");
}
if (members == null)
{
throw new ArgumentNullException("members");
}
if (data == null)
{
throw new ArgumentNullException("data");
}
int num = members.Length;
if (num != data.Length)
{
throw new ArgumentException("different length in members and data");
}
for (int i = 0; i < num; i++)
{
MemberInfo memberInfo = members[i];
if (memberInfo == null)
{
throw new ArgumentNullException(string.Format("members[{0}]", i));
}
if (memberInfo.MemberType != MemberTypes.Field)
{
throw new SerializationException(string.Format("members [{0}] is not a field.", i));
}
FieldInfo fieldInfo = memberInfo as FieldInfo;
fieldInfo.SetValue(obj, data[i]);
}
return obj;
}
/// Determines whether the specified can be deserialized with the property set to Low.
/// The to check for the ability to deserialize.
/// The property value.
/// The parameter is an advanced type and cannot be deserialized when the property is set to Low.
// Token: 0x06002BDE RID: 11230 RVA: 0x00090AF8 File Offset: 0x0008ECF8
public static void CheckTypeSecurity(Type t, TypeFilterLevel securityLevel)
{
if (securityLevel == TypeFilterLevel.Full)
{
return;
}
FormatterServices.CheckNotAssignable(typeof(DelegateSerializationHolder), t);
FormatterServices.CheckNotAssignable(typeof(ISponsor), t);
FormatterServices.CheckNotAssignable(typeof(IEnvoyInfo), t);
FormatterServices.CheckNotAssignable(typeof(ObjRef), t);
}
// Token: 0x06002BDF RID: 11231 RVA: 0x00090B50 File Offset: 0x0008ED50
private static void CheckNotAssignable(Type basetype, Type type)
{
if (basetype.IsAssignableFrom(type))
{
string text = "Type " + basetype + " and the types derived from it";
string text2 = text;
text = string.Concat(new object[] { text2, " (such as ", type, ") are not permitted to be deserialized at this security level" });
throw new SecurityException(text);
}
}
/// Creates a new instance of the specified object type.
/// A zeroed object of the specified type.
/// The type of object to create.
/// The parameter is null.
/// The parameter is not a valid common language runtime type.
/// The caller does not have the required permission.
///
///
///
// Token: 0x06002BE0 RID: 11232 RVA: 0x00090BA8 File Offset: 0x0008EDA8
public static object GetSafeUninitializedObject(Type type)
{
return FormatterServices.GetUninitializedObject(type);
}
// Token: 0x040010FF RID: 4351
private const BindingFlags fieldFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
}
}