<Compile Include="$(BclSourcesRoot)\System\UInt32.cs" />
<Compile Include="$(BclSourcesRoot)\System\UInt64.cs" />
<Compile Include="$(BclSourcesRoot)\System\UIntPtr.cs" />
- <Compile Include="$(BclSourcesRoot)\System\UnitySerializationHolder.cs" />
<Compile Include="$(BclSourcesRoot)\System\ValueType.cs" />
<Compile Include="$(BclSourcesRoot)\System\Version.cs" />
<Compile Include="$(BclSourcesRoot)\System\WeakReference.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MdImport.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MemberFilter.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfo.Internal.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberInfoSerializationHolder.cs" />
+ <Compile Include="$(BclSourcesRoot)\System\Reflection\MemberSerializationStringGenerator.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MemberTypes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\IReflect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfoSerializationHolder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Module.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\UnauthorizedAccessException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventArgs.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\UnhandledExceptionEventHandler.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\UnitySerializationHolder.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Void.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleMinusOneIsInvalid.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\CriticalHandleZeroOrMinusOneIsInvalid.cs"/>
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-//
-
using System;
-using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Globalization;
using System.Diagnostics.Contracts;
namespace System.Reflection
{
[Serializable]
- internal class MemberInfoSerializationHolder : ISerializable, IObjectReference
+#if CORECLR
+ internal
+#else
+ public // On CoreRT, this must be public because of the Reflection.Core/CoreLib divide and the need to whitelist past the ReflectionBlock.
+#endif
+ class MemberInfoSerializationHolder : ISerializable, IObjectReference
{
#region Staitc Public Members
- public static void GetSerializationInfo(SerializationInfo info, String name, RuntimeType reflectedClass, String signature, MemberTypes type)
+ public static void GetSerializationInfo(SerializationInfo info, FieldInfo f)
+ {
+ // Compat: Serializing ToString() since the full framework does it but the deserialization logic makes no use of it.
+ GetSerializationInfo(info, f.Name, f.ReflectedType, f.ToString(), MemberTypes.Field);
+ }
+
+ public static void GetSerializationInfo(SerializationInfo info, EventInfo e)
+ {
+ GetSerializationInfo(info, e.Name, e.ReflectedType, null, MemberTypes.Event);
+ }
+
+ public static void GetSerializationInfo(SerializationInfo info, ConstructorInfo c)
+ {
+ GetSerializationInfo(info, c.Name, c.ReflectedType, c.ToString(), c.SerializationToString(), MemberTypes.Constructor, genericArguments: null);
+ }
+
+ public static void GetSerializationInfo(SerializationInfo info, MethodInfo m)
+ {
+ Type[] genericArguments = m.IsConstructedGenericMethod ? m.GetGenericArguments() : null;
+ GetSerializationInfo(info, m.Name, m.ReflectedType, m.ToString(), m.SerializationToString(), MemberTypes.Method, genericArguments);
+ }
+
+ public static void GetSerializationInfo(SerializationInfo info, PropertyInfo p)
+ {
+ GetSerializationInfo(info, p.Name, p.ReflectedType, p.ToString(), p.SerializationToString(), MemberTypes.Property, genericArguments: null);
+ }
+ #endregion
+
+ #region Private Static Members
+ private static void GetSerializationInfo(SerializationInfo info, string name, Type reflectedClass, string signature, MemberTypes type)
{
GetSerializationInfo(info, name, reflectedClass, signature, null, type, null);
}
- public static void GetSerializationInfo(
+ private static void GetSerializationInfo(
SerializationInfo info,
- String name,
- RuntimeType reflectedClass,
- String signature,
- String signature2,
+ string name,
+ Type reflectedClass,
+ string signature,
+ string signature2,
MemberTypes type,
Type[] genericArguments)
{
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- String assemblyName = reflectedClass.Module.Assembly.FullName;
- String typeName = reflectedClass.FullName;
+ string assemblyName = reflectedClass.Module.Assembly.FullName;
+ string typeName = reflectedClass.FullName;
info.SetType(typeof(MemberInfoSerializationHolder));
- info.AddValue("Name", name, typeof(String));
- info.AddValue("AssemblyName", assemblyName, typeof(String));
- info.AddValue("ClassName", typeName, typeof(String));
- info.AddValue("Signature", signature, typeof(String));
- info.AddValue("Signature2", signature2, typeof(String));
+ info.AddValue("Name", name, typeof(string));
+ info.AddValue("AssemblyName", assemblyName, typeof(string));
+ info.AddValue("ClassName", typeName, typeof(string));
+ info.AddValue("Signature", signature, typeof(string));
+ info.AddValue("Signature2", signature2, typeof(string));
info.AddValue("MemberType", (int)type);
info.AddValue("GenericArguments", genericArguments, typeof(Type[]));
}
#endregion
#region Private Data Members
- private String m_memberName;
- private RuntimeType m_reflectedType;
- // m_signature stores the ToString() representation of the member which is sometimes ambiguous.
+ private readonly string _memberName;
+ private readonly Type _reflectedType;
+ // _signature stores the ToString() representation of the member which is sometimes ambiguous.
// Mulitple overloads of the same methods or properties can identical ToString().
- // m_signature2 stores the SerializationToString() representation which should be unique for each member.
+ // _signature2 stores the SerializationToString() representation which should be unique for each member.
// It is only written and used by post 4.0 CLR versions.
- private String m_signature;
- private String m_signature2;
- private MemberTypes m_memberType;
- private SerializationInfo m_info;
+ private readonly string _signature;
+ private readonly string _signature2;
+ private readonly MemberTypes _memberType;
+ private readonly SerializationInfo _info;
#endregion
#region Constructor
- internal MemberInfoSerializationHolder(SerializationInfo info, StreamingContext context)
+ // Needs to be public so it can be whitelisted in Reflection.
+ public MemberInfoSerializationHolder(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- String assemblyName = info.GetString("AssemblyName");
- String typeName = info.GetString("ClassName");
+ string assemblyName = info.GetString("AssemblyName");
+ string typeName = info.GetString("ClassName");
if (assemblyName == null || typeName == null)
throw new SerializationException(SR.Serialization_InsufficientState);
- Assembly assem = FormatterServices.LoadAssemblyFromString(assemblyName);
- m_reflectedType = assem.GetType(typeName, true, false) as RuntimeType;
- m_memberName = info.GetString("Name");
- m_signature = info.GetString("Signature");
+ Assembly assem = Assembly.Load(assemblyName);
+ _reflectedType = assem.GetType(typeName, true, false);
+ _memberName = info.GetString("Name");
+ _signature = info.GetString("Signature");
// Only v4.0 and later generates and consumes Signature2
- m_signature2 = (string)info.GetValueNoThrow("Signature2", typeof(string));
- m_memberType = (MemberTypes)info.GetInt32("MemberType");
- m_info = info;
+ _signature2 = (string)info.GetValueNoThrow("Signature2", typeof(string));
+ _memberType = (MemberTypes)info.GetInt32("MemberType");
+ _info = info;
}
#endregion
#region ISerializable
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
- throw new NotSupportedException(SR.GetResourceString(ResId.NotSupported_Method));
+ throw new NotSupportedException();
}
#endregion
#region IObjectReference
- public virtual Object GetRealObject(StreamingContext context)
+ public virtual object GetRealObject(StreamingContext context)
{
- if (m_memberName == null || m_reflectedType == null || m_memberType == 0)
- throw new SerializationException(SR.GetResourceString(ResId.Serialization_InsufficientState));
+ if (_memberName == null || _reflectedType == null || _memberType == 0)
+ throw new SerializationException(SR.Serialization_InsufficientState);
BindingFlags bindingFlags =
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.OptionalParamBinding;
- switch (m_memberType)
+ switch (_memberType)
{
#region case MemberTypes.Field:
case MemberTypes.Field:
{
- FieldInfo[] fields = m_reflectedType.GetMember(m_memberName, MemberTypes.Field, bindingFlags) as FieldInfo[];
+ FieldInfo[] fields = _reflectedType.GetMember(_memberName, MemberTypes.Field, bindingFlags) as FieldInfo[];
if (fields.Length == 0)
- throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
return fields[0];
}
#region case MemberTypes.Event:
case MemberTypes.Event:
{
- EventInfo[] events = m_reflectedType.GetMember(m_memberName, MemberTypes.Event, bindingFlags) as EventInfo[];
+ EventInfo[] events = _reflectedType.GetMember(_memberName, MemberTypes.Event, bindingFlags) as EventInfo[];
if (events.Length == 0)
- throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
return events[0];
}
#region case MemberTypes.Property:
case MemberTypes.Property:
{
- PropertyInfo[] properties = m_reflectedType.GetMember(m_memberName, MemberTypes.Property, bindingFlags) as PropertyInfo[];
+ PropertyInfo[] properties = _reflectedType.GetMember(_memberName, MemberTypes.Property, bindingFlags) as PropertyInfo[];
if (properties.Length == 0)
- throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
if (properties.Length == 1)
return properties[0];
{
for (int i = 0; i < properties.Length; i++)
{
- if (m_signature2 != null)
+ if (_signature2 != null)
{
- if (((RuntimePropertyInfo)properties[i]).SerializationToString().Equals(m_signature2))
+ if (properties[i].SerializationToString().Equals(_signature2))
return properties[i];
}
else
{
- if ((properties[i]).ToString().Equals(m_signature))
+ if ((properties[i]).ToString().Equals(_signature))
return properties[i];
}
}
}
- throw new SerializationException(SR.Format(SR.GetResourceString(ResId.Serialization_UnknownMember), m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
}
#endregion
#region case MemberTypes.Constructor:
case MemberTypes.Constructor:
{
- if (m_signature == null)
- throw new SerializationException(SR.GetResourceString(ResId.Serialization_NullSignature));
+ if (_signature == null)
+ throw new SerializationException(SR.Serialization_NullSignature);
- ConstructorInfo[] constructors = m_reflectedType.GetMember(m_memberName, MemberTypes.Constructor, bindingFlags) as ConstructorInfo[];
+ ConstructorInfo[] constructors = _reflectedType.GetMember(_memberName, MemberTypes.Constructor, bindingFlags) as ConstructorInfo[];
if (constructors.Length == 1)
return constructors[0];
{
for (int i = 0; i < constructors.Length; i++)
{
- if (m_signature2 != null)
+ if (_signature2 != null)
{
- if (((RuntimeConstructorInfo)constructors[i]).SerializationToString().Equals(m_signature2))
+ if (constructors[i].SerializationToString().Equals(_signature2))
return constructors[i];
}
else
{
- if (constructors[i].ToString().Equals(m_signature))
+ if (constructors[i].ToString().Equals(_signature))
return constructors[i];
}
}
}
- throw new SerializationException(SR.Format(SR.GetResourceString(ResId.Serialization_UnknownMember), m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
}
#endregion
{
MethodInfo methodInfo = null;
- if (m_signature == null)
- throw new SerializationException(SR.GetResourceString(ResId.Serialization_NullSignature));
+ if (_signature == null)
+ throw new SerializationException(SR.Serialization_NullSignature);
- Type[] genericArguments = m_info.GetValueNoThrow("GenericArguments", typeof(Type[])) as Type[];
+ Type[] genericArguments = _info.GetValueNoThrow("GenericArguments", typeof(Type[])) as Type[];
- MethodInfo[] methods = m_reflectedType.GetMember(m_memberName, MemberTypes.Method, bindingFlags) as MethodInfo[];
+ MethodInfo[] methods = _reflectedType.GetMember(_memberName, MemberTypes.Method, bindingFlags) as MethodInfo[];
if (methods.Length == 1)
methodInfo = methods[0];
{
for (int i = 0; i < methods.Length; i++)
{
- if (m_signature2 != null)
+ if (_signature2 != null)
{
- if (((RuntimeMethodInfo)methods[i]).SerializationToString().Equals(m_signature2))
+ if (methods[i].SerializationToString().Equals(_signature2))
{
methodInfo = methods[i];
break;
}
else
{
- if (methods[i].ToString().Equals(m_signature))
+ if (methods[i].ToString().Equals(_signature))
{
methodInfo = methods[i];
break;
{
MethodInfo candidateMethod = methods[i].MakeGenericMethod(genericArguments);
- if (m_signature2 != null)
+ if (_signature2 != null)
{
- if (((RuntimeMethodInfo)candidateMethod).SerializationToString().Equals(m_signature2))
+ if (candidateMethod.SerializationToString().Equals(_signature2))
{
methodInfo = candidateMethod;
break;
}
else
{
- if (candidateMethod.ToString().Equals(m_signature))
+ if (candidateMethod.ToString().Equals(_signature))
{
methodInfo = candidateMethod;
break;
}
if (methodInfo == null)
- throw new SerializationException(SR.Format(SR.GetResourceString(ResId.Serialization_UnknownMember), m_memberName));
+ throw new SerializationException(SR.Format(SR.Serialization_UnknownMember, _memberName));
if (!methodInfo.IsGenericMethodDefinition)
return methodInfo;
#endregion
}
}
+
// See the LICENSE file in the project root for more information.
-using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Reflection;
using System.Globalization;
{
[Serializable]
// Holds classes (Empty, Null, Missing) for which we guarantee that there is only ever one instance of.
- internal class UnitySerializationHolder : ISerializable, IObjectReference
+#if CORECLR
+ internal
+#else
+ public // On CoreRT, this must be public because of the Reflection.Core/CoreLib divide and the need to whitelist past the ReflectionBlock.
+#endif
+ class UnitySerializationHolder : ISerializable, IObjectReference
{
- #region Internal Constants
+#region Internal Constants
internal const int EmptyUnity = 0x0001;
internal const int NullUnity = 0x0002;
internal const int MissingUnity = 0x0003;
internal const int RuntimeTypeUnity = 0x0004;
- internal const int ModuleUnity = 0x0005;
- internal const int AssemblyUnity = 0x0006;
+ public const int ModuleUnity = 0x0005;
+ public const int AssemblyUnity = 0x0006;
internal const int GenericParameterTypeUnity = 0x0007;
internal const int PartialInstantiationTypeUnity = 0x0008;
internal const int Array = 0x0002;
internal const int SzArray = 0x0003;
internal const int ByRef = 0x0004;
- #endregion
+#endregion
- #region Internal Static Members
+#region Internal Static Members
internal static void GetUnitySerializationInfo(SerializationInfo info, Missing missing)
{
info.SetType(typeof(UnitySerializationHolder));
info.AddValue("UnityType", MissingUnity);
}
- internal static RuntimeType AddElementTypes(SerializationInfo info, RuntimeType type)
+ internal static Type AddElementTypes(SerializationInfo info, Type type)
{
List<int> elementTypes = new List<int>();
while (type.HasElementType)
elementTypes.Add(ByRef);
}
- type = (RuntimeType)type.GetElementType();
+ type = type.GetElementType();
}
info.AddValue("ElementTypes", elementTypes.ToArray(), typeof(int[]));
internal Type MakeElementTypes(Type type)
{
- for (int i = m_elementTypes.Length - 1; i >= 0; i--)
+ for (int i = _elementTypes.Length - 1; i >= 0; i--)
{
- if (m_elementTypes[i] == SzArray)
+ if (_elementTypes[i] == SzArray)
{
type = type.MakeArrayType();
}
- else if (m_elementTypes[i] == Array)
+ else if (_elementTypes[i] == Array)
{
- type = type.MakeArrayType(m_elementTypes[--i]);
+ type = type.MakeArrayType(_elementTypes[--i]);
}
- else if ((m_elementTypes[i] == Pointer))
+ else if ((_elementTypes[i] == Pointer))
{
type = type.MakePointerType();
}
- else if ((m_elementTypes[i] == ByRef))
+ else if ((_elementTypes[i] == ByRef))
{
type = type.MakeByRefType();
}
return type;
}
- internal static void GetUnitySerializationInfo(SerializationInfo info, RuntimeType type)
+ public static void GetUnitySerializationInfo(SerializationInfo info, Type type)
{
- if (type.GetRootElementType().IsGenericParameter)
+ Type rootElementType = type;
+ while (rootElementType.HasElementType)
+ {
+ rootElementType = rootElementType.GetElementType();
+ }
+
+ if (rootElementType.IsGenericParameter)
{
type = AddElementTypes(info, type);
info.SetType(typeof(UnitySerializationHolder));
unityType = PartialInstantiationTypeUnity;
type = AddElementTypes(info, type);
info.AddValue("GenericArguments", type.GetGenericArguments(), typeof(Type[]));
- type = (RuntimeType)type.GetGenericTypeDefinition();
+ type = type.GetGenericTypeDefinition();
}
- GetUnitySerializationInfo(info, unityType, type.FullName, type.GetRuntimeAssembly());
+ GetUnitySerializationInfo(info, unityType, type.FullName, type.Assembly);
}
- internal static void GetUnitySerializationInfo(
- SerializationInfo info, int unityType, String data, RuntimeAssembly assembly)
+ public static void GetUnitySerializationInfo(
+ SerializationInfo info, int unityType, string data, Assembly assembly)
{
// A helper method that returns the SerializationInfo that a class utilizing
// UnitySerializationHelper should return from a call to GetObjectData. It contains
// types.)
info.SetType(typeof(UnitySerializationHolder));
- info.AddValue("Data", data, typeof(String));
+ info.AddValue("Data", data, typeof(string));
info.AddValue("UnityType", unityType);
- String assemName;
+ string assemName;
if (assembly == null)
{
- assemName = String.Empty;
+ assemName = string.Empty;
}
else
{
info.AddValue("AssemblyName", assemName);
}
- #endregion
-
- #region Private Data Members
- private Type[] m_instantiation;
- private int[] m_elementTypes;
- private int m_genericParameterPosition;
- private Type m_declaringType;
- private MethodBase m_declaringMethod;
- private String m_data;
- private String m_assemblyName;
- private int m_unityType;
- #endregion
-
- #region Constructor
- internal UnitySerializationHolder(SerializationInfo info, StreamingContext context)
+#endregion
+
+#region Private Data Members
+ private readonly Type[] _instantiation;
+ private readonly int[] _elementTypes;
+ private readonly int _genericParameterPosition;
+ private readonly Type _declaringType;
+ private readonly MethodBase _declaringMethod;
+ private readonly string _data;
+ private readonly string _assemblyName;
+ private int _unityType;
+#endregion
+
+#region Constructor
+ public UnitySerializationHolder(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- m_unityType = info.GetInt32("UnityType");
+ _unityType = info.GetInt32("UnityType");
- if (m_unityType == MissingUnity)
+ if (_unityType == MissingUnity)
return;
- if (m_unityType == GenericParameterTypeUnity)
+ if (_unityType == GenericParameterTypeUnity)
{
- m_declaringMethod = info.GetValue("DeclaringMethod", typeof(MethodBase)) as MethodBase;
- m_declaringType = info.GetValue("DeclaringType", typeof(Type)) as Type;
- m_genericParameterPosition = info.GetInt32("GenericParameterPosition");
- m_elementTypes = info.GetValue("ElementTypes", typeof(int[])) as int[];
+ _declaringMethod = info.GetValue("DeclaringMethod", typeof(MethodBase)) as MethodBase;
+ _declaringType = info.GetValue("DeclaringType", typeof(Type)) as Type;
+ _genericParameterPosition = info.GetInt32("GenericParameterPosition");
+ _elementTypes = info.GetValue("ElementTypes", typeof(int[])) as int[];
return;
}
- if (m_unityType == PartialInstantiationTypeUnity)
+ if (_unityType == PartialInstantiationTypeUnity)
{
- m_instantiation = info.GetValue("GenericArguments", typeof(Type[])) as Type[];
- m_elementTypes = info.GetValue("ElementTypes", typeof(int[])) as int[];
+ _instantiation = info.GetValue("GenericArguments", typeof(Type[])) as Type[];
+ _elementTypes = info.GetValue("ElementTypes", typeof(int[])) as int[];
}
- m_data = info.GetString("Data");
- m_assemblyName = info.GetString("AssemblyName");
+ _data = info.GetString("Data");
+ _assemblyName = info.GetString("AssemblyName");
}
- #endregion
+#endregion
- #region Private Methods
+#region Private Methods
private void ThrowInsufficientInformation(string field)
{
throw new SerializationException(
SR.Format(SR.Serialization_InsufficientDeserializationState, field));
}
- #endregion
+#endregion
- #region ISerializable
+#region ISerializable
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new NotSupportedException(SR.NotSupported_UnitySerHolder);
}
- #endregion
+#endregion
- #region IObjectReference
- public virtual Object GetRealObject(StreamingContext context)
+#region IObjectReference
+ 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
+ // GetRealObject uses the data we have in _data and _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)
+ switch (_unityType)
{
case EmptyUnity:
{
case PartialInstantiationTypeUnity:
{
- m_unityType = RuntimeTypeUnity;
+ _unityType = RuntimeTypeUnity;
Type definition = GetRealObject(context) as Type;
- m_unityType = PartialInstantiationTypeUnity;
+ _unityType = PartialInstantiationTypeUnity;
- if (m_instantiation[0] == null)
+ if (_instantiation[0] == null)
return null;
- return MakeElementTypes(definition.MakeGenericType(m_instantiation));
+ return MakeElementTypes(definition.MakeGenericType(_instantiation));
}
case GenericParameterTypeUnity:
{
- if (m_declaringMethod == null && m_declaringType == null)
+ if (_declaringMethod == null && _declaringType == null)
ThrowInsufficientInformation("DeclaringMember");
- if (m_declaringMethod != null)
- return m_declaringMethod.GetGenericArguments()[m_genericParameterPosition];
+ if (_declaringMethod != null)
+ return _declaringMethod.GetGenericArguments()[_genericParameterPosition];
- return MakeElementTypes(m_declaringType.GetGenericArguments()[m_genericParameterPosition]);
+ return MakeElementTypes(_declaringType.GetGenericArguments()[_genericParameterPosition]);
}
case RuntimeTypeUnity:
{
- if (m_data == null || m_data.Length == 0)
+ if (_data == null || _data.Length == 0)
ThrowInsufficientInformation("Data");
- if (m_assemblyName == null)
+ if (_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
- if (m_assemblyName.Length == 0)
- return Type.GetType(m_data, true, false);
+ if (_assemblyName.Length == 0)
+ return Type.GetType(_data, true, false);
- assembly = Assembly.Load(m_assemblyName);
+ assembly = Assembly.Load(_assemblyName);
- Type t = assembly.GetType(m_data, true, false);
+ Type t = assembly.GetType(_data, true, false);
return t;
}
case ModuleUnity:
{
- if (m_data == null || m_data.Length == 0)
+ if (_data == null || _data.Length == 0)
ThrowInsufficientInformation("Data");
- if (m_assemblyName == null)
+ if (_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
- assembly = Assembly.Load(m_assemblyName);
+ assembly = Assembly.Load(_assemblyName);
- Module namedModule = assembly.GetModule(m_data);
+ Module namedModule = assembly.GetModule(_data);
if (namedModule == null)
throw new SerializationException(
- SR.Format(SR.Serialization_UnableToFindModule, m_data, m_assemblyName));
+ SR.Format(SR.Serialization_UnableToFindModule, _data, _assemblyName));
return namedModule;
}
case AssemblyUnity:
{
- if (m_data == null || m_data.Length == 0)
+ if (_data == null || _data.Length == 0)
ThrowInsufficientInformation("Data");
- if (m_assemblyName == null)
+ if (_assemblyName == null)
ThrowInsufficientInformation("AssemblyName");
- assembly = Assembly.Load(m_assemblyName);
+ assembly = Assembly.Load(_assemblyName);
return assembly;
}
throw new ArgumentException(SR.Argument_InvalidUnity);
}
}
- #endregion
+#endregion
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Text;
+using System.Reflection;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace System
+{
+ internal static class MemberSerializationStringGenerator
+ {
+ //
+ // Generate the "Signature2" binary serialization string for PropertyInfos
+ //
+ // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing
+ // metadata prevents generating the string, this method throws a MissingMetadata exception.
+ //
+ public static string SerializationToString(this PropertyInfo property) => ((RuntimePropertyInfo)property).SerializationToString();
+
+ //
+ // Generate the "Signature2" binary serialization string for ConstructorInfos
+ //
+ // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing
+ // metadata prevents generating the string, this method throws a MissingMetadata exception.
+ //
+ public static string SerializationToString(this ConstructorInfo constructor) => ((RuntimeConstructorInfo)constructor).SerializationToString();
+
+ //
+ // Generate the "Signature2" binary serialization string for MethodInfos
+ //
+ // Because the string is effectively a file format for serialized Reflection objects, it must be exactly correct. If missing
+ // metadata prevents generating the string, this method throws a MissingMetadata exception.
+ //
+ public static string SerializationToString(this MethodInfo method) => ((RuntimeMethodInfo)method).SerializationToString();
+ }
+}
if (info == null)
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- MemberInfoSerializationHolder.GetSerializationInfo(
- info,
- Name,
- ReflectedTypeInternal,
- ToString(),
- SerializationToString(),
- MemberTypes.Constructor,
- null);
+ MemberInfoSerializationHolder.GetSerializationInfo(info, this);
}
internal string SerializationToString()
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- MemberInfoSerializationHolder.GetSerializationInfo(
- info,
- Name,
- ReflectedTypeInternal,
- null,
- MemberTypes.Event);
+ MemberInfoSerializationHolder.GetSerializationInfo(info, this);
}
#endregion
if (info == null)
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- MemberInfoSerializationHolder.GetSerializationInfo(
- info,
- Name,
- ReflectedTypeInternal,
- ToString(),
- MemberTypes.Field);
+
+ MemberInfoSerializationHolder.GetSerializationInfo(info, this);
}
#endregion
}
if (m_reflectedTypeCache.IsGlobal)
throw new NotSupportedException(SR.NotSupported_GlobalMethodSerialization);
- MemberInfoSerializationHolder.GetSerializationInfo(
- info,
- Name,
- ReflectedTypeInternal,
- ToString(),
- SerializationToString(),
- MemberTypes.Method,
- IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
+ MemberInfoSerializationHolder.GetSerializationInfo(info, this);
}
internal string SerializationToString()
throw new ArgumentNullException(nameof(info));
Contract.EndContractBlock();
- MemberInfoSerializationHolder.GetSerializationInfo(
- info,
- Name,
- ReflectedTypeInternal,
- ToString(),
- SerializationToString(),
- MemberTypes.Property,
- null);
+ MemberInfoSerializationHolder.GetSerializationInfo(info, this);
}
internal string SerializationToString()