This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3dfbf5
commit db966f6
Showing
3 changed files
with
67 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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.Runtime.Serialization; | ||
using System.Reflection; | ||
using System.Diagnostics.Contracts; | ||
|
||
namespace System | ||
{ | ||
// Holds classes (Empty, Null, Missing) for which we guarantee that there is only ever one instance of. | ||
#if CORECLR | ||
internal | ||
#else | ||
public // On CoreRT, this must be public because of the Reflection.Core/CoreLib divide and the need to whitelist past the ReflectionBlock. | ||
#endif | ||
class UnitySerializationHolder : ISerializable, IObjectReference | ||
{ | ||
internal const int NullUnity = 0x0002; | ||
const string DataName = "Data"; | ||
const string UnityTypeName = "UnityType"; | ||
const string AssemblyNameName = "AssemblyName"; | ||
|
||
private readonly string _data; | ||
private readonly string _assemblyName; | ||
private int _unityType; | ||
|
||
public static void GetUnitySerializationInfo(SerializationInfo info, int unityType, string data, Assembly assembly) | ||
{ | ||
// A helper method that returns the SerializationInfo that a class utilizing | ||
// UnitySerializationHelper should return from a call to GetObjectData. It contains | ||
// the unityType (defined above) and any optional data (used only for the reflection | ||
// types.) | ||
|
||
info.SetType(typeof(UnitySerializationHolder)); | ||
info.AddValue(DataName, data, typeof(string)); | ||
info.AddValue(UnityTypeName, unityType); | ||
info.AddValue(AssemblyNameName, assembly?.FullName ?? string.Empty); | ||
} | ||
|
||
public UnitySerializationHolder(SerializationInfo info, StreamingContext context) | ||
{ | ||
if (info == null) | ||
{ | ||
throw new ArgumentNullException(nameof(info)); | ||
} | ||
|
||
_unityType = info.GetInt32(UnityTypeName); | ||
_data = info.GetString(DataName); | ||
_assemblyName = info.GetString(AssemblyNameName); | ||
} | ||
|
||
public virtual void GetObjectData(SerializationInfo info, StreamingContext context) => | ||
throw new NotSupportedException(SR.NotSupported_UnitySerHolder); | ||
|
||
public virtual object GetRealObject(StreamingContext context) => DBNull.Value; | ||
} | ||
} |