14 private const int defaultSize = 4;
16 private const string s_mscorlibAssemblySimpleName =
"mscorlib";
18 private const string s_mscorlibFileName =
"mscorlib.dll";
20 internal string[] m_members;
22 internal object[] m_data;
24 internal Type[] m_types;
28 internal int m_currMember;
32 private string m_fullTypeName;
34 private string m_assemName;
36 private Type objectType;
38 private bool isFullTypeNameSetExplicit;
40 private bool isAssemblyNameSetExplicit;
42 private bool requireSameTokenInPartialTrust;
51 return m_fullTypeName;
59 m_fullTypeName = value;
60 isFullTypeNameSetExplicit =
true;
73 [SecuritySafeCritical]
80 if (requireSameTokenInPartialTrust)
82 DemandForUnsafeAssemblyNameAssignments(m_assemName, value);
85 isAssemblyNameSetExplicit =
true;
107 internal string[] MemberNames => m_members;
109 internal object[] MemberValues => m_data;
116 [CLSCompliant(
false)]
118 : this(type, converter, requireSameTokenInPartialTrust: false)
126 [CLSCompliant(
false)]
129 if ((
object)type ==
null)
133 if (converter ==
null)
140 m_members =
new string[4];
141 m_data =
new object[4];
142 m_types =
new Type[4];
144 m_converter = converter;
145 this.requireSameTokenInPartialTrust = requireSameTokenInPartialTrust;
151 [SecuritySafeCritical]
154 if ((
object)type ==
null)
158 if (requireSameTokenInPartialTrust)
162 if ((
object)objectType != type)
167 isFullTypeNameSetExplicit =
false;
168 isAssemblyNameSetExplicit =
false;
172 private static bool Compare(
byte[] a,
byte[] b)
174 if (a ==
null || b ==
null || a.Length == 0 || b.Length == 0 || a.Length != b.Length)
178 for (
int i = 0; i < a.Length; i++)
188 [SecuritySafeCritical]
189 internal static void DemandForUnsafeAssemblyNameAssignments(
string originalAssemblyName,
string newAssemblyName)
191 if (!IsAssemblyNameAssignmentSafe(originalAssemblyName, newAssemblyName))
197 internal static bool IsAssemblyNameAssignmentSafe(
string originalAssemblyName,
string newAssemblyName)
199 if (originalAssemblyName == newAssemblyName)
219 private void ExpandArrays()
221 int num = m_currMember * 2;
222 if (num < m_currMember && int.MaxValue > m_currMember)
226 string[] array =
new string[num];
227 object[] array2 =
new object[num];
229 Array.
Copy(m_members, array, m_currMember);
230 Array.
Copy(m_data, array2, m_currMember);
231 Array.
Copy(m_types, array3, m_currMember);
249 if ((
object)type ==
null)
253 AddValueInternal(name, value, type);
266 AddValue(name, value, typeof(
object));
270 AddValue(name, value, value.GetType());
281 AddValue(name, value, typeof(
bool));
291 AddValue(name, value, typeof(
char));
299 [CLSCompliant(
false)]
302 AddValue(name, value, typeof(sbyte));
312 AddValue(name, value, typeof(
byte));
322 AddValue(name, value, typeof(
short));
330 [CLSCompliant(
false)]
333 AddValue(name, value, typeof(ushort));
351 [CLSCompliant(
false)]
354 AddValue(name, value, typeof(uint));
364 AddValue(name, value, typeof(
long));
372 [CLSCompliant(
false)]
375 AddValue(name, value, typeof(ulong));
385 AddValue(name, value, typeof(
float));
395 AddValue(name, value, typeof(
double));
405 AddValue(name, value, typeof(decimal));
418 internal void AddValueInternal(
string name,
object value,
Type type)
424 m_nameToIndex.
Add(name, m_currMember);
425 if (m_currMember >= m_members.Length)
429 m_members[m_currMember] = name;
430 m_data[m_currMember] = value;
431 m_types[m_currMember] = type;
435 internal void UpdateValue(
string name,
object value, Type type)
437 int num = FindElement(name);
440 AddValueInternal(name, value, type);
447 private int FindElement(
string name)
451 throw new ArgumentNullException(
"name");
453 if (m_nameToIndex.
TryGetValue(name, out
int value))
460 private object GetElement(
string name, out Type foundType)
462 int num = FindElement(name);
465 throw new SerializationException(Environment.GetResourceString(
"Serialization_NotFound", name));
467 foundType = m_types[num];
472 private object GetElementNoThrow(
string name, out Type foundType)
474 int num = FindElement(name);
480 foundType = m_types[num];
492 [SecuritySafeCritical]
495 if ((
object)type ==
null)
499 RuntimeType runtimeType = type as RuntimeType;
500 if (runtimeType ==
null)
505 object element = GetElement(name, out foundType);
514 else if ((
object)foundType == type || type.
IsAssignableFrom(foundType) || element ==
null)
518 return m_converter.
Convert(element, type);
521 [SecuritySafeCritical]
523 internal object GetValueNoThrow(
string name,
Type type)
526 object elementNoThrow = GetElementNoThrow(name, out foundType);
527 if (elementNoThrow ==
null)
536 return elementNoThrow;
539 else if ((
object)foundType == type || type.
IsAssignableFrom(foundType) || elementNoThrow ==
null)
541 return elementNoThrow;
543 return m_converter.
Convert(elementNoThrow, type);
556 object element = GetElement(name, out foundType);
557 if ((
object)foundType == typeof(
bool))
559 return (
bool)element;
574 object element = GetElement(name, out foundType);
575 if ((
object)foundType == typeof(
char))
577 return (
char)element;
579 return m_converter.
ToChar(element);
589 [CLSCompliant(
false)]
593 object element = GetElement(name, out foundType);
594 if ((
object)foundType == typeof(sbyte))
596 return (sbyte)element;
598 return m_converter.
ToSByte(element);
611 object element = GetElement(name, out foundType);
612 if ((
object)foundType == typeof(
byte))
614 return (
byte)element;
616 return m_converter.
ToByte(element);
629 object element = GetElement(name, out foundType);
630 if ((
object)foundType == typeof(
short))
632 return (
short)element;
634 return m_converter.
ToInt16(element);
644 [CLSCompliant(
false)]
648 object element = GetElement(name, out foundType);
649 if ((
object)foundType == typeof(ushort))
651 return (ushort)element;
653 return m_converter.
ToUInt16(element);
666 object element = GetElement(name, out foundType);
667 if ((
object)foundType == typeof(
int))
671 return m_converter.
ToInt32(element);
681 [CLSCompliant(
false)]
685 object element = GetElement(name, out foundType);
686 if ((
object)foundType == typeof(uint))
688 return (uint)element;
690 return m_converter.
ToUInt32(element);
703 object element = GetElement(name, out foundType);
704 if ((
object)foundType == typeof(
long))
706 return (
long)element;
708 return m_converter.
ToInt64(element);
718 [CLSCompliant(
false)]
722 object element = GetElement(name, out foundType);
723 if ((
object)foundType == typeof(ulong))
725 return (ulong)element;
727 return m_converter.
ToUInt64(element);
740 object element = GetElement(name, out foundType);
741 if ((
object)foundType == typeof(
float))
743 return (
float)element;
745 return m_converter.
ToSingle(element);
758 object element = GetElement(name, out foundType);
759 if ((
object)foundType == typeof(
double))
761 return (
double)element;
763 return m_converter.
ToDouble(element);
776 object element = GetElement(name, out foundType);
777 if ((
object)foundType == typeof(decimal))
779 return (decimal)element;
794 object element = GetElement(name, out foundType);
795 if ((
object)foundType == typeof(
DateTime))
812 object element = GetElement(name, out foundType);
813 if ((
object)foundType == typeof(
string) || element ==
null)
815 return (
string)element;
817 return m_converter.
ToString(element);
virtual Assembly Assembly
Gets the appropriate T:System.Reflection.Assembly for this instance of T:System.Reflection....
void AddValue(string name, sbyte value)
Adds an 8-bit signed integer value into the T:System.Runtime.Serialization.SerializationInfo store.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
long GetInt64(string name)
Retrieves a 64-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
ulong GetUInt64(string name)
Retrieves a 64-bit unsigned integer value from the T:System.Runtime.Serialization....
float GetSingle(string name)
Retrieves a single-precision floating-point value from the T:System.Runtime.Serialization....
sbyte GetSByte(string name)
Retrieves an 8-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
virtual string FullName
Gets the display name of the assembly.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
bool GetBoolean(string name)
Retrieves a Boolean value from the T:System.Runtime.Serialization.SerializationInfo store.
Provides base functionality for proxies.
void SetType(Type type)
Sets the T:System.Type of the object to serialize.
SerializationInfoEnumerator GetEnumerator()
Returns a T:System.Runtime.Serialization.SerializationInfoEnumerator used to iterate through the name...
void AddValue(string name, char value)
Adds a Unicode character value into the T:System.Runtime.Serialization.SerializationInfo store.
string FullTypeName
Gets or sets the full name of the T:System.Type to serialize.
void AddValue(string name, int value)
Adds a 32-bit signed integer value into the T:System.Runtime.Serialization.SerializationInfo store.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
void AddValue(string name, short value)
Adds a 16-bit signed integer value into the T:System.Runtime.Serialization.SerializationInfo store.
SerializationInfo(Type type, IFormatterConverter converter)
Creates a new instance of the T:System.Runtime.Serialization.SerializationInfo class.
Type ObjectType
Returns the type of the object to be serialized.
bool ContainsKey(TKey key)
Determines whether the T:System.Collections.Generic.Dictionary`2 contains the specified key.
char GetChar(string name)
Retrieves a Unicode character value from the T:System.Runtime.Serialization.SerializationInfo store.
string AssemblyName
Gets or sets the assembly name of the type to serialize during serialization only.
Provides information about, and means to manipulate, the current environment and platform....
void AddValue(string name, decimal value)
Adds a decimal value into the T:System.Runtime.Serialization.SerializationInfo store.
void AddValue(string name, object value, Type type)
Adds a value into the T:System.Runtime.Serialization.SerializationInfo store, where value is associa...
string Name
Gets or sets the simple name of the assembly. This is usually, but not necessarily,...
void AddValue(string name, ushort value)
Adds a 16-bit unsigned integer value into the T:System.Runtime.Serialization.SerializationInfo store.
SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust)
Initializes a new instance of the T:System.Runtime.Serialization.SerializationInfo class.
Defines the underlying structure of all code access permissions.
void AddValue(string name, byte value)
Adds an 8-bit unsigned integer value into the T:System.Runtime.Serialization.SerializationInfo store.
void AddValue(string name, float value)
Adds a single-precision floating-point value into the T:System.Runtime.Serialization....
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
abstract Assembly Assembly
Gets the T:System.Reflection.Assembly in which the type is declared. For generic types,...
Represents type declarations: class types, interface types, array types, value types,...
short GetInt16(string name)
Retrieves a 16-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
The exception thrown when an error occurs during serialization or deserialization.
void AddValue(string name, ulong value)
Adds a 64-bit unsigned integer value into the T:System.Runtime.Serialization.SerializationInfo store.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
void AddValue(string name, DateTime value)
Adds a T:System.DateTime value into the T:System.Runtime.Serialization.SerializationInfo store.
static bool IsTransparentProxy(object proxy)
Returns a Boolean value that indicates whether the given object is a transparent proxy or a real obje...
Describes an assembly's unique identity in full.
void AddValue(string name, object value)
Adds the specified object into the T:System.Runtime.Serialization.SerializationInfo store,...
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
static RealProxy GetRealProxy(object proxy)
Returns the real proxy backing the specified transparent proxy.
decimal GetDecimal(string name)
Retrieves a decimal value from the T:System.Runtime.Serialization.SerializationInfo store.
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 ...
bool IsFullTypeNameSetExplicit
Gets whether the full type name has been explicitly set.
uint GetUInt32(string name)
Retrieves a 32-bit unsigned integer value from the T:System.Runtime.Serialization....
int MemberCount
Gets the number of members that have been added to the T:System.Runtime.Serialization....
string GetString(string name)
Retrieves a T:System.String value from the T:System.Runtime.Serialization.SerializationInfo store.
ushort GetUInt16(string name)
Retrieves a 16-bit unsigned integer value from the T:System.Runtime.Serialization....
void AddValue(string name, long value)
Adds a 64-bit signed integer value into the T:System.Runtime.Serialization.SerializationInfo store.
object GetValue(string name, Type type)
Retrieves a value from the T:System.Runtime.Serialization.SerializationInfo store.
bool IsAssemblyNameSetExplicit
Gets whether the assembly name has been explicitly set.
void AddValue(string name, bool value)
Adds a Boolean value into the T:System.Runtime.Serialization.SerializationInfo store.
void Add(TKey key, TValue value)
Adds the specified key and value to the dictionary.
int GetInt32(string name)
Retrieves a 32-bit signed integer value from the T:System.Runtime.Serialization.SerializationInfo sto...
DateTime GetDateTime(string name)
Retrieves a T:System.DateTime value from the T:System.Runtime.Serialization.SerializationInfo store.
abstract new Module Module
Gets the module (the DLL) in which the current T:System.Type is defined.
byte GetByte(string name)
Retrieves an 8-bit unsigned integer value from the T:System.Runtime.Serialization....
double GetDouble(string name)
Retrieves a double-precision floating-point value from the T:System.Runtime.Serialization....
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
void AddValue(string name, double value)
Adds a double-precision floating-point value into the T:System.Runtime.Serialization....
Provides a formatter-friendly mechanism for parsing the data in T:System.Runtime.Serialization....
bool TryGetValue(TKey key, out TValue value)
Gets the value associated with the specified key.
void AddValue(string name, uint value)
Adds a 32-bit unsigned integer value into the T:System.Runtime.Serialization.SerializationInfo store.
byte [] GetPublicKeyToken()
Gets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which ...
virtual bool IsAssignableFrom(Type c)
Determines whether an instance of a specified type can be assigned to an instance of the current type...