From: Atsushi Kanamori Date: Thu, 23 Mar 2017 18:49:42 +0000 (-0700) Subject: Migrate the Reflection serialization holders to the shared partition. (dotnet/coreclr... X-Git-Tag: submit/tizen/20210909.063632~11030^2~7585 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=42bb091087c77c59ab1cb64105d26ea5585ee738;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Migrate the Reflection serialization holders to the shared partition. (dotnet/coreclr#10429) * String => string, SR.GetResourceString() => SR. * Copy over CoreRT files verbatim. * Get things building and running again. * Don't bring CoreRT's visibility sins into CoreCLR * String => string, Object => object * De-"m_" the field names. * Move the files to the shared directory. Commit migrated from https://github.com/dotnet/coreclr/commit/0b9b922e7a4197e478adb354189eab508a475410 --- diff --git a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj index ca6e4d1..29f247e 100644 --- a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj @@ -408,7 +408,6 @@ - @@ -470,7 +469,7 @@ - + diff --git a/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index 6d07579..f72f599 100644 --- a/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -162,6 +162,7 @@ + @@ -226,6 +227,7 @@ + diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/MemberInfoSerializationHolder.cs similarity index 58% rename from src/coreclr/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs rename to src/coreclr/src/mscorlib/shared/System/Reflection/MemberInfoSerializationHolder.cs index a487f68..dfc5666 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/MemberInfoSerializationHolder.cs +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/MemberInfoSerializationHolder.cs @@ -2,10 +2,7 @@ // 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; @@ -13,20 +10,54 @@ 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) { @@ -34,83 +65,84 @@ namespace System.Reflection 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]; } @@ -119,10 +151,10 @@ namespace System.Reflection #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]; } @@ -131,10 +163,10 @@ namespace System.Reflection #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]; @@ -143,30 +175,30 @@ namespace System.Reflection { 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]; @@ -175,20 +207,20 @@ namespace System.Reflection { 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 @@ -197,12 +229,12 @@ namespace System.Reflection { 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]; @@ -211,9 +243,9 @@ namespace System.Reflection { 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; @@ -221,7 +253,7 @@ namespace System.Reflection } else { - if (methods[i].ToString().Equals(m_signature)) + if (methods[i].ToString().Equals(_signature)) { methodInfo = methods[i]; break; @@ -236,9 +268,9 @@ namespace System.Reflection { 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; @@ -246,7 +278,7 @@ namespace System.Reflection } else { - if (candidateMethod.ToString().Equals(m_signature)) + if (candidateMethod.ToString().Equals(_signature)) { methodInfo = candidateMethod; break; @@ -258,7 +290,7 @@ namespace System.Reflection } 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; @@ -280,3 +312,4 @@ namespace System.Reflection #endregion } } + diff --git a/src/coreclr/src/mscorlib/src/System/UnitySerializationHolder.cs b/src/coreclr/src/mscorlib/shared/System/UnitySerializationHolder.cs similarity index 60% rename from src/coreclr/src/mscorlib/src/System/UnitySerializationHolder.cs rename to src/coreclr/src/mscorlib/shared/System/UnitySerializationHolder.cs index 943e8ce..f195798 100644 --- a/src/coreclr/src/mscorlib/src/System/UnitySerializationHolder.cs +++ b/src/coreclr/src/mscorlib/shared/System/UnitySerializationHolder.cs @@ -3,7 +3,6 @@ // 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; @@ -15,15 +14,20 @@ namespace System { [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; @@ -31,16 +35,16 @@ namespace System 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 elementTypes = new List(); while (type.HasElementType) @@ -63,7 +67,7 @@ namespace System elementTypes.Add(ByRef); } - type = (RuntimeType)type.GetElementType(); + type = type.GetElementType(); } info.AddValue("ElementTypes", elementTypes.ToArray(), typeof(int[])); @@ -73,21 +77,21 @@ namespace System 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(); } @@ -96,9 +100,15 @@ namespace System 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)); @@ -118,14 +128,14 @@ namespace System 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 @@ -133,14 +143,14 @@ namespace System // 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 { @@ -149,78 +159,78 @@ namespace System 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: { @@ -239,73 +249,73 @@ namespace System 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; } @@ -314,43 +324,6 @@ namespace System throw new ArgumentException(SR.Argument_InvalidUnity); } } - #endregion +#endregion } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs b/src/coreclr/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs new file mode 100644 index 0000000..d25c746 --- /dev/null +++ b/src/coreclr/src/mscorlib/src/System/Reflection/MemberSerializationStringGenerator.cs @@ -0,0 +1,39 @@ +// 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(); + } +} diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs index c2601ae..8c3b1fc 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeConstructorInfo.cs @@ -468,14 +468,7 @@ namespace System.Reflection 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() diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs index ba356e2..e2faf83 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeEventInfo.cs @@ -162,12 +162,7 @@ namespace System.Reflection throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); - MemberInfoSerializationHolder.GetSerializationInfo( - info, - Name, - ReflectedTypeInternal, - null, - MemberTypes.Event); + MemberInfoSerializationHolder.GetSerializationInfo(info, this); } #endregion diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs index cab7a4a..29cc97d 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeFieldInfo.cs @@ -128,12 +128,8 @@ namespace System.Reflection if (info == null) throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); - MemberInfoSerializationHolder.GetSerializationInfo( - info, - Name, - ReflectedTypeInternal, - ToString(), - MemberTypes.Field); + + MemberInfoSerializationHolder.GetSerializationInfo(info, this); } #endregion } diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs index 73298d3..372d4f8 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimeMethodInfo.cs @@ -779,14 +779,7 @@ namespace System.Reflection 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() diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs index fe4ffbf..b6a4792 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/RuntimePropertyInfo.cs @@ -455,14 +455,7 @@ namespace System.Reflection throw new ArgumentNullException(nameof(info)); Contract.EndContractBlock(); - MemberInfoSerializationHolder.GetSerializationInfo( - info, - Name, - ReflectedTypeInternal, - ToString(), - SerializationToString(), - MemberTypes.Property, - null); + MemberInfoSerializationHolder.GetSerializationInfo(info, this); } internal string SerializationToString()