25 private static bool unsafeTypeForwardersIsEnabled;
28 private static volatile bool unsafeTypeForwardersIsEnabledInitialized;
30 private static readonly
Type[] advancedTypes;
32 private static Binder s_binder;
34 [SecuritySafeCritical]
38 unsafeTypeForwardersIsEnabled =
false;
39 unsafeTypeForwardersIsEnabledInitialized =
false;
40 advancedTypes =
new Type[4]
42 typeof(DelegateSerializationHolder),
50 private static MemberInfo[] GetSerializableMembers(RuntimeType type)
54 for (
int i = 0; i < fields.Length; i++)
61 if (num != fields.Length)
65 for (
int j = 0; j < fields.Length; j++)
69 array[num] = fields[j];
78 private static bool CheckSerializable(RuntimeType type)
80 if (type.IsSerializable)
87 private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type)
94 if (!CheckSerializable(type))
98 MemberInfo[] array = GetSerializableMembers(type);
99 RuntimeType runtimeType = (RuntimeType)type.BaseType;
100 if (runtimeType !=
null && runtimeType != (RuntimeType)typeof(
object))
102 RuntimeType[] parentTypes =
null;
103 int parentTypeCount = 0;
104 bool parentTypes2 = GetParentTypes(runtimeType, out parentTypes, out parentTypeCount);
105 if (parentTypeCount > 0)
108 for (
int i = 0; i < parentTypeCount; i++)
110 runtimeType = parentTypes[i];
111 if (!CheckSerializable(runtimeType))
116 string namePrefix = parentTypes2 ? runtimeType.
Name : runtimeType.FullName;
122 list.Add(
new SerializationFieldInfo((RuntimeFieldInfo)fieldInfo, namePrefix));
126 if (list !=
null && list.Count > 0)
138 private static bool GetParentTypes(RuntimeType parentType, out RuntimeType[] parentTypes, out
int parentTypeCount)
143 RuntimeType right = (RuntimeType)typeof(
object);
144 RuntimeType runtimeType = parentType;
145 while (runtimeType != right)
147 if (!runtimeType.IsInterface)
149 string name = runtimeType.Name;
151 while (flag && num < parentTypeCount)
153 string name2 = parentTypes[num].Name;
154 if (name2.Length == name.Length && name2[0] == name[0] && name == name2)
161 if (parentTypes ==
null || parentTypeCount == parentTypes.Length)
163 RuntimeType[] array =
new RuntimeType[
Math.
Max(parentTypeCount * 2, 12)];
164 if (parentTypes !=
null)
166 Array.
Copy(parentTypes, 0, array, 0, parentTypeCount);
170 parentTypes[parentTypeCount++] = runtimeType;
172 runtimeType = (RuntimeType)runtimeType.BaseType;
197 if ((
object)type ==
null)
201 if (!(type is RuntimeType))
205 MemberHolder key =
new MemberHolder(type, context);
206 return m_MemberInfoTable.
GetOrAdd(key, (MemberHolder _) => InternalGetSerializableMembers((RuntimeType)type));
222 if (num < advancedTypes.Length)
224 if (advancedTypes[num].IsAssignableFrom(t))
244 if ((
object)type ==
null)
248 if (!(type is RuntimeType))
252 return nativeGetUninitializedObject((RuntimeType)type);
264 if ((
object)type ==
null)
268 if (!(type is RuntimeType))
274 return nativeGetUninitializedObject((RuntimeType)type);
278 return nativeGetSafeUninitializedObject((RuntimeType)type);
288 private static extern object nativeGetSafeUninitializedObject(RuntimeType type);
292 private static extern object nativeGetUninitializedObject(RuntimeType type);
296 private static extern bool GetEnableUnsafeTypeForwarders();
298 [SecuritySafeCritical]
299 internal static bool UnsafeTypeForwardersIsEnabled()
301 if (!unsafeTypeForwardersIsEnabledInitialized)
303 unsafeTypeForwardersIsEnabled = GetEnableUnsafeTypeForwarders();
304 unsafeTypeForwardersIsEnabledInitialized =
true;
306 return unsafeTypeForwardersIsEnabled;
310 internal static void SerializationSetValue(
MemberInfo fi,
object target,
object value)
312 RtFieldInfo rtFieldInfo = fi as RtFieldInfo;
313 if (rtFieldInfo !=
null)
315 rtFieldInfo.CheckConsistency(target);
316 rtFieldInfo.UnsafeSetValue(target, value,
BindingFlags.Default, s_binder,
null);
319 SerializationFieldInfo serializationFieldInfo = fi as SerializationFieldInfo;
320 if (serializationFieldInfo !=
null)
322 serializationFieldInfo.InternalSetValue(target, value,
BindingFlags.Default, s_binder,
null);
325 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidFieldInfo"));
352 if (members.Length != data.Length)
356 for (
int i = 0; i < members.Length; i++)
359 if (memberInfo ==
null)
369 SerializationSetValue(memberInfo, obj, data[i]);
392 int num = members.Length;
393 object[] array =
new object[num];
394 for (
int i = 0; i < num; i++)
397 if (memberInfo ==
null)
403 RtFieldInfo rtFieldInfo = memberInfo as RtFieldInfo;
404 if (rtFieldInfo !=
null)
406 rtFieldInfo.CheckConsistency(obj);
407 array[i] = rtFieldInfo.UnsafeGetValue(obj);
411 array[i] = ((SerializationFieldInfo)memberInfo).InternalGetValue(obj);
427 if (innerSurrogate ==
null)
431 return new SurrogateForCyclicalReference(innerSurrogate);
447 return assem.GetType(name, throwOnError:
false, ignoreCase:
false);
450 internal static Assembly LoadAssemblyFromString(
string assemblyName)
455 internal static Assembly LoadAssemblyFromStringNoThrow(
string assemblyName)
459 return LoadAssemblyFromString(assemblyName);
467 internal static string GetClrAssemblyName(Type type, out
bool hasTypeForwardedFrom)
469 if ((
object)type ==
null)
471 throw new ArgumentNullException(
"type");
474 if (customAttributes !=
null && customAttributes.Length != 0)
476 hasTypeForwardedFrom =
true;
480 hasTypeForwardedFrom =
false;
481 return type.Assembly.FullName;
484 internal static string GetClrTypeFullName(Type type)
488 return GetClrTypeFullNameForArray(type);
490 return GetClrTypeFullNameForNonArrayTypes(type);
493 private static string GetClrTypeFullNameForArray(Type type)
495 int arrayRank = type.GetArrayRank();
501 for (
int i = 1; i < arrayRank; i++)
503 stringBuilder.
Append(
",");
505 stringBuilder.
Append(
"]");
509 private static string GetClrTypeFullNameForNonArrayTypes(Type type)
511 if (!type.IsGenericType)
513 return type.FullName;
515 Type[] genericArguments = type.GetGenericArguments();
517 Type[] array = genericArguments;
518 foreach (Type type2
in array)
521 stringBuilder.
Append(GetClrAssemblyName(type2, out
bool _)).
Append(
"],");
Obtains information about the attributes of a member and provides access to member metadata.
bool IsNotSerialized
Gets a value indicating whether this field has the NotSerialized attribute.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static Assembly Load(string assemblyString)
Loads an assembly given the long form of its name.
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Discovers the attributes of a field and provides access to field metadata.
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
override string ToString()
Returns a String representing the name of the current Type.
Stores all relevant information required to generate a proxy in order to communicate with a remote ob...
string AssemblyFullName
Gets the assembly-qualified name of the source type.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static Binder DefaultBinder
Gets a reference to the default binder, which implements internal rules for selecting the appropriate...
Provides information about, and means to manipulate, the current environment and platform....
Specifies a source T:System.Type in another assembly.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
TValue GetOrAdd(TKey key, Func< TKey, TValue > valueFactory)
Adds a key/value pair to the T:System.Collections.Concurrent.ConcurrentDictionary`2 by using the spec...
static sbyte Max(sbyte val1, sbyte val2)
Returns the larger of two 8-bit signed integers.
FieldAttributes
Specifies flags that describe the attributes of a field.
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
Opens the file if it exists and seeks to the end of the file, or creates a new file....
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Implements a serialization surrogate selector that allows one object to perform serialization and des...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Represents type declarations: class types, interface types, array types, value types,...
The exception thrown when an error occurs during serialization or deserialization.
MethodImplOptions
Defines the details of how a method is implemented.
abstract string Name
Gets the name of the current member.
Provides a set of properties that are carried with the execution code path during remote method calls...
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
The exception that is thrown when one of the arguments provided to a method is not valid.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Provides envoy information.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
abstract MemberTypes MemberType
When overridden in a derived class, gets a T:System.Reflection.MemberTypes value indicating the type ...
StreamingContextStates
Defines a set of flags that specifies the source or destination context for the stream during seriali...
Provides information about a specific culture (called a locale for unmanaged code development)....
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Defines size, enumerators, and synchronization methods for all nongeneric collections.
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
Implements the T:System.Runtime.Remoting.Activation.IConstructionCallMessage interface to create a re...
The exception that is thrown when a security error is detected.
Enforces a synchronization domain for the current context and all contexts that share the same instan...
StringBuilder Remove(int startIndex, int length)
Removes the specified range of characters from this instance.