From 90be35920b48820536b8740f64d565ded55d811e Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 28 Jul 2016 07:01:30 -0400 Subject: [PATCH] Move serialization primitives to System.Runtime We need BinaryFormatter to be able to serialize types from coreclr that use the various serialization types (e.g. ISerializable), which means those types must have the same identity as the ones BinaryFormatter recognizes, and we need a bunch of types all across corefx to be able to use these same types to implement serialization. As such, the types are moving down to System.Runtime, and on coreclr, are type-forwarding to the implementations there. There are a few outstanding issues: - SR is not currently available in System.Runtime. The few uses of SR in the versions of the code used for corert have been replaced by hardcoded strings and TODOs. - Debug.Assert is not currently available in System.Runtime. Asserts have been commented out with TODOs. - To get things to build as types are moving around, P2P references are used. --- ...System.Runtime.Serialization.Formatters.cs | 162 +--------------- ...em.Runtime.Serialization.Formatters.csproj | 4 +- ...e.Serialization.Formatters.TypeForwards.cs | 12 ++ ...em.Runtime.Serialization.Formatters.csproj | 18 +- .../Serialization/FormatterServices.cs | 2 - .../Formatters/Binary/BinaryObjectInfo.cs | 4 +- .../Runtime/Serialization/ObjectManager.cs | 13 ++ .../src/System/TemporaryStubs.cs | 6 +- .../tests/BinaryFormatterTests.cs | 2 - .../tests/SerializationInfoTests.cs | 36 +--- ...time.Serialization.Formatters.Tests.csproj | 5 +- .../tests/project.json | 4 +- ...em.Runtime.Serialization.Json.Tests.csproj | 7 +- ...System.Runtime.Serialization.Primitives.cs | 56 +----- ...em.Runtime.Serialization.Primitives.csproj | 1 + ...e.Serialization.Primitives.TypeForwards.cs | 11 ++ ...em.Runtime.Serialization.Primitives.csproj | 1 + .../Serialization/SerializationException.cs | 40 ---- .../Runtime/Serialization/StreamingContext.cs | 77 -------- src/System.Runtime/ref/System.Runtime.cs | 180 ++++++++++++++++++ src/System.Runtime/src/System.Runtime.csproj | 18 ++ .../src/System/NonSerializedAttribute.cs | 1 - .../Serialization/IDeserializationCallback.cs | 0 .../Serialization/IFormatterConverter.cs | 0 .../Runtime/Serialization/IObjectReference.cs | 0 .../Runtime/Serialization/ISerializable.cs | 0 .../Serialization/OnDeserializedAttribute.cs | 4 - .../Serialization/OnDeserializingAttribute.cs | 4 - .../Serialization/OnSerializedAttribute.cs | 4 - .../Serialization/OnSerializingAttribute.cs | 4 - .../Serialization/OptionalFieldAttribute.cs | 2 +- .../Serialization/SerializationException.cs | 23 +++ .../Serialization/SerializationInfo.cs | 44 ++--- .../SerializationInfoEnumerator.cs | 24 +-- .../Runtime/Serialization/StreamingContext.cs | 53 ++++++ .../src/System/SerializableAttribute.cs | 0 36 files changed, 389 insertions(+), 433 deletions(-) create mode 100644 src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.TypeForwards.cs create mode 100644 src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.TypeForwards.cs delete mode 100644 src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/SerializationException.cs delete mode 100644 src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/StreamingContext.cs rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/NonSerializedAttribute.cs (99%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/IDeserializationCallback.cs (100%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/IFormatterConverter.cs (100%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/IObjectReference.cs (100%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/ISerializable.cs (100%) rename src/{System.Runtime.Serialization.Primitives => System.Runtime}/src/System/Runtime/Serialization/OnDeserializedAttribute.cs (82%) rename src/{System.Runtime.Serialization.Primitives => System.Runtime}/src/System/Runtime/Serialization/OnDeserializingAttribute.cs (82%) rename src/{System.Runtime.Serialization.Primitives => System.Runtime}/src/System/Runtime/Serialization/OnSerializedAttribute.cs (82%) rename src/{System.Runtime.Serialization.Primitives => System.Runtime}/src/System/Runtime/Serialization/OnSerializingAttribute.cs (82%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/OptionalFieldAttribute.cs (82%) create mode 100644 src/System.Runtime/src/System/Runtime/Serialization/SerializationException.cs rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/SerializationInfo.cs (89%) rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/Runtime/Serialization/SerializationInfoEnumerator.cs (66%) create mode 100644 src/System.Runtime/src/System/Runtime/Serialization/StreamingContext.cs rename src/{System.Runtime.Serialization.Formatters => System.Runtime}/src/System/SerializableAttribute.cs (100%) diff --git a/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.cs b/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.cs index eb3d74e47db3..7d5b60ded0ce 100644 --- a/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.cs +++ b/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.cs @@ -8,145 +8,15 @@ using System; using System.Collections; -namespace System -{ - [AttributeUsage(AttributeTargets.Field, Inherited = false)] - public sealed class NonSerializedAttribute : Attribute - { - public NonSerializedAttribute() - { - } - } - - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)] - public sealed class SerializableAttribute : Attribute - { - public SerializableAttribute() - { - } - } -} +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.NonSerializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.SerializableAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.IDeserializationCallback))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.IFormatterConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.ISerializable))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationEntry))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationInfo))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationInfoEnumerator))] -namespace System.Runtime.Serialization -{ - public interface IObjectReference - { - object GetRealObject(StreamingContext context); - } - [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited = false)] - public sealed partial class OptionalFieldAttribute : System.Attribute - { - public OptionalFieldAttribute() { } - public int VersionAdded { get { return default(int); } set { } } - } - [CLSCompliant(false)] - public interface IFormatterConverter - { - object Convert(object value, Type type); - object Convert(object value, TypeCode typeCode); - bool ToBoolean(object value); - char ToChar(object value); - [CLSCompliant(false)] - sbyte ToSByte(object value); - byte ToByte(object value); - short ToInt16(object value); - [CLSCompliant(false)] - ushort ToUInt16(object value); - int ToInt32(object value); - [CLSCompliant(false)] - uint ToUInt32(object value); - long ToInt64(object value); - [CLSCompliant(false)] - ulong ToUInt64(object value); - float ToSingle(object value); - double ToDouble(object value); - Decimal ToDecimal(object value); - DateTime ToDateTime(object value); - String ToString(object value); - } - - public interface ISerializable - { - void GetObjectData(SerializationInfo info, StreamingContext context); - } - - public interface IDeserializationCallback - { - void OnDeserialization(object sender); - } - - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public struct SerializationEntry - { - public string Name { get { throw null; } } - public Type ObjectType { get { throw null; } } - public object Value { get { throw null; } } - } - - public sealed class SerializationInfo - { - [CLSCompliant(false)] - public SerializationInfo(Type type, IFormatterConverter converter) { } - public string AssemblyName { get { throw null; } set { } } - public string FullTypeName { get { throw null; } set { } } - public int MemberCount { get { throw null; } } - public Type ObjectType { get { throw null; } } - public void AddValue(string name, bool value) { } - public void AddValue(string name, byte value) { } - public void AddValue(string name, char value) { } - public void AddValue(string name, DateTime value) { } - public void AddValue(string name, decimal value) { } - public void AddValue(string name, double value) { } - public void AddValue(string name, short value) { } - public void AddValue(string name, int value) { } - public void AddValue(string name, long value) { } - public void AddValue(string name, object value) { } - public void AddValue(string name, object value, Type type) { } - [CLSCompliant(false)] - public void AddValue(string name, sbyte value) { } - public void AddValue(string name, float value) { } - [CLSCompliant(false)] - public void AddValue(string name, ushort value) { } - [CLSCompliant(false)] - public void AddValue(string name, uint value) { } - [CLSCompliant(false)] - public void AddValue(string name, ulong value) { } - public bool GetBoolean(string name) { throw null; } - public byte GetByte(string name) { throw null; } - public char GetChar(string name) { throw null; } - public DateTime GetDateTime(string name) { throw null; } - public decimal GetDecimal(string name) { throw null; } - public double GetDouble(string name) { throw null; } - public SerializationInfoEnumerator GetEnumerator() { throw null; } - public short GetInt16(string name) { throw null; } - public int GetInt32(string name) { throw null; } - public long GetInt64(string name) { throw null; } - [CLSCompliant(false)] - public sbyte GetSByte(string name) { throw null; } - public float GetSingle(string name) { throw null; } - public string GetString(string name) { throw null; } - [CLSCompliant(false)] - public ushort GetUInt16(string name) { throw null; } - [CLSCompliant(false)] - public uint GetUInt32(string name) { throw null; } - [CLSCompliant(false)] - public ulong GetUInt64(string name) { throw null; } - public object GetValue(string name, Type type) { throw null; } - public void SetType(Type type) { } - } - - public sealed class SerializationInfoEnumerator : IEnumerator - { - private SerializationInfoEnumerator() { } - public SerializationEntry Current { get { throw null; } } - public string Name { get { throw null; } } - public Type ObjectType { get { throw null; } } - object System.Collections.IEnumerator.Current { get { throw null; } } - public object Value { get { throw null; } } - public bool MoveNext() { throw null; } - public void Reset() { throw null; } - } -} namespace System.Runtime.Serialization { [System.CLSCompliantAttribute(false)] @@ -248,22 +118,6 @@ public ObjectIDGenerator() { } public virtual long GetId(object obj, out bool firstTime) { firstTime = default(bool); return default(long); } public virtual long HasId(object obj, out bool firstTime) { firstTime = default(bool); return default(long); } } - public partial class ObjectManager - { - public ObjectManager(System.Runtime.Serialization.ISurrogateSelector selector, System.Runtime.Serialization.StreamingContext context) { } - public virtual void DoFixups() { } - public virtual object GetObject(long objectID) { return default(object); } - public virtual void RaiseDeserializationEvent() { } - public void RaiseOnDeserializingEvent(object obj) { } - public virtual void RecordArrayElementFixup(long arrayToBeFixed, int index, long objectRequired) { } - public virtual void RecordArrayElementFixup(long arrayToBeFixed, int[] indices, long objectRequired) { } - public virtual void RecordDelayedFixup(long objectToBeFixed, string memberName, long objectRequired) { } - public virtual void RecordFixup(long objectToBeFixed, System.Reflection.MemberInfo member, long objectRequired) { } - public virtual void RegisterObject(object obj, long objectID) { } - public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo info) { } - public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo info, long idOfContainingObj, System.Reflection.MemberInfo member) { } - public void RegisterObject(object obj, long objectID, System.Runtime.Serialization.SerializationInfo info, long idOfContainingObj, System.Reflection.MemberInfo member, int[] arrayIndex) { } - } public abstract partial class SerializationBinder { protected SerializationBinder() { } diff --git a/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.csproj b/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.csproj index a661650f13b7..e69f49721c69 100644 --- a/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.csproj +++ b/src/System.Runtime.Serialization.Formatters/ref/System.Runtime.Serialization.Formatters.csproj @@ -4,7 +4,7 @@ 4.0.1.0 Library - netstandard1.3 + netstandard1.5 .NETStandard,Version=v1.3 @@ -12,6 +12,8 @@ + + \ No newline at end of file diff --git a/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.TypeForwards.cs b/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.TypeForwards.cs new file mode 100644 index 000000000000..3d8a59b1f91b --- /dev/null +++ b/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.TypeForwards.cs @@ -0,0 +1,12 @@ +// 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. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.NonSerializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.SerializableAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.IDeserializationCallback))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.IFormatterConverter))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.ISerializable))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationEntry))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationInfo))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationInfoEnumerator))] diff --git a/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.csproj b/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.csproj index 021342f09eba..009126b2fcd6 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.csproj +++ b/src/System.Runtime.Serialization.Formatters/src/System.Runtime.Serialization.Formatters.csproj @@ -15,31 +15,26 @@ - - + + - - - - - - - + + @@ -69,9 +64,8 @@ - - - + + diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/FormatterServices.cs b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/FormatterServices.cs index 400afb132b20..1e3a8b2a795c 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/FormatterServices.cs +++ b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/FormatterServices.cs @@ -86,8 +86,6 @@ public static object GetUninitializedObject(Type type) public static object GetSafeUninitializedObject(Type type) => GetUninitializedObject(type); - internal static bool UnsafeTypeForwardersIsEnabled() => true; - internal static void SerializationSetValue(MemberInfo fi, object target, object value) { Debug.Assert(fi != null); diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs index 7265ee7b93ed..32413fb9e4fd 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs +++ b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/Formatters/Binary/BinaryObjectInfo.cs @@ -105,7 +105,7 @@ internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, St { throw new SerializationException(SR.Format(SR.Serialization_NonSerType, _objectType.FullName, _objectType.GetTypeInfo().Assembly.FullName)); } - _si = new SerializationInfo(_objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); + _si = new SerializationInfo(_objectType, converter); ((ISerializable)obj).GetObjectData(_si, context); InitSiWrite(); CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString); @@ -154,7 +154,7 @@ internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelecto } else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType)) { - _si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled()); + _si = new SerializationInfo(objectType, converter); _cache = new SerObjectInfoCache(objectType); CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString); _isSi = true; diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs index a5e8c53da275..3c2831893469 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs +++ b/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ObjectManager.cs @@ -1624,4 +1624,17 @@ internal TypeLoadExceptionHolder(string typeName) internal string TypeName { get; } } + + // TODO: Temporary workaround. Remove this once SerializationInfo.UpdateValue is exposed + // from coreclr for use by ObjectManager. + internal static class SerializationInfoExtensions + { + private static readonly Action s_updateValue = + (Action)typeof(SerializationInfo) + .GetMethod("UpdateValue", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .CreateDelegate(typeof(Action)); + + public static void UpdateValue(this SerializationInfo si, string name, object value, Type type) => + s_updateValue(si, name, value, type); + } } diff --git a/src/System.Runtime.Serialization.Formatters/src/System/TemporaryStubs.cs b/src/System.Runtime.Serialization.Formatters/src/System/TemporaryStubs.cs index 186b4c7d6d04..201274f7094b 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/TemporaryStubs.cs +++ b/src/System.Runtime.Serialization.Formatters/src/System/TemporaryStubs.cs @@ -6,11 +6,6 @@ namespace System { - internal interface ICloneable // TODO: Replace with real ICloneable when it's available - { - object Clone(); - } - internal class MarshalByRefObject { } // TODO: Replace with real MarshalByRefObject when it's available internal sealed class TypedReference // TODO: Replace with System.TypedReference when available and functional @@ -47,6 +42,7 @@ namespace System.Reflection { internal static class CustomReflectionExtensions { + // TODO: Replace with FieldInfo.SetValueDirect when available and functional internal static void SetValueDirect(this FieldInfo field, TypedReference obj, object value) // TODO: Replace with FieldInfo.SetValueDirect when available { if (field == null) diff --git a/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs b/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs index 5ee6950cf657..bc60428c04e7 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs +++ b/src/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs @@ -58,7 +58,6 @@ public static IEnumerable SerializableObjects() yield return (StructWithIntField?)new StructWithIntField() { X = 42 }; // Other core serializable types - yield return DateTime.Now; yield return TimeSpan.FromDays(7); yield return new Version(1, 2, 3, 4); yield return Tuple.Create(1, "2", Tuple.Create(3.4)); @@ -192,7 +191,6 @@ public static IEnumerable NonSerializableObjects() yield return new object[] { 1, 2, 3, new NonSerializableClass() }; // TODO: Move these to the serializable category when enabled in the runtime - yield return DateTimeOffset.Now; var e = new OperationCanceledException(); yield return e; try { throw e; } catch { } yield return e; diff --git a/src/System.Runtime.Serialization.Formatters/tests/SerializationInfoTests.cs b/src/System.Runtime.Serialization.Formatters/tests/SerializationInfoTests.cs index e19c7257ed6f..7509f743f478 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/SerializationInfoTests.cs +++ b/src/System.Runtime.Serialization.Formatters/tests/SerializationInfoTests.cs @@ -78,42 +78,17 @@ public void SerializationInfoEnumerate() public void NegativeAddValueTwice() { var si = new SerializationInfo(typeof(Serializable), new FormatterConverter()); - Assert.Throws(() => - { - si.AddValue("bool", true); - si.AddValue("bool", true); - }); - - try - { - si.AddValue("bool", false); - } - catch (Exception e) - { - Assert.Equal("Cannot add the same member twice to a SerializationInfo object.", e.Message); - } + si.AddValue("bool", true); + Assert.Throws(() => si.AddValue("bool", true)); } + [ActiveIssue("https://github.com/dotnet/coreclr/pull/6423")] [Fact] public void NegativeValueNotFound() { var si = new SerializationInfo(typeof(Serializable), new FormatterConverter()); - Assert.Throws(() => - { - si.AddValue("a", 1); - si.GetInt32("b"); - }); - - si = new SerializationInfo(typeof(Serializable), new FormatterConverter()); - try - { - si.AddValue("a", 1); - si.GetInt32("b"); - } - catch (Exception e) - { - Assert.Equal("Member 'b' was not found.", e.Message); - } + si.AddValue("a", 1); + Assert.Throws(() => si.GetInt32("b")); } } @@ -125,7 +100,6 @@ public void GetObjectData(SerializationInfo info, StreamingContext context) info.AddValue("string", "hello"); info.AddValue("bool", true); info.AddValue("char", 'a'); - info.AddValue("byte", byte.MaxValue); info.AddValue("decimal", decimal.MaxValue); info.AddValue("double", double.MaxValue); diff --git a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index 07539de658e3..62ee8d5cf2f5 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -9,7 +9,7 @@ System.Runtime.Serialization.Formatters.Tests System.Runtime.Serialization.Formatters.Tests true - .NETStandard,Version=v1.3 + .NETStandard,Version=v1.5 @@ -35,6 +35,9 @@ + + + {69e46a6f-9966-45a5-8945-2559fe337827} RemoteExecutorConsoleApp diff --git a/src/System.Runtime.Serialization.Formatters/tests/project.json b/src/System.Runtime.Serialization.Formatters/tests/project.json index 845c7bcd35c8..7978614db05b 100644 --- a/src/System.Runtime.Serialization.Formatters/tests/project.json +++ b/src/System.Runtime.Serialization.Formatters/tests/project.json @@ -21,12 +21,10 @@ "Microsoft.DotNet.xunit.performance": "1.0.0-alpha-build0037" }, "frameworks": { - "netstandard1.3": {} + "netstandard1.5": {} }, "supports": { "coreFx.Test.netcoreapp1.0": {}, - "coreFx.Test.net46": {}, - "coreFx.Test.net461": {}, "coreFx.Test.net462": {}, "coreFx.Test.net463": {} } diff --git a/src/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj b/src/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj index 867a9feb7efb..c327a21caf38 100644 --- a/src/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj +++ b/src/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj @@ -10,7 +10,7 @@ System.Runtime.Serialization.Json.Tests System.Runtime.Serialization.Json.Tests {701CB3BC-00DC-435D-BDE4-C5FC29A708A7} - .NETStandard,Version=v1.3 + .NETStandard,Version=v1.5 Performance/project.json @@ -30,6 +30,11 @@ System.Private.DataContractSerialization true + + {D62A6082-5229-4845-8BE9-75753E08C65A} + System.Xml.XmlSerializer + + diff --git a/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.cs b/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.cs index 40d345f99995..c8417af3b6be 100644 --- a/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.cs +++ b/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.cs @@ -5,6 +5,13 @@ // Changes to this file must follow the http://aka.ms/api-review process. // ------------------------------------------------------------------------------ +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnDeserializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnDeserializingAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnSerializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnSerializingAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationException))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.StreamingContext))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.StreamingContextStates))] namespace System.Runtime.Serialization { @@ -85,53 +92,4 @@ public KnownTypeAttribute(System.Type type) { } public string MethodName { get { return default(string); } } public System.Type Type { get { return default(System.Type); } } } - [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] - public sealed partial class OnDeserializedAttribute : System.Attribute - { - public OnDeserializedAttribute() { } - } - [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] - public sealed partial class OnDeserializingAttribute : System.Attribute - { - public OnDeserializingAttribute() { } - } - [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] - public sealed partial class OnSerializedAttribute : System.Attribute - { - public OnSerializedAttribute() { } - } - [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] - public sealed partial class OnSerializingAttribute : System.Attribute - { - public OnSerializingAttribute() { } - } - public partial class SerializationException : System.Exception - { - public SerializationException() { } - public SerializationException(string message) { } - public SerializationException(string message, System.Exception innerException) { } - } - [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public partial struct StreamingContext - { - public StreamingContext(System.Runtime.Serialization.StreamingContextStates state) { } - public StreamingContext(System.Runtime.Serialization.StreamingContextStates state, object additional) { } - public override bool Equals(object obj) { return default(bool); } - public override int GetHashCode() { return default(int); } - public System.Runtime.Serialization.StreamingContextStates State { get { return default(System.Runtime.Serialization.StreamingContextStates); } } - public object Context { get { return default(object); } } - } - [Flags] - public enum StreamingContextStates - { - CrossProcess = 0x01, - CrossMachine = 0x02, - File = 0x04, - Persistence = 0x08, - Remoting = 0x10, - Other = 0x20, - Clone = 0x40, - CrossAppDomain = 0x80, - All = 0xFF, - } } diff --git a/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.csproj b/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.csproj index 4428867d45ad..010299c808df 100644 --- a/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.csproj +++ b/src/System.Runtime.Serialization.Primitives/ref/System.Runtime.Serialization.Primitives.csproj @@ -12,6 +12,7 @@ + \ No newline at end of file diff --git a/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.TypeForwards.cs b/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.TypeForwards.cs new file mode 100644 index 000000000000..541225471325 --- /dev/null +++ b/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.TypeForwards.cs @@ -0,0 +1,11 @@ +// 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. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnDeserializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnDeserializingAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnSerializedAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.OnSerializingAttribute))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.SerializationException))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.StreamingContext))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Runtime.Serialization.StreamingContextStates))] diff --git a/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.csproj b/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.csproj index 67e59d383438..5aa4833f1fdd 100644 --- a/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.csproj +++ b/src/System.Runtime.Serialization.Primitives/src/System.Runtime.Serialization.Primitives.csproj @@ -23,6 +23,7 @@ + diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/SerializationException.cs b/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/SerializationException.cs deleted file mode 100644 index 680259da2bfc..000000000000 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/SerializationException.cs +++ /dev/null @@ -1,40 +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: Thrown when something goes wrong during serialization or -** deserialization. -** -** -=============================================================================*/ - -using System; - -namespace System.Runtime.Serialization -{ - public class SerializationException : Exception - { - private static string s_nullMessage = SR.SerializationException; - - // Creates a new SerializationException with its message - // string set to a default message. - public SerializationException() - : base(s_nullMessage) - { - } - - public SerializationException(string message) - : base(message) - { - } - - public SerializationException(string message, Exception innerException) - : base(message, innerException) - { - } - } -} diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/StreamingContext.cs b/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/StreamingContext.cs deleted file mode 100644 index a10a2aace3dc..000000000000 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/StreamingContext.cs +++ /dev/null @@ -1,77 +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. - -/*============================================================ -** -** ValueType: StreamingContext -** -** -** Purpose: A value type indicating the source or destination of our streaming. -** -** -===========================================================*/ - -using System; - -namespace System.Runtime.Serialization -{ - public struct StreamingContext - { - internal Object m_additionalContext; - internal StreamingContextStates m_state; - - public StreamingContext(StreamingContextStates state) - : this(state, null) - { - } - - public StreamingContext(StreamingContextStates state, Object additional) - { - m_state = state; - m_additionalContext = additional; - } - - public Object Context - { - get { return m_additionalContext; } - } - - public override bool Equals(Object obj) - { - if (!(obj is StreamingContext)) - { - return false; - } - StreamingContext ctx = (StreamingContext)obj; - return ctx.m_additionalContext == m_additionalContext && ctx.m_state == m_state; - } - - public override int GetHashCode() - { - return (int)m_state; - } - - public StreamingContextStates State - { - get { return m_state; } - } - } - - // ********************************************************** - // Keep these in sync with the version in vm\runtimehandles.h - // ********************************************************** - [Flags] - public enum StreamingContextStates - { - CrossProcess = 0x01, - CrossMachine = 0x02, - File = 0x04, - Persistence = 0x08, - Remoting = 0x10, - Other = 0x20, - Clone = 0x40, - CrossAppDomain = 0x80, - All = 0xFF, - } -} diff --git a/src/System.Runtime/ref/System.Runtime.cs b/src/System.Runtime/ref/System.Runtime.cs index 61955718c56e..607344a338e3 100644 --- a/src/System.Runtime/ref/System.Runtime.cs +++ b/src/System.Runtime/ref/System.Runtime.cs @@ -1377,6 +1377,13 @@ internal MulticastDelegate() { } public static bool operator ==(System.MulticastDelegate d1, System.MulticastDelegate d2) { return default(bool); } public static bool operator !=(System.MulticastDelegate d1, System.MulticastDelegate d2) { return default(bool); } } + [AttributeUsage(AttributeTargets.Field, Inherited = false)] + public sealed class NonSerializedAttribute : Attribute + { + public NonSerializedAttribute() + { + } + } public partial class NotImplementedException : System.Exception { public NotImplementedException() { } @@ -1547,6 +1554,13 @@ public partial struct SByte : System.IComparable, System.IComparable, Sys [System.CLSCompliantAttribute(false)] public static bool TryParse(string s, out sbyte result) { result = default(sbyte); return default(bool); } } + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)] + public sealed class SerializableAttribute : Attribute + { + public SerializableAttribute() + { + } + } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public partial struct Single : System.IComparable, System.IComparable, System.IConvertible, System.IEquatable, System.IFormattable { @@ -3490,6 +3504,172 @@ public StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind layoutKin public System.Runtime.InteropServices.LayoutKind Value { get { return default(System.Runtime.InteropServices.LayoutKind); } } } } +namespace System.Runtime.Serialization +{ + public interface IDeserializationCallback + { + void OnDeserialization(object sender); + } + [CLSCompliant(false)] + public interface IFormatterConverter + { + object Convert(object value, Type type); + object Convert(object value, TypeCode typeCode); + bool ToBoolean(object value); + char ToChar(object value); + [CLSCompliant(false)] + sbyte ToSByte(object value); + byte ToByte(object value); + short ToInt16(object value); + [CLSCompliant(false)] + ushort ToUInt16(object value); + int ToInt32(object value); + [CLSCompliant(false)] + uint ToUInt32(object value); + long ToInt64(object value); + [CLSCompliant(false)] + ulong ToUInt64(object value); + float ToSingle(object value); + double ToDouble(object value); + Decimal ToDecimal(object value); + DateTime ToDateTime(object value); + String ToString(object value); + } + public interface IObjectReference + { + object GetRealObject(StreamingContext context); + } + public interface ISerializable + { + void GetObjectData(SerializationInfo info, StreamingContext context); + } + [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] + public sealed partial class OnDeserializedAttribute : System.Attribute + { + public OnDeserializedAttribute() { } + } + [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] + public sealed partial class OnDeserializingAttribute : System.Attribute + { + public OnDeserializingAttribute() { } + } + [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] + public sealed partial class OnSerializedAttribute : System.Attribute + { + public OnSerializedAttribute() { } + } + [System.AttributeUsageAttribute((System.AttributeTargets)(64), Inherited = false)] + public sealed partial class OnSerializingAttribute : System.Attribute + { + public OnSerializingAttribute() { } + } + [System.AttributeUsageAttribute(System.AttributeTargets.Field, Inherited = false)] + public sealed partial class OptionalFieldAttribute : System.Attribute + { + public OptionalFieldAttribute() { } + public int VersionAdded { get { return default(int); } set { } } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public struct SerializationEntry + { + public string Name { get { throw null; } } + public Type ObjectType { get { throw null; } } + public object Value { get { throw null; } } + } + public partial class SerializationException : System.Exception + { + public SerializationException() { } + public SerializationException(string message) { } + public SerializationException(string message, System.Exception innerException) { } + } + public sealed class SerializationInfo + { + [CLSCompliant(false)] + public SerializationInfo(Type type, IFormatterConverter converter) { } + public string AssemblyName { get { throw null; } set { } } + public string FullTypeName { get { throw null; } set { } } + public int MemberCount { get { throw null; } } + public Type ObjectType { get { throw null; } } + public bool IsFullTypeNameSetExplicit { get { throw null; } } + public bool IsAssemblyNameSetExplicit { get { throw null; } } + public void AddValue(string name, bool value) { } + public void AddValue(string name, byte value) { } + public void AddValue(string name, char value) { } + public void AddValue(string name, DateTime value) { } + public void AddValue(string name, decimal value) { } + public void AddValue(string name, double value) { } + public void AddValue(string name, short value) { } + public void AddValue(string name, int value) { } + public void AddValue(string name, long value) { } + public void AddValue(string name, object value) { } + public void AddValue(string name, object value, Type type) { } + [CLSCompliant(false)] + public void AddValue(string name, sbyte value) { } + public void AddValue(string name, float value) { } + [CLSCompliant(false)] + public void AddValue(string name, ushort value) { } + [CLSCompliant(false)] + public void AddValue(string name, uint value) { } + [CLSCompliant(false)] + public void AddValue(string name, ulong value) { } + public bool GetBoolean(string name) { throw null; } + public byte GetByte(string name) { throw null; } + public char GetChar(string name) { throw null; } + public DateTime GetDateTime(string name) { throw null; } + public decimal GetDecimal(string name) { throw null; } + public double GetDouble(string name) { throw null; } + public SerializationInfoEnumerator GetEnumerator() { throw null; } + public short GetInt16(string name) { throw null; } + public int GetInt32(string name) { throw null; } + public long GetInt64(string name) { throw null; } + [CLSCompliant(false)] + public sbyte GetSByte(string name) { throw null; } + public float GetSingle(string name) { throw null; } + public string GetString(string name) { throw null; } + [CLSCompliant(false)] + public ushort GetUInt16(string name) { throw null; } + [CLSCompliant(false)] + public uint GetUInt32(string name) { throw null; } + [CLSCompliant(false)] + public ulong GetUInt64(string name) { throw null; } + public object GetValue(string name, Type type) { throw null; } + public void SetType(Type type) { } + } + public sealed class SerializationInfoEnumerator : System.Collections.IEnumerator + { + private SerializationInfoEnumerator() { } + public SerializationEntry Current { get { throw null; } } + public string Name { get { throw null; } } + public Type ObjectType { get { throw null; } } + object System.Collections.IEnumerator.Current { get { throw null; } } + public object Value { get { throw null; } } + public bool MoveNext() { throw null; } + public void Reset() { throw null; } + } + [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] + public partial struct StreamingContext + { + public StreamingContext(System.Runtime.Serialization.StreamingContextStates state) { } + public StreamingContext(System.Runtime.Serialization.StreamingContextStates state, object additional) { } + public override bool Equals(object obj) { return default(bool); } + public override int GetHashCode() { return default(int); } + public System.Runtime.Serialization.StreamingContextStates State { get { return default(System.Runtime.Serialization.StreamingContextStates); } } + public object Context { get { return default(object); } } + } + [Flags] + public enum StreamingContextStates + { + CrossProcess = 0x01, + CrossMachine = 0x02, + File = 0x04, + Persistence = 0x08, + Remoting = 0x10, + Other = 0x20, + Clone = 0x40, + CrossAppDomain = 0x80, + All = 0xFF, + } +} namespace System.Runtime.Versioning { [System.AttributeUsageAttribute((System.AttributeTargets)(1), AllowMultiple = false, Inherited = false)] diff --git a/src/System.Runtime/src/System.Runtime.csproj b/src/System.Runtime/src/System.Runtime.csproj index 9aab543efbab..50527efca67b 100644 --- a/src/System.Runtime/src/System.Runtime.csproj +++ b/src/System.Runtime/src/System.Runtime.csproj @@ -10,6 +10,7 @@ true netstandard1.7 .NETStandard,Version=v1.7 + 0436 @@ -36,6 +37,23 @@ + + + + + + + + + + + + + + + + + Windows_NT diff --git a/src/System.Runtime.Serialization.Formatters/src/System/NonSerializedAttribute.cs b/src/System.Runtime/src/System/NonSerializedAttribute.cs similarity index 99% rename from src/System.Runtime.Serialization.Formatters/src/System/NonSerializedAttribute.cs rename to src/System.Runtime/src/System/NonSerializedAttribute.cs index b65789c14ebe..8fe484e5b9c5 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/NonSerializedAttribute.cs +++ b/src/System.Runtime/src/System/NonSerializedAttribute.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - namespace System { [AttributeUsage(AttributeTargets.Field, Inherited = false)] diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IDeserializationCallback.cs b/src/System.Runtime/src/System/Runtime/Serialization/IDeserializationCallback.cs similarity index 100% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IDeserializationCallback.cs rename to src/System.Runtime/src/System/Runtime/Serialization/IDeserializationCallback.cs diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IFormatterConverter.cs b/src/System.Runtime/src/System/Runtime/Serialization/IFormatterConverter.cs similarity index 100% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IFormatterConverter.cs rename to src/System.Runtime/src/System/Runtime/Serialization/IFormatterConverter.cs diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IObjectReference.cs b/src/System.Runtime/src/System/Runtime/Serialization/IObjectReference.cs similarity index 100% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/IObjectReference.cs rename to src/System.Runtime/src/System/Runtime/Serialization/IObjectReference.cs diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ISerializable.cs b/src/System.Runtime/src/System/Runtime/Serialization/ISerializable.cs similarity index 100% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/ISerializable.cs rename to src/System.Runtime/src/System/Runtime/Serialization/ISerializable.cs diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializedAttribute.cs b/src/System.Runtime/src/System/Runtime/Serialization/OnDeserializedAttribute.cs similarity index 82% rename from src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializedAttribute.cs rename to src/System.Runtime/src/System/Runtime/Serialization/OnDeserializedAttribute.cs index 2ecdafbc50ef..408a55ccf9e9 100644 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializedAttribute.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/OnDeserializedAttribute.cs @@ -2,10 +2,6 @@ // 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; - namespace System.Runtime.Serialization { [AttributeUsage(AttributeTargets.Method, Inherited = false)] diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializingAttribute.cs b/src/System.Runtime/src/System/Runtime/Serialization/OnDeserializingAttribute.cs similarity index 82% rename from src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializingAttribute.cs rename to src/System.Runtime/src/System/Runtime/Serialization/OnDeserializingAttribute.cs index fcd7267e04fd..162857e8d3b8 100644 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnDeserializingAttribute.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/OnDeserializingAttribute.cs @@ -2,10 +2,6 @@ // 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; - namespace System.Runtime.Serialization { [AttributeUsage(AttributeTargets.Method, Inherited = false)] diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializedAttribute.cs b/src/System.Runtime/src/System/Runtime/Serialization/OnSerializedAttribute.cs similarity index 82% rename from src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializedAttribute.cs rename to src/System.Runtime/src/System/Runtime/Serialization/OnSerializedAttribute.cs index 3312c18d6240..020dd0257cac 100644 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializedAttribute.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/OnSerializedAttribute.cs @@ -2,10 +2,6 @@ // 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; - namespace System.Runtime.Serialization { [AttributeUsage(AttributeTargets.Method, Inherited = false)] diff --git a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializingAttribute.cs b/src/System.Runtime/src/System/Runtime/Serialization/OnSerializingAttribute.cs similarity index 82% rename from src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializingAttribute.cs rename to src/System.Runtime/src/System/Runtime/Serialization/OnSerializingAttribute.cs index f750c37daa78..8dc8af3f2356 100644 --- a/src/System.Runtime.Serialization.Primitives/src/System/Runtime/Serialization/OnSerializingAttribute.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/OnSerializingAttribute.cs @@ -2,10 +2,6 @@ // 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; - namespace System.Runtime.Serialization { [AttributeUsage(AttributeTargets.Method, Inherited = false)] diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/OptionalFieldAttribute.cs b/src/System.Runtime/src/System/Runtime/Serialization/OptionalFieldAttribute.cs similarity index 82% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/OptionalFieldAttribute.cs rename to src/System.Runtime/src/System/Runtime/Serialization/OptionalFieldAttribute.cs index 84daa539be2c..5f22ee669a3c 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/OptionalFieldAttribute.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/OptionalFieldAttribute.cs @@ -16,7 +16,7 @@ public int VersionAdded { if (value < 1) { - throw new ArgumentException(SR.Serialization_OptionalFieldVersionValue); + throw new ArgumentException("Version value must be positive."); // TODO: SR.Serialization_OptionalFieldVersionValue); } _versionAdded = value; } diff --git a/src/System.Runtime/src/System/Runtime/Serialization/SerializationException.cs b/src/System.Runtime/src/System/Runtime/Serialization/SerializationException.cs new file mode 100644 index 000000000000..d03fac679330 --- /dev/null +++ b/src/System.Runtime/src/System/Runtime/Serialization/SerializationException.cs @@ -0,0 +1,23 @@ +// 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. + +namespace System.Runtime.Serialization +{ + public class SerializationException : Exception + { + private static string s_nullMessage = "Serialization error."; // TODO: SR.SerializationException; + + public SerializationException() : base(s_nullMessage) + { + } + + public SerializationException(string message) : base(message) + { + } + + public SerializationException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationInfo.cs b/src/System.Runtime/src/System/Runtime/Serialization/SerializationInfo.cs similarity index 89% rename from src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationInfo.cs rename to src/System.Runtime/src/System/Runtime/Serialization/SerializationInfo.cs index 35facef50f7d..0546660410ea 100644 --- a/src/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationInfo.cs +++ b/src/System.Runtime/src/System/Runtime/Serialization/SerializationInfo.cs @@ -3,9 +3,10 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; +// TODO: Put back asserts once Debug.Assert is available + namespace System.Runtime.Serialization { public sealed class SerializationInfo @@ -24,8 +25,6 @@ public sealed class SerializationInfo private string _rootTypeName; private string _rootTypeAssemblyName; private Type _rootType; - internal bool IsFullTypeNameSetExplicit; - internal bool IsAssemblyNameSetExplicit; [CLSCompliant(false)] public SerializationInfo(Type type, IFormatterConverter converter) @@ -50,11 +49,6 @@ public SerializationInfo(Type type, IFormatterConverter converter) _converter = converter; } - internal SerializationInfo(Type type, IFormatterConverter converter, bool requireSameTokenInPartialTrust) : - this(type, converter) - { - } - public string FullTypeName { get { return _rootTypeName; } @@ -85,6 +79,10 @@ public string AssemblyName } } + public bool IsFullTypeNameSetExplicit { get; private set; } + + public bool IsAssemblyNameSetExplicit { get; private set; } + public void SetType(Type type) { if (type == null) @@ -111,7 +109,7 @@ public void SetType(Type type) private void ExpandArrays() { int newSize; - Debug.Assert(_names.Length == _count); + // Debug.Assert(_names.Length == _count); newSize = (_count * 2); @@ -141,9 +139,9 @@ private void ExpandArrays() internal void UpdateValue(string name, object value, Type type) { - Debug.Assert(null != name, "[SerializationInfo.UpdateValue]name!=null"); - Debug.Assert(null != value, "[SerializationInfo.UpdateValue]value!=null"); - Debug.Assert(null != type, "[SerializationInfo.UpdateValue]type!=null"); + //Debug.Assert(null != name, "[SerializationInfo.UpdateValue]name!=null"); + //Debug.Assert(null != value, "[SerializationInfo.UpdateValue]value!=null"); + //Debug.Assert(null != type, "[SerializationInfo.UpdateValue]type!=null"); int index = FindElement(name); if (index < 0) @@ -262,7 +260,7 @@ internal void AddValueInternal(string name, object value, Type type) { if (_nameToIndex.ContainsKey(name)) { - throw new SerializationException(SR.Serialization_SameNameTwice); + throw new SerializationException("Cannot add the same member twice to a SerializationInfo object."); // TODO: SR.Serialization_SameNameTwice); } _nameToIndex.Add(name, _count); @@ -295,14 +293,14 @@ private object GetElement(string name, out Type foundType) int index = FindElement(name); if (index == -1) { - throw new SerializationException(SR.Format(SR.Serialization_NotFound, name)); + throw new SerializationException(string.Format("Member '{0}' was not found.", name)); // TODO: SR.Format(SR.Serialization_NotFound, name)); } - Debug.Assert(index < _values.Length); - Debug.Assert(index < _types.Length); + //Debug.Assert(index < _values.Length); + //Debug.Assert(index < _types.Length); foundType = _types[index]; - Debug.Assert(foundType != null); + //Debug.Assert(foundType != null); return _values[index]; } @@ -315,11 +313,11 @@ private object GetElementNoThrow(string name, out Type foundType) return null; } - Debug.Assert(index < _values.Length, "[SerializationInfo.GetElement]index= 0, "[SerializationInfoEnumerator.ctor]numItems>=0"); - Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems"); - Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems"); - Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems"); + // TODO: Put back asserts once Debug.Assert is available + //Debug.Assert(members != null, "[SerializationInfoEnumerator.ctor]members!=null"); + //Debug.Assert(info != null, "[SerializationInfoEnumerator.ctor]info!=null"); + //Debug.Assert(types != null, "[SerializationInfoEnumerator.ctor]types!=null"); + //Debug.Assert(numItems >= 0, "[SerializationInfoEnumerator.ctor]numItems>=0"); + //Debug.Assert(members.Length >= numItems, "[SerializationInfoEnumerator.ctor]members.Length>=numItems"); + //Debug.Assert(info.Length >= numItems, "[SerializationInfoEnumerator.ctor]info.Length>=numItems"); + //Debug.Assert(types.Length >= numItems, "[SerializationInfoEnumerator.ctor]types.Length>=numItems"); _members = members; _data = info; @@ -78,7 +78,7 @@ public SerializationEntry Current { if (_current == false) { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + throw new InvalidOperationException("Enumeration has either not started or has already finished."); // TODO: SR.InvalidOperation_EnumOpCantHappen); } return new SerializationEntry(_members[_currItem], _data[_currItem], _types[_currItem]); } @@ -96,7 +96,7 @@ public string Name { if (_current == false) { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + throw new InvalidOperationException("Enumeration has either not started or has already finished."); // TODO: SR.InvalidOperation_EnumOpCantHappen); } return _members[_currItem]; } @@ -107,7 +107,7 @@ public object Value { if (_current == false) { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + throw new InvalidOperationException("Enumeration has either not started or has already finished."); // TODO: SR.InvalidOperation_EnumOpCantHappen); } return _data[_currItem]; } @@ -118,7 +118,7 @@ public Type ObjectType { if (_current == false) { - throw new InvalidOperationException(SR.InvalidOperation_EnumOpCantHappen); + throw new InvalidOperationException("Enumeration has either not started or has already finished."); // TODO: SR.InvalidOperation_EnumOpCantHappen); } return _types[_currItem]; } diff --git a/src/System.Runtime/src/System/Runtime/Serialization/StreamingContext.cs b/src/System.Runtime/src/System/Runtime/Serialization/StreamingContext.cs new file mode 100644 index 000000000000..98a622fc6844 --- /dev/null +++ b/src/System.Runtime/src/System/Runtime/Serialization/StreamingContext.cs @@ -0,0 +1,53 @@ +// 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. + +namespace System.Runtime.Serialization +{ + public struct StreamingContext + { + private readonly object _additionalContext; + private readonly StreamingContextStates _state; + + public StreamingContext(StreamingContextStates state) : this(state, null) + { + } + + public StreamingContext(StreamingContextStates state, object additional) + { + _state = state; + _additionalContext = additional; + } + + public override bool Equals(object obj) + { + if (!(obj is StreamingContext)) + { + return false; + } + StreamingContext ctx = (StreamingContext)obj; + return ctx._additionalContext == _additionalContext && ctx._state == _state; + } + + public override int GetHashCode() => (int)_state; + + public StreamingContextStates State => _state; + + public object Context => _additionalContext; + } + + // Keep these in sync with the version in vm\runtimehandles.h + [Flags] + public enum StreamingContextStates + { + CrossProcess = 0x01, + CrossMachine = 0x02, + File = 0x04, + Persistence = 0x08, + Remoting = 0x10, + Other = 0x20, + Clone = 0x40, + CrossAppDomain = 0x80, + All = 0xFF, + } +} diff --git a/src/System.Runtime.Serialization.Formatters/src/System/SerializableAttribute.cs b/src/System.Runtime/src/System/SerializableAttribute.cs similarity index 100% rename from src/System.Runtime.Serialization.Formatters/src/System/SerializableAttribute.cs rename to src/System.Runtime/src/System/SerializableAttribute.cs