Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Add BinaryFormatter to corefx
Browse files Browse the repository at this point in the history
This ports BinaryFormatter from desktop, along with all of the supporting types and general Formatter-related types.  I've added a bunch of tests, bringing code coverage up to ~80%, though there's still more that can/should be done.  I did not port remoting-specific functionality, though there are still some remnants I've left as they were enabled in the runtime even when remoting wasn't compiled in, and it wasn't clear if they were serving additional purposes.
  • Loading branch information
stephentoub committed Jul 15, 2016
1 parent 9597861 commit 5e0cfd8
Show file tree
Hide file tree
Showing 72 changed files with 12,416 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public SerializableAttribute()

namespace System.Runtime.Serialization
{
[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
{
Expand Down Expand Up @@ -137,3 +143,199 @@ private SerializationInfoEnumerator() { }
public void Reset() { throw null; }
}
}
namespace System.Runtime.Serialization
{
[System.CLSCompliantAttribute(false)]
public abstract partial class Formatter : System.Runtime.Serialization.IFormatter
{
protected System.Runtime.Serialization.ObjectIDGenerator m_idGenerator;
protected System.Collections.Queue m_objectQueue;
protected Formatter() { }
public abstract System.Runtime.Serialization.SerializationBinder Binder { get; set; }
public abstract System.Runtime.Serialization.StreamingContext Context { get; set; }
public abstract System.Runtime.Serialization.ISurrogateSelector SurrogateSelector { get; set; }
public abstract object Deserialize(System.IO.Stream serializationStream);
protected virtual object GetNext(out long objID) { objID = default(long); return default(object); }
protected virtual long Schedule(object obj) { return default(long); }
public abstract void Serialize(System.IO.Stream serializationStream, object graph);
protected abstract void WriteArray(object obj, string name, System.Type memberType);
protected abstract void WriteBoolean(bool val, string name);
protected abstract void WriteByte(byte val, string name);
protected abstract void WriteChar(char val, string name);
protected abstract void WriteDateTime(System.DateTime val, string name);
protected abstract void WriteDecimal(decimal val, string name);
protected abstract void WriteDouble(double val, string name);
protected abstract void WriteInt16(short val, string name);
protected abstract void WriteInt32(int val, string name);
protected abstract void WriteInt64(long val, string name);
protected virtual void WriteMember(string memberName, object data) { }
protected abstract void WriteObjectRef(object obj, string name, System.Type memberType);
[System.CLSCompliantAttribute(false)]
protected abstract void WriteSByte(sbyte val, string name);
protected abstract void WriteSingle(float val, string name);
protected abstract void WriteTimeSpan(System.TimeSpan val, string name);
[System.CLSCompliantAttribute(false)]
protected abstract void WriteUInt16(ushort val, string name);
[System.CLSCompliantAttribute(false)]
protected abstract void WriteUInt32(uint val, string name);
[System.CLSCompliantAttribute(false)]
protected abstract void WriteUInt64(ulong val, string name);
protected abstract void WriteValueType(object obj, string name, System.Type memberType);
}
public partial class FormatterConverter : System.Runtime.Serialization.IFormatterConverter
{
public FormatterConverter() { }
public object Convert(object value, System.Type type) { return default(object); }
public object Convert(object value, System.TypeCode typeCode) { return default(object); }
public bool ToBoolean(object value) { return default(bool); }
public byte ToByte(object value) { return default(byte); }
public char ToChar(object value) { return default(char); }
public System.DateTime ToDateTime(object value) { return default(System.DateTime); }
public decimal ToDecimal(object value) { return default(decimal); }
public double ToDouble(object value) { return default(double); }
public short ToInt16(object value) { return default(short); }
public int ToInt32(object value) { return default(int); }
public long ToInt64(object value) { return default(long); }
[System.CLSCompliantAttribute(false)]
public sbyte ToSByte(object value) { return default(sbyte); }
public float ToSingle(object value) { return default(float); }
public string ToString(object value) { return default(string); }
[System.CLSCompliantAttribute(false)]
public ushort ToUInt16(object value) { return default(ushort); }
[System.CLSCompliantAttribute(false)]
public uint ToUInt32(object value) { return default(uint); }
[System.CLSCompliantAttribute(false)]
public ulong ToUInt64(object value) { return default(ulong); }
}
public static partial class FormatterServices
{
public static void CheckTypeSecurity(System.Type t, System.Runtime.Serialization.Formatters.TypeFilterLevel securityLevel) { }
public static object[] GetObjectData(object obj, System.Reflection.MemberInfo[] members) { return default(object[]); }
public static object GetSafeUninitializedObject(System.Type type) { return default(object); }
public static System.Reflection.MemberInfo[] GetSerializableMembers(System.Type type) { return default(System.Reflection.MemberInfo[]); }
public static System.Reflection.MemberInfo[] GetSerializableMembers(System.Type type, System.Runtime.Serialization.StreamingContext context) { return default(System.Reflection.MemberInfo[]); }
public static System.Runtime.Serialization.ISerializationSurrogate GetSurrogateForCyclicalReference(System.Runtime.Serialization.ISerializationSurrogate innerSurrogate) { return default(System.Runtime.Serialization.ISerializationSurrogate); }
public static System.Type GetTypeFromAssembly(System.Reflection.Assembly assem, string name) { return default(System.Type); }
public static object GetUninitializedObject(System.Type type) { return default(object); }
public static object PopulateObjectMembers(object obj, System.Reflection.MemberInfo[] members, object[] data) { return default(object); }
}
public partial interface IFormatter
{
System.Runtime.Serialization.SerializationBinder Binder { get; set; }
System.Runtime.Serialization.StreamingContext Context { get; set; }
System.Runtime.Serialization.ISurrogateSelector SurrogateSelector { get; set; }
object Deserialize(System.IO.Stream serializationStream);
void Serialize(System.IO.Stream serializationStream, object graph);
}
public partial interface ISerializationSurrogate
{
void GetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
object SetObjectData(object obj, System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISurrogateSelector selector);
}
public partial interface ISurrogateSelector
{
void ChainSelector(System.Runtime.Serialization.ISurrogateSelector selector);
System.Runtime.Serialization.ISurrogateSelector GetNextSelector();
System.Runtime.Serialization.ISerializationSurrogate GetSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context, out System.Runtime.Serialization.ISurrogateSelector selector);
}
public partial class ObjectIDGenerator
{
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() { }
public virtual void BindToName(System.Type serializedType, out string assemblyName, out string typeName) { assemblyName = default(string); typeName = default(string); }
public abstract System.Type BindToType(string assemblyName, string typeName);
}
public sealed partial class SerializationObjectManager
{
public SerializationObjectManager(System.Runtime.Serialization.StreamingContext context) { }
public void RaiseOnSerializedEvent() { }
public void RegisterObject(object obj) { }
}
public partial class SurrogateSelector : System.Runtime.Serialization.ISurrogateSelector
{
public SurrogateSelector() { }
public virtual void AddSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.ISerializationSurrogate surrogate) { }
public virtual void ChainSelector(System.Runtime.Serialization.ISurrogateSelector selector) { }
public virtual System.Runtime.Serialization.ISurrogateSelector GetNextSelector() { return default(System.Runtime.Serialization.ISurrogateSelector); }
public virtual System.Runtime.Serialization.ISerializationSurrogate GetSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context, out System.Runtime.Serialization.ISurrogateSelector selector) { selector = default(System.Runtime.Serialization.ISurrogateSelector); return default(System.Runtime.Serialization.ISerializationSurrogate); }
public virtual void RemoveSurrogate(System.Type type, System.Runtime.Serialization.StreamingContext context) { }
}
} // end of System.Runtime.Serialization
namespace System.Runtime.Serialization.Formatters
{
public enum FormatterAssemblyStyle
{
Full = 1,
Simple = 0,
}
public enum FormatterTypeStyle
{
TypesAlways = 1,
TypesWhenNeeded = 0,
XsdString = 2,
}
public partial interface IFieldInfo
{
string[] FieldNames { get; set; }
System.Type[] FieldTypes { get; set; }
}
public enum TypeFilterLevel
{
Full = 3,
Low = 2,
}
} // end of System.Runtime.Serialization.Formatters
namespace System.Runtime.Serialization.Formatters.Binary
{
public sealed partial class BinaryFormatter : System.Runtime.Serialization.IFormatter
{
public BinaryFormatter() { }
public BinaryFormatter(System.Runtime.Serialization.ISurrogateSelector selector, System.Runtime.Serialization.StreamingContext context) { }
public System.Runtime.Serialization.Formatters.FormatterAssemblyStyle AssemblyFormat { get { return default(System.Runtime.Serialization.Formatters.FormatterAssemblyStyle); } set { } }
public System.Runtime.Serialization.SerializationBinder Binder { get { return default(System.Runtime.Serialization.SerializationBinder); } set { } }
public System.Runtime.Serialization.StreamingContext Context { get { return default(System.Runtime.Serialization.StreamingContext); } set { } }
public System.Runtime.Serialization.Formatters.TypeFilterLevel FilterLevel { get { return default(System.Runtime.Serialization.Formatters.TypeFilterLevel); } set { } }
public System.Runtime.Serialization.ISurrogateSelector SurrogateSelector { get { return default(System.Runtime.Serialization.ISurrogateSelector); } set { } }
public System.Runtime.Serialization.Formatters.FormatterTypeStyle TypeFormat { get { return default(System.Runtime.Serialization.Formatters.FormatterTypeStyle); } set { } }
public object Deserialize(System.IO.Stream serializationStream) { return default(object); }
public object Deserialize(System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) { return default(object); }
public void Serialize(System.IO.Stream serializationStream, object graph) { }
public void Serialize(System.IO.Stream serializationStream, object graph, System.Runtime.Remoting.Messaging.Header[] headers) { }
public object UnsafeDeserialize(System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) { return default(object); }
}
} // end of System.Runtime.Serialization.Formatters.Binary
namespace System.Runtime.Remoting.Messaging
{
public partial class Header
{
public string HeaderNamespace;
public bool MustUnderstand;
public string Name;
public object Value;
public Header(string _Name, object _Value) { }
public Header(string _Name, object _Value, bool _MustUnderstand) { }
public Header(string _Name, object _Value, bool _MustUnderstand, string _HeaderNamespace) { }
}
public delegate object HeaderHandler(System.Runtime.Remoting.Messaging.Header[] headers);
}
3 changes: 3 additions & 0 deletions src/System.Runtime.Serialization.Formatters/ref/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"dependencies": {
"System.Collections.NonGeneric": "4.0.0",
"System.IO": "4.0.10",
"System.Reflection": "4.1.0",
"System.Runtime": "4.0.20",
"System.Runtime.Extensions": "4.0.10",
"System.Runtime.Serialization.Primitives": "4.1.1"
Expand Down
Loading

0 comments on commit 5e0cfd8

Please sign in to comment.