From 4b11dc566a5bbfa1378d6266525c281b028abcc8 Mon Sep 17 00:00:00 2001 From: Jiyoung Yun Date: Fri, 10 Feb 2017 20:35:12 +0900 Subject: Imported Upstream version 1.0.0.9910 --- .../Runtime/Serialization/FormatterConverter.cs | 3 +- .../Runtime/Serialization/FormatterServices.cs | 480 --------------------- .../Serialization/IDeserializationCallback.cs | 1 - .../src/System/Runtime/Serialization/IFormatter.cs | 41 -- .../Runtime/Serialization/IFormatterConverter.cs | 1 - .../Runtime/Serialization/IObjectReference.cs | 2 - .../System/Runtime/Serialization/ISerializable.cs | 2 - .../Serialization/ISerializationSurrogate.cs | 34 -- .../Runtime/Serialization/ISurrogateSelector.cs | 34 -- .../System/Runtime/Serialization/MemberHolder.cs | 51 --- .../Serialization/SafeSerializationManager.cs | 210 +-------- .../Serialization/SerializationAttributes.cs | 5 - .../Runtime/Serialization/SerializationBinder.cs | 29 -- .../Serialization/SerializationException.cs | 1 - .../Serialization/SerializationFieldInfo.cs | 136 ------ .../Runtime/Serialization/SerializationInfo.cs | 59 --- .../Serialization/SerializationInfoEnumerator.cs | 2 - .../Runtime/Serialization/StreamingContext.cs | 2 - 18 files changed, 3 insertions(+), 1090 deletions(-) delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/IFormatter.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/ISerializationSurrogate.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/ISurrogateSelector.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/MemberHolder.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/SerializationBinder.cs delete mode 100644 src/mscorlib/src/System/Runtime/Serialization/SerializationFieldInfo.cs (limited to 'src/mscorlib/src/System/Runtime/Serialization') diff --git a/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs b/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs index b710ed0b3a..27f7ecf9d2 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/FormatterConverter.cs @@ -17,8 +17,7 @@ namespace System.Runtime.Serialization { using System.Globalization; using System.Diagnostics.Contracts; -[System.Runtime.InteropServices.ComVisible(true)] - public class FormatterConverter : IFormatterConverter { + internal class FormatterConverter : IFormatterConverter { public FormatterConverter() { } diff --git a/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs b/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs index 27c3f15136..c3f9eb4452 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/FormatterServices.cs @@ -18,10 +18,6 @@ namespace System.Runtime.Serialization { using System.Collections; using System.Collections.Generic; using System.Security; - using System.Security.Permissions; -#if FEATURE_SERIALIZATION - using System.Runtime.Serialization.Formatters; -#endif using System.Runtime.Remoting; using System.Runtime.CompilerServices; using System.Runtime.Versioning; @@ -32,211 +28,7 @@ namespace System.Runtime.Serialization { using System.Diagnostics; using System.Diagnostics.Contracts; - [System.Runtime.InteropServices.ComVisible(true)] public static class FormatterServices { -#if FEATURE_SERIALIZATION - internal static Dictionary m_MemberInfoTable = new Dictionary(32); - private static bool unsafeTypeForwardersIsEnabled = false; - - private static volatile bool unsafeTypeForwardersIsEnabledInitialized = false; - - private static Object s_FormatterServicesSyncObject = null; - - private static Object formatterServicesSyncObject - { - get - { - if (s_FormatterServicesSyncObject == null) - { - Object o = new Object(); - Interlocked.CompareExchange(ref s_FormatterServicesSyncObject, o, null); - } - return s_FormatterServicesSyncObject; - } - } - - static FormatterServices() - { - // Static initialization touches security critical types, so we need an - // explicit static constructor to allow us to mark it safe critical. - } - - private static MemberInfo[] GetSerializableMembers(RuntimeType type) { - // get the list of all fields - FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - int countProper = 0; - for (int i = 0; i < fields.Length; i++) { - if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized) - continue; - countProper++; - } - if (countProper != fields.Length) { - FieldInfo[] properFields = new FieldInfo[countProper]; - countProper = 0; - for (int i = 0; i < fields.Length; i++) { - if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized) - continue; - properFields[countProper] = fields[i]; - countProper++; - } - return properFields; - } - else - return fields; - } - - private static bool CheckSerializable(RuntimeType type) { - if (type.IsSerializable) { - return true; - } - return false; - } - - private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type) { - List allMembers = null; - MemberInfo[] typeMembers; - FieldInfo [] typeFields; - RuntimeType parentType; - - Debug.Assert((object)type != null, "[GetAllSerializableMembers]type!=null"); - - if (type.IsInterface) { - return new MemberInfo[0]; - } - - if (!(CheckSerializable(type))) { - throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", type.FullName, type.Module.Assembly.FullName)); - } - - //Get all of the serializable members in the class to be serialized. - typeMembers = GetSerializableMembers(type); - - //If this class doesn't extend directly from object, walk its hierarchy and - //get all of the private and assembly-access fields (e.g. all fields that aren't - //virtual) and include them in the list of things to be serialized. - parentType = (RuntimeType)(type.BaseType); - if (parentType != null && parentType != (RuntimeType)typeof(Object)) { - RuntimeType[] parentTypes = null; - int parentTypeCount = 0; - bool classNamesUnique = GetParentTypes(parentType, out parentTypes, out parentTypeCount); - if (parentTypeCount > 0){ - allMembers = new List(); - for (int i = 0; i < parentTypeCount;i++){ - parentType = parentTypes[i]; - if (!CheckSerializable(parentType)) { - throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", parentType.FullName, parentType.Module.Assembly.FullName)); - } - - typeFields = parentType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); - String typeName = classNamesUnique ? parentType.Name : parentType.FullName; - foreach (FieldInfo field in typeFields) { - // Family and Assembly fields will be gathered by the type itself. - if (!field.IsNotSerialized) { - allMembers.Add(new SerializationFieldInfo((RuntimeFieldInfo)field, typeName)); - } - } - } - //If we actually found any new MemberInfo's, we need to create a new MemberInfo array and - //copy all of the members which we've found so far into that. - if (allMembers!=null && allMembers.Count>0) { - MemberInfo[] membersTemp = new MemberInfo[allMembers.Count + typeMembers.Length]; - Array.Copy(typeMembers, membersTemp, typeMembers.Length); - ((ICollection)allMembers).CopyTo(membersTemp, typeMembers.Length); - typeMembers = membersTemp; - } - } - } - return typeMembers; - } - - private static bool GetParentTypes(RuntimeType parentType, out RuntimeType[] parentTypes, out int parentTypeCount){ - //Check if there are any dup class names. Then we need to include as part of - //typeName to prefix the Field names in SerializationFieldInfo - /*out*/ parentTypes = null; - /*out*/ parentTypeCount = 0; - bool unique = true; - RuntimeType objectType = (RuntimeType)typeof(object); - for (RuntimeType t1 = parentType; t1 != objectType; t1 = (RuntimeType)t1.BaseType) - { - if (t1.IsInterface) continue; - string t1Name = t1.Name; - for(int i=0;unique && i 0) { - hasTypeForwardedFrom = true; - TypeForwardedFromAttribute typeForwardedFromAttribute = (TypeForwardedFromAttribute)typeAttributes[0]; - return typeForwardedFromAttribute.AssemblyFullName; - } - else { - hasTypeForwardedFrom = false; - return type.Assembly.FullName; - } - } - - internal static string GetClrTypeFullName(Type type) { - if (type.IsArray) { - return GetClrTypeFullNameForArray(type); - } - else { - return GetClrTypeFullNameForNonArrayTypes(type); - } - } - - static string GetClrTypeFullNameForArray(Type type) { - int rank = type.GetArrayRank(); - if (rank == 1) - { - return String.Format(CultureInfo.InvariantCulture, "{0}{1}", GetClrTypeFullName(type.GetElementType()), "[]"); - } - else - { - StringBuilder builder = new StringBuilder(GetClrTypeFullName(type.GetElementType())).Append("["); - for (int commaIndex = 1; commaIndex < rank; commaIndex++) - { - builder.Append(","); - } - builder.Append("]"); - return builder.ToString(); - } - } - - static string GetClrTypeFullNameForNonArrayTypes(Type type) { - if (!type.IsGenericType) { - return type.FullName; - } - - Type[] genericArguments = type.GetGenericArguments(); - StringBuilder builder = new StringBuilder(type.GetGenericTypeDefinition().FullName).Append("["); - bool hasTypeForwardedFrom; - - foreach (Type genericArgument in genericArguments) { - builder.Append("[").Append(GetClrTypeFullName(genericArgument)).Append(", "); - builder.Append(GetClrAssemblyName(genericArgument, out hasTypeForwardedFrom)).Append("],"); - } - - //remove the last comma and close typename for generic with a close bracket - return builder.Remove(builder.Length - 1, 1).Append("]").ToString(); - } - } - - internal sealed class SurrogateForCyclicalReference : ISerializationSurrogate - { - ISerializationSurrogate innerSurrogate; - internal SurrogateForCyclicalReference(ISerializationSurrogate innerSurrogate) - { - if (innerSurrogate == null) - throw new ArgumentNullException(nameof(innerSurrogate)); - this.innerSurrogate = innerSurrogate; - } - - public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) - { - innerSurrogate.GetObjectData(obj, info, context); - } - - public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) - { - return innerSurrogate.SetObjectData(obj, info, context, selector); - } } } diff --git a/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs b/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs index e2497e5d34..2911a4016e 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/IDeserializationCallback.cs @@ -16,7 +16,6 @@ namespace System.Runtime.Serialization { using System; // Interface does not need to be marked with the serializable attribute - [System.Runtime.InteropServices.ComVisible(true)] public interface IDeserializationCallback { void OnDeserialization(Object sender); } diff --git a/src/mscorlib/src/System/Runtime/Serialization/IFormatter.cs b/src/mscorlib/src/System/Runtime/Serialization/IFormatter.cs deleted file mode 100644 index 8d91d95acf..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/IFormatter.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -/*============================================================ -** -** Interface: IFormatter; -** -** -** Purpose: The interface for all formatters. -** -** -===========================================================*/ -namespace System.Runtime.Serialization { - using System.Runtime.Remoting; - using System; - using System.IO; - -[System.Runtime.InteropServices.ComVisible(true)] - public interface IFormatter { - Object Deserialize(Stream serializationStream); - - void Serialize(Stream serializationStream, Object graph); - - - ISurrogateSelector SurrogateSelector { - get; - set; - } - - SerializationBinder Binder { - get; - set; - } - - StreamingContext Context { - get; - set; - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/IFormatterConverter.cs b/src/mscorlib/src/System/Runtime/Serialization/IFormatterConverter.cs index 182cc93412..0be0db9acd 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/IFormatterConverter.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/IFormatterConverter.cs @@ -17,7 +17,6 @@ namespace System.Runtime.Serialization { using System; [CLSCompliant(false)] -[System.Runtime.InteropServices.ComVisible(true)] public interface IFormatterConverter { Object Convert(Object value, Type type); Object Convert(Object value, TypeCode typeCode); diff --git a/src/mscorlib/src/System/Runtime/Serialization/IObjectReference.cs b/src/mscorlib/src/System/Runtime/Serialization/IObjectReference.cs index 42662a10f6..ef5ee6ade0 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/IObjectReference.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/IObjectReference.cs @@ -18,9 +18,7 @@ namespace System.Runtime.Serialization { using System; - using System.Security.Permissions; // Interface does not need to be marked with the serializable attribute -[System.Runtime.InteropServices.ComVisible(true)] public interface IObjectReference { Object GetRealObject(StreamingContext context); } diff --git a/src/mscorlib/src/System/Runtime/Serialization/ISerializable.cs b/src/mscorlib/src/System/Runtime/Serialization/ISerializable.cs index fc283d41f1..816aa0484b 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/ISerializable.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/ISerializable.cs @@ -16,11 +16,9 @@ namespace System.Runtime.Serialization { using System.Runtime.Remoting; using System.Runtime.Serialization; - using System.Security.Permissions; using System; using System.Reflection; - [System.Runtime.InteropServices.ComVisible(true)] public interface ISerializable { void GetObjectData(SerializationInfo info, StreamingContext context); } diff --git a/src/mscorlib/src/System/Runtime/Serialization/ISerializationSurrogate.cs b/src/mscorlib/src/System/Runtime/Serialization/ISerializationSurrogate.cs deleted file mode 100644 index 226bbdcc75..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/ISerializationSurrogate.cs +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -/*============================================================ -** -** Interface: ISurrogate -** -** -** Purpose: The interface implemented by an object which -** supports surrogates. -** -** -===========================================================*/ -namespace System.Runtime.Serialization { - using System.Runtime.Remoting; - using System.Runtime.Serialization; - using System.Security.Permissions; - using System; - using System.Reflection; -[System.Runtime.InteropServices.ComVisible(true)] - public interface ISerializationSurrogate { - // Interface does not need to be marked with the serializable attribute - // Returns a SerializationInfo completely populated with all of the data needed to reinstantiate the - // the object at the other end of serialization. - // - void GetObjectData(Object obj, SerializationInfo info, StreamingContext context); - - // Reinflate the object using all of the information in data. The information in - // members is used to find the particular field or property which needs to be set. - // - Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector); - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/ISurrogateSelector.cs b/src/mscorlib/src/System/Runtime/Serialization/ISurrogateSelector.cs deleted file mode 100644 index 87b7845894..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/ISurrogateSelector.cs +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -/*============================================================ -** -** Interface: ISurrogateSelector -** -** -** Purpose: A user-supplied class for doing the type to surrogate -** mapping. -** -** -===========================================================*/ -namespace System.Runtime.Serialization { - - using System.Runtime.Remoting; - using System.Security.Permissions; - using System; -[System.Runtime.InteropServices.ComVisible(true)] - public interface ISurrogateSelector { - // Interface does not need to be marked with the serializable attribute - // Specifies the next ISurrogateSelector to be examined for surrogates if the current - // instance doesn't have a surrogate for the given type and assembly in the given context. - void ChainSelector(ISurrogateSelector selector); - - // Returns the appropriate surrogate for the given type in the given context. - ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector); - - - // Return the next surrogate in the chain. Returns null if no more exist. - ISurrogateSelector GetNextSelector(); - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/MemberHolder.cs b/src/mscorlib/src/System/Runtime/Serialization/MemberHolder.cs deleted file mode 100644 index 1303e40c27..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/MemberHolder.cs +++ /dev/null @@ -1,51 +0,0 @@ -// 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. - -/*============================================================ -** -** -** -** Purpose: This is a lightweight class designed to hold the members -** and StreamingContext for a particular class. -** -** -============================================================*/ -namespace System.Runtime.Serialization { - - using System.Runtime.Remoting; - using System; - using System.Reflection; - [Serializable] - internal class MemberHolder { -// disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - internal MemberInfo[] members = null; -#pragma warning restore 0414 - internal Type memberType; - internal StreamingContext context; - - internal MemberHolder(Type type, StreamingContext ctx) { - memberType = type; - context = ctx; - } - - public override int GetHashCode() { - return memberType.GetHashCode(); - } - - public override bool Equals(Object obj) { - if (!(obj is MemberHolder)) { - return false; - } - - MemberHolder temp = (MemberHolder)obj; - - if (Object.ReferenceEquals(temp.memberType, memberType) && temp.context.State == context.State) { - return true; - } - - return false; - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs b/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs index 585d367605..260e873bc7 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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; @@ -211,10 +211,7 @@ namespace System.Runtime.Serialization private StreamingContext m_streamingContext; private List m_serializedStates = new List(); - internal SafeSerializationEventArgs(StreamingContext streamingContext) - { - m_streamingContext = streamingContext; - } + internal SafeSerializationEventArgs() {} public void AddSerializedState(ISafeSerializationData serializedState) { @@ -226,11 +223,6 @@ namespace System.Runtime.Serialization m_serializedStates.Add(serializedState); } - internal IList SerializedStates - { - get { return m_serializedStates; } - } - public StreamingContext StreamingContext { get { return m_streamingContext; } @@ -245,202 +237,4 @@ namespace System.Runtime.Serialization // this object. void CompleteDeserialization(object deserialized); } -#if FEATURE_SERIALIZATION - // Helper class to implement safe serialization. Concrete ISerializable types which want to allow - // transparent subclasses code to participate in serialization should contain an instance of - // SafeSerializationManager and wire up to it as described in code:#SafeSerialization. - [Serializable] - internal sealed class SafeSerializationManager : IObjectReference, ISerializable - { - // Saved states to store in the serialization stream. This is typed as object rather than - // ISafeSerializationData because ISafeSerializationData can't be marked serializable. - private IList m_serializedStates; - - // This is the SerializationInfo that is used when the SafeSerializationManager type has replaced - // itself as the target of serialziation. It is not used directly by the safe serialization code, - // but just held onto so that the real object being deserialzed can use it later. - private SerializationInfo m_savedSerializationInfo; - - // Real object that we've deserialized - this is stored when we complete construction and calling - // the deserialization .ctors on it and is used when we need to notify the stored safe - // deserialization data that they should populate the object with their fields. - private object m_realObject; - - // Real type that should be deserialized - private RuntimeType m_realType; - - // Event fired when we need to collect state to serialize into the parent object - internal event EventHandler SerializeObjectState; - - // Name that is used to store the real type being deserialized in the main SerializationInfo - private const string RealTypeSerializationName = "CLR_SafeSerializationManager_RealType"; - - internal SafeSerializationManager() - { - } - - private SafeSerializationManager(SerializationInfo info, StreamingContext context) - { - // We need to determine if we're being called to really deserialize a SafeSerializationManager, - // or if we're being called because we've intercepted the deserialization callback for the real - // object being deserialized. We use the presence of the RealTypeSerializationName field in the - // serialization info to indicate that this is the interception callback and we just need to - // safe the info. If that field is not present, then we should be in a real deserialization - // construction. - RuntimeType realType = info.GetValueNoThrow(RealTypeSerializationName, typeof(RuntimeType)) as RuntimeType; - - if (realType == null) - { - m_serializedStates = info.GetValue("m_serializedStates", typeof(List)) as List; - } - else - { - m_realType = realType; - m_savedSerializationInfo = info; - } - } - - // Determine if the serialization manager is in an active state - that is if any code is hooked up - // to use it for serialization - internal bool IsActive - { - get { return SerializeObjectState != null; } - } - - // CompleteSerialization is called by the base ISerializable in its GetObjectData method. It is - // responsible for gathering up the serialized object state of any delegates that wish to add their - // own state to the serialized object. - internal void CompleteSerialization(object serializedObject, - SerializationInfo info, - StreamingContext context) - { - Contract.Requires(serializedObject != null); - Contract.Requires(info != null); - Contract.Requires(typeof(ISerializable).IsAssignableFrom(serializedObject.GetType())); - Contract.Requires(serializedObject.GetType().IsAssignableFrom(info.ObjectType)); - - // Clear out any stale state - m_serializedStates = null; - - // We only want to kick in our special serialization sauce if someone wants to participate in - // it, otherwise if we have no delegates registered there's no reason for us to get in the way - // of the regular serialization machinery. - EventHandler serializeObjectStateEvent = SerializeObjectState; - if (serializeObjectStateEvent != null) - { - // Get any extra data to add to our serialization state now - SafeSerializationEventArgs eventArgs = new SafeSerializationEventArgs(context); - serializeObjectStateEvent(serializedObject, eventArgs); - m_serializedStates = eventArgs.SerializedStates; - - // Replace the type to be deserialized by the standard serialization code paths with - // ourselves, which allows us to control the deserialization process. - info.AddValue(RealTypeSerializationName, serializedObject.GetType(), typeof(RuntimeType)); - info.SetType(typeof(SafeSerializationManager)); - } - } - - // CompleteDeserialization is called by the base ISerializable object's OnDeserialized handler to - // finish the deserialization of the object by notifying the saved states that they should - // re-populate their portions of the deserialized object. - internal void CompleteDeserialization(object deserializedObject) - { - Contract.Requires(deserializedObject != null); - - if (m_serializedStates != null) - { - foreach (ISafeSerializationData serializedState in m_serializedStates) - { - serializedState.CompleteDeserialization(deserializedObject); - } - } - } - - void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) - { - info.AddValue("m_serializedStates", m_serializedStates, typeof(List)); - } - - // GetRealObject intercepts the deserialization process in order to allow deserializing part of the - // object's inheritance heirarchy using standard ISerializable constructors, and the remaining - // portion using the saved serialization states. - object IObjectReference.GetRealObject(StreamingContext context) - { - // If we've already deserialized the real object, use that rather than deserializing it again - if (m_realObject != null) - { - return m_realObject; - } - - // If we don't have a real type to deserialize, then this is really a SafeSerializationManager - // and we don't need to rebuild the object that we're standing in for. - if (m_realType == null) - { - return this; - } - - // Look for the last type in GetRealType's inheritance hierarchy which implements a critical - // deserialization constructor. This will be the object that we use as the deserialization - // construction type to initialize via standard ISerializable semantics - - // First build up the chain starting at the type below Object and working to the real type we - // serialized. - Stack inheritanceChain = new Stack(); - RuntimeType currentType = m_realType; - do - { - inheritanceChain.Push(currentType); - currentType = currentType.BaseType as RuntimeType; - } - while (currentType != typeof(object)); - - // Now look for the first type that does not implement the ISerializable .ctor. When we find - // that, previousType will point at the last type that did implement the .ctor. We require that - // the .ctor we invoke also be non-transparent - RuntimeConstructorInfo serializationCtor = null; - RuntimeType previousType = null; - do - { - previousType = currentType; - currentType = inheritanceChain.Pop() as RuntimeType; - serializationCtor = currentType.GetSerializationCtor(); - } - while (serializationCtor != null && serializationCtor.IsSecurityCritical); - - // previousType is the last type that did implement the deserialization .ctor before the first - // type that did not, so we'll grab it's .ctor to use for deserialization. - BCLDebug.Assert(previousType != null, "We should have at least one inheritance from the base type"); - serializationCtor = ObjectManager.GetConstructor(previousType); - - // Allocate an instance of the final type and run the selected .ctor on that instance to get the - // standard ISerializable initialization done. - object deserialized = FormatterServices.GetUninitializedObject(m_realType); - serializationCtor.SerializationInvoke(deserialized, m_savedSerializationInfo, context); - m_savedSerializationInfo = null; - m_realType = null; - - // Save away the real object that was deserialized so that we can fill it in later, and return - // it back as the object that should result from the final deserialization. - m_realObject = deserialized; - return deserialized; - } - - [OnDeserialized] - private void OnDeserialized(StreamingContext context) - { - // We only need to complete deserialization if we were hooking the deserialization process. If - // we have not deserialized an object in the GetRealObject call, then there's nothing more for - // us to do here. - if (m_realObject != null) - { - // Fire the real object's OnDeserialized method if they registered one. Since we replaced - // ourselves as the target of the deserialization, OnDeserialized on the target won't - // automatically get triggered unless we do it manually. - SerializationEvents cache = SerializationEventsCache.GetSerializationEventsForType(m_realObject.GetType()); - cache.InvokeOnDeserialized(m_realObject, context); - m_realObject = null; - } - } - } -#endif } diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs index 27c5751cc6..38abffa66e 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SerializationAttributes.cs @@ -17,7 +17,6 @@ namespace System.Runtime.Serialization using System.Reflection; [AttributeUsage(AttributeTargets.Field, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] public sealed class OptionalFieldAttribute : Attribute { int versionAdded = 1; @@ -38,25 +37,21 @@ namespace System.Runtime.Serialization } [AttributeUsage(AttributeTargets.Method, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] public sealed class OnSerializingAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] public sealed class OnSerializedAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] public sealed class OnDeserializingAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method, Inherited=false)] -[System.Runtime.InteropServices.ComVisible(true)] public sealed class OnDeserializedAttribute : Attribute { } diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationBinder.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationBinder.cs deleted file mode 100644 index 7457991008..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationBinder.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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. - -/*============================================================ -** -** Interface: SerializationBinder -** -** -** Purpose: The base class of serialization binders. -** -** -===========================================================*/ -namespace System.Runtime.Serialization { - using System; - - [Serializable] -[System.Runtime.InteropServices.ComVisible(true)] - public abstract class SerializationBinder { - - public virtual void BindToName(Type serializedType, out String assemblyName, out String typeName) - { - assemblyName = null; - typeName = null; - } - - public abstract Type BindToType(String assemblyName, String typeName); - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs index b88ccfd706..e9cb79b7af 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SerializationException.cs @@ -17,7 +17,6 @@ namespace System.Runtime.Serialization { using System; using System.Runtime.Serialization; - [System.Runtime.InteropServices.ComVisible(true)] [Serializable] public class SerializationException : SystemException { diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationFieldInfo.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationFieldInfo.cs deleted file mode 100644 index 82536ce3b4..0000000000 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationFieldInfo.cs +++ /dev/null @@ -1,136 +0,0 @@ -// 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. - -/*============================================================ -** -** -** -** Purpose: Provides a methods of representing imaginary fields -** which are unique to serialization. In this case, what we're -** representing is the private members of parent classes. We -** aggregate the RuntimeFieldInfo associated with this member -** and return a managled form of the name. The name that we -** return is .parentname.fieldname -** -** -============================================================*/ - -namespace System.Runtime.Serialization { - - using System; - using System.Reflection; - using System.Globalization; - using System.Diagnostics; - using System.Diagnostics.Contracts; - using System.Threading; - - internal sealed class SerializationFieldInfo : FieldInfo { - - internal const String FakeNameSeparatorString = "+"; - - private RuntimeFieldInfo m_field; - private String m_serializationName; - - public override Module Module { get { return m_field.Module; } } - public override int MetadataToken { get { return m_field.MetadataToken; } } - - internal SerializationFieldInfo(RuntimeFieldInfo field, String namePrefix) { - Debug.Assert(field!=null, "[SerializationFieldInfo.ctor]field!=null"); - Debug.Assert(namePrefix!=null, "[SerializationFieldInfo.ctor]namePrefix!=null"); - - m_field = field; - m_serializationName = String.Concat(namePrefix, FakeNameSeparatorString, m_field.Name); - } - - // - // MemberInfo methods - // - public override String Name { - get { - return m_serializationName; - } - } - - public override Type DeclaringType { - get { - return m_field.DeclaringType; - } - } - - public override Type ReflectedType { - get { - return m_field.ReflectedType; - } - } - - public override Object[] GetCustomAttributes(bool inherit) { - return m_field.GetCustomAttributes(inherit); - } - - public override Object[] GetCustomAttributes(Type attributeType, bool inherit) { - return m_field.GetCustomAttributes(attributeType, inherit); - } - - public override bool IsDefined(Type attributeType, bool inherit) { - return m_field.IsDefined(attributeType, inherit); - } - - // - // FieldInfo methods - // - public override Type FieldType { - get { - return m_field.FieldType; - } - } - - public override Object GetValue(Object obj) { - return m_field.GetValue(obj); - } - - internal Object InternalGetValue(Object obj) { - RtFieldInfo field = m_field as RtFieldInfo; - if (field != null) - { - field.CheckConsistency(obj); - return field.UnsafeGetValue(obj); - } - else - return m_field.GetValue(obj); - } - - public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) { - m_field.SetValue(obj, value, invokeAttr, binder, culture); - } - - internal void InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) { - RtFieldInfo field = m_field as RtFieldInfo; - if (field != null) - { - field.CheckConsistency(obj); - field.UnsafeSetValue(obj, value, invokeAttr, binder, culture); - } - else - m_field.SetValue(obj, value, invokeAttr, binder, culture); - } - - internal RuntimeFieldInfo FieldInfo { - get { - return m_field; - } - } - - public override RuntimeFieldHandle FieldHandle { - get { - return m_field.FieldHandle; - } - } - - public override FieldAttributes Attributes { - get { - return m_field.Attributes; - } - } - } -} diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs index 55909c85fd..45521f2397 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfo.cs @@ -24,7 +24,6 @@ namespace System.Runtime.Serialization using System.Security; using System.Runtime.CompilerServices; - [System.Runtime.InteropServices.ComVisible(true)] public sealed class SerializationInfo { private const int defaultSize = 4; @@ -146,49 +145,10 @@ namespace System.Runtime.Serialization } } - private static bool Compare(byte[] a, byte[] b) - { - // if either or both assemblies do not have public key token, we should demand, hence, returning false will force a demand - if (a == null || b == null || a.Length == 0 || b.Length == 0 || a.Length != b.Length) - { - return false; - } - else - { - for (int i = 0; i < a.Length; i++) - { - if (a[i] != b[i]) return false; - } - - return true; - } - } - internal static void DemandForUnsafeAssemblyNameAssignments(string originalAssemblyName, string newAssemblyName) { } - internal static bool IsAssemblyNameAssignmentSafe(string originalAssemblyName, string newAssemblyName) - { - if (originalAssemblyName == newAssemblyName) - { - return true; - } - - AssemblyName originalAssembly = new AssemblyName(originalAssemblyName); - AssemblyName newAssembly = new AssemblyName(newAssemblyName); - - // mscorlib will get loaded by the runtime regardless of its string casing or its public key token, - // so setting the assembly name to mscorlib must always be protected by a demand - if (string.Equals(newAssembly.Name, s_mscorlibAssemblySimpleName, StringComparison.OrdinalIgnoreCase) || - string.Equals(newAssembly.Name, s_mscorlibFileName, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - - return Compare(originalAssembly.GetPublicKeyToken(), newAssembly.GetPublicKeyToken()); - } - public int MemberCount { get @@ -467,7 +427,6 @@ namespace System.Runtime.Serialization return m_data[index]; } - [System.Runtime.InteropServices.ComVisible(true)] private Object GetElementNoThrow(String name, out Type foundType) { int index = FindElement(name); @@ -518,7 +477,6 @@ namespace System.Runtime.Serialization return m_converter.Convert(value, type); } - [System.Runtime.InteropServices.ComVisible(true)] internal Object GetValueNoThrow(String name, Type type) { Type foundType; @@ -741,22 +699,5 @@ namespace System.Runtime.Serialization return m_converter.ToString(value); } - internal string[] MemberNames - { - get - { - return m_members; - } - - } - - internal object[] MemberValues - { - get - { - return m_data; - } - } - } } diff --git a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs index 32c65492e1..0858dfc19f 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs @@ -21,7 +21,6 @@ namespace System.Runtime.Serialization { // // The tuple returned by SerializationInfoEnumerator.Current. // -[System.Runtime.InteropServices.ComVisible(true)] public struct SerializationEntry { private Type m_type; private Object m_value; @@ -57,7 +56,6 @@ namespace System.Runtime.Serialization { // This does not snapshot the values, it just keeps pointers to the // member variables of the SerializationInfo that created it. // -[System.Runtime.InteropServices.ComVisible(true)] public sealed class SerializationInfoEnumerator : IEnumerator { String[] m_members; Object[] m_data; diff --git a/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs b/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs index ef4a096a51..c01a3edc4f 100644 --- a/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs +++ b/src/mscorlib/src/System/Runtime/Serialization/StreamingContext.cs @@ -16,7 +16,6 @@ namespace System.Runtime.Serialization { using System.Runtime.Remoting; using System; [Serializable] -[System.Runtime.InteropServices.ComVisible(true)] public struct StreamingContext { internal Object m_additionalContext; internal StreamingContextStates m_state; @@ -59,7 +58,6 @@ namespace System.Runtime.Serialization { // ********************************************************** [Serializable] [Flags] -[System.Runtime.InteropServices.ComVisible(true)] public enum StreamingContextStates { CrossProcess=0x01, CrossMachine=0x02, -- cgit v1.2.3