Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,23 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: DeserializationEventHandler
**
**
** Purpose: The multicast delegate called when the DeserializationEvent is thrown.
**
**
===========================================================*/
namespace System.Runtime.Serialization {
[Serializable]
internal delegate void DeserializationEventHandler(Object sender);
[Serializable]
internal delegate void SerializationEventHandler(StreamingContext context);
}

View File

@@ -0,0 +1,224 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: Formatter
**
**
** Purpose: The abstract base class for all COM+ Runtime
** Serialization Formatters.
**
**
===========================================================*/
namespace System.Runtime.Serialization {
using System.Threading;
using System.Runtime.Remoting;
using System;
using System.Collections;
using System.Reflection;
using System.IO;
using System.Globalization;
// This abstract class provides some helper methods for implementing
// IFormatter. It will manage queueing objects for serialization
// (the functionality formerly provided by the IGraphWalker interface)
// and generating ids on a per-object basis.
[Serializable]
[CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Formatter : IFormatter {
protected ObjectIDGenerator m_idGenerator;
protected Queue m_objectQueue;
// The default constructor instantiates the queue for objects
// to be serialized and creates a new instance of the
// ObjectIDGenerator.
protected Formatter() {
m_objectQueue = new Queue();
m_idGenerator = new ObjectIDGenerator();
}
public abstract Object Deserialize(Stream serializationStream);
// This gives back the next object to be serialized. Objects
// are returned in a FIFO order based on how they were passed
// to Schedule. The id of the object is put into the objID parameter
// and the Object itself is returned from the function.
protected virtual Object GetNext(out long objID) {
bool isNew;
if (m_objectQueue.Count==0) {
objID=0;
return null;
}
Object obj = m_objectQueue.Dequeue();
objID = m_idGenerator.HasId(obj, out isNew);
if (isNew) {
throw new SerializationException(Environment.GetResourceString("Serialization_NoID"));
}
return obj;
}
// Schedules an object for later serialization if it hasn't already been scheduled.
// We get an ID for obj and put it on the queue for later serialization
// if this is a new object id.
protected virtual long Schedule(Object obj) {
bool isNew;
long id;
if (obj==null) {
return 0;
}
id = m_idGenerator.GetId(obj, out isNew);
if (isNew) {
m_objectQueue.Enqueue(obj);
}
return id;
}
public abstract void Serialize(Stream serializationStream, Object graph);
// Writes an array to the stream
protected abstract void WriteArray(Object obj, String name, Type memberType);
// Writes a boolean to the stream.
protected abstract void WriteBoolean(bool val, String name);
// Writes a byte to the stream.
protected abstract void WriteByte(byte val, String name);
// Writes a character to the stream.
protected abstract void WriteChar(char val, String name);
// Writes an instance of DateTime to the stream.
protected abstract void WriteDateTime(DateTime val, String name);
// Writes an instance of Decimal to the stream.
protected abstract void WriteDecimal(Decimal val, String name);
// Writes an instance of Double to the stream.
protected abstract void WriteDouble(double val, String name);
// Writes an instance of Int16 to the stream.
protected abstract void WriteInt16(short val, String name);
// Writes an instance of Int32 to the stream.
protected abstract void WriteInt32(int val, String name);
// Writes an instance of Int64 to the stream.
protected abstract void WriteInt64(long val, String name);
// Writes an object reference to the stream. Schedules the object with the graph walker
// to handle the work.
protected abstract void WriteObjectRef(Object obj, String name, Type memberType);
// Switches on the type of the member to determine which of the Write* methods
// to call in order to write this particular member to the stream.
protected virtual void WriteMember(String memberName, Object data) {
BCLDebug.Trace("SER", "[Formatter.WriteMember]data: ", data);
if (data==null) {
WriteObjectRef(data, memberName, typeof(Object));
return;
}
Type varType = data.GetType();
BCLDebug.Trace("SER", "[Formatter.WriteMember]data is of type: " , varType);
if (varType==typeof(Boolean)) {
WriteBoolean(Convert.ToBoolean(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Char)) {
WriteChar(Convert.ToChar(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(SByte)) {
WriteSByte(Convert.ToSByte(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Byte)) {
WriteByte(Convert.ToByte(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Int16)) {
WriteInt16(Convert.ToInt16(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Int32)) {
WriteInt32(Convert.ToInt32(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Int64)) {
WriteInt64(Convert.ToInt64(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Single)) {
WriteSingle(Convert.ToSingle(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Double)) {
WriteDouble(Convert.ToDouble(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(DateTime)) {
WriteDateTime(Convert.ToDateTime(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(Decimal)) {
WriteDecimal(Convert.ToDecimal(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(UInt16)) {
WriteUInt16(Convert.ToUInt16(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(UInt32)) {
WriteUInt32(Convert.ToUInt32(data, CultureInfo.InvariantCulture), memberName);
} else if (varType==typeof(UInt64)) {
WriteUInt64(Convert.ToUInt64(data, CultureInfo.InvariantCulture), memberName);
} else {
if (varType.IsArray) {
WriteArray(data, memberName, varType);
} else if (varType.IsValueType) {
WriteValueType(data, memberName, varType);
} else {
WriteObjectRef(data, memberName, varType);
}
}
}
// Writes an instance of SByte to the stream.
[CLSCompliant(false)]
protected abstract void WriteSByte(sbyte val, String name);
// Writes an instance of Single to the stream.
protected abstract void WriteSingle(float val, String name);
// Writes an instance of TimeSpan to the stream.
protected abstract void WriteTimeSpan(TimeSpan val, String name);
// Writes an instance of an ushort to the stream.
[CLSCompliant(false)]
protected abstract void WriteUInt16(ushort val, String name);
// Writes an instance of an uint to the stream.
[CLSCompliant(false)]
protected abstract void WriteUInt32(uint val, String name);
// Writes an instance of a ulong to the stream.
[CLSCompliant(false)]
protected abstract void WriteUInt64(ulong val, String name);
// Writes a valuetype out to the stream.
protected abstract void WriteValueType(Object obj, String name, Type memberType);
public abstract ISurrogateSelector SurrogateSelector {
get;
set;
}
public abstract SerializationBinder Binder {
get;
set;
}
public abstract StreamingContext Context {
get;
set;
}
}
}

View File

@@ -0,0 +1,169 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: FormatterConverter
**
**
** Purpose: A base implementation of the IFormatterConverter
** interface that uses the Convert class and the
** IConvertible interface.
**
**
============================================================*/
namespace System.Runtime.Serialization {
using System;
using System.Globalization;
using System.Diagnostics.Contracts;
[System.Runtime.InteropServices.ComVisible(true)]
public class FormatterConverter : IFormatterConverter {
public FormatterConverter() {
}
public Object Convert(Object value, Type type) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
}
public Object Convert(Object value, TypeCode typeCode) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ChangeType(value, typeCode, CultureInfo.InvariantCulture);
}
public bool ToBoolean(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToBoolean(value, CultureInfo.InvariantCulture);
}
public char ToChar(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToChar(value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
public sbyte ToSByte(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToSByte(value, CultureInfo.InvariantCulture);
}
public byte ToByte(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToByte(value, CultureInfo.InvariantCulture);
}
public short ToInt16(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToInt16(value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
public ushort ToUInt16(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToUInt16(value, CultureInfo.InvariantCulture);
}
public int ToInt32(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToInt32(value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
public uint ToUInt32(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToUInt32(value, CultureInfo.InvariantCulture);
}
public long ToInt64(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToInt64(value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
public ulong ToUInt64(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToUInt64(value, CultureInfo.InvariantCulture);
}
public float ToSingle(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToSingle(value, CultureInfo.InvariantCulture);
}
public double ToDouble(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToDouble(value, CultureInfo.InvariantCulture);
}
public Decimal ToDecimal(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToDecimal(value, CultureInfo.InvariantCulture);
}
public DateTime ToDateTime(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToDateTime(value, CultureInfo.InvariantCulture);
}
public String ToString(Object value) {
if (value==null) {
throw new ArgumentNullException("value");
}
Contract.EndContractBlock();
return System.Convert.ToString(value, CultureInfo.InvariantCulture);
}
}
}

View File

@@ -0,0 +1,260 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: BinaryEnums
**
**
** Purpose: Soap XML Formatter Enums
**
**
===========================================================*/
namespace System.Runtime.Serialization.Formatters.Binary
{
using System.Runtime.Serialization.Formatters;
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System;
// BinaryHeaderEnum is the first byte on binary records
// (except for primitive types which do not have a header)
[Serializable]
enum BinaryHeaderEnum
{
SerializedStreamHeader = 0,
Object = 1,
ObjectWithMap = 2,
ObjectWithMapAssemId = 3,
ObjectWithMapTyped = 4,
ObjectWithMapTypedAssemId = 5,
ObjectString = 6,
Array = 7,
MemberPrimitiveTyped = 8,
MemberReference = 9,
ObjectNull = 10,
MessageEnd = 11,
Assembly = 12,
ObjectNullMultiple256 = 13,
ObjectNullMultiple = 14,
ArraySinglePrimitive = 15,
ArraySingleObject = 16,
ArraySingleString = 17,
CrossAppDomainMap = 18,
CrossAppDomainString = 19,
CrossAppDomainAssembly = 20,
MethodCall = 21,
MethodReturn = 22,
}
// BinaryTypeEnum is used specify the type on the wire.
// Additional information is transmitted with Primitive and Object types
[Serializable]
enum BinaryTypeEnum
{
Primitive = 0,
String = 1,
Object = 2,
ObjectUrt = 3,
ObjectUser = 4,
ObjectArray = 5,
StringArray = 6,
PrimitiveArray = 7,
}
[Serializable]
internal enum BinaryArrayTypeEnum
{
Single = 0,
Jagged = 1,
Rectangular = 2,
SingleOffset = 3,
JaggedOffset = 4,
RectangularOffset = 5,
}
// Enums are for internal use by the XML and Binary Serializers
// They will eventually signed to restrict there use
// Formatter Enums
[Serializable]
internal enum InternalSerializerTypeE
{
Soap = 1,
Binary = 2,
}
// Writer Enums
[Serializable]
internal enum InternalElementTypeE
{
ObjectBegin = 0,
ObjectEnd = 1,
Member = 2,
}
// ParseRecord Enums
[Serializable]
internal enum InternalParseTypeE
{
Empty = 0,
SerializedStreamHeader = 1,
Object = 2,
Member = 3,
ObjectEnd = 4,
MemberEnd = 5,
Headers = 6,
HeadersEnd = 7,
SerializedStreamHeaderEnd = 8,
Envelope = 9,
EnvelopeEnd = 10,
Body = 11,
BodyEnd = 12,
}
[Serializable]
internal enum InternalObjectTypeE
{
Empty = 0,
Object = 1,
Array = 2,
}
[Serializable]
internal enum InternalObjectPositionE
{
Empty = 0,
Top = 1,
Child = 2,
Headers = 3,
}
[Serializable]
internal enum InternalArrayTypeE
{
Empty = 0,
Single = 1,
Jagged = 2,
Rectangular = 3,
Base64 = 4,
}
[Serializable]
internal enum InternalMemberTypeE
{
Empty = 0,
Header = 1,
Field = 2,
Item = 3,
}
[Serializable]
internal enum InternalMemberValueE
{
Empty = 0,
InlineValue = 1,
Nested = 2,
Reference = 3,
Null = 4,
}
// XML Parse Enum
[Serializable]
internal enum InternalParseStateE
{
Initial = 0,
Object = 1,
Member = 2,
MemberChild = 3,
}
// Data Type Enums
[Serializable]
internal enum InternalPrimitiveTypeE
{
Invalid = 0,
Boolean = 1,
Byte = 2,
Char = 3,
Currency = 4,
Decimal = 5,
Double = 6,
Int16 = 7,
Int32 = 8,
Int64 = 9,
SByte = 10,
Single = 11,
TimeSpan = 12,
DateTime = 13,
UInt16 = 14,
UInt32 = 15,
UInt64 = 16,
// Used in only for MethodCall or MethodReturn header
Null = 17,
String = 18,
}
[Serializable]
[Flags]
internal enum MessageEnum
{
NoArgs = 0x1,
ArgsInline = 0x2,
ArgsIsArray = 0x4,
ArgsInArray = 0x8,
NoContext = 0x10,
ContextInline = 0x20,
ContextInArray = 0x40,
MethodSignatureInArray = 0x80,
PropertyInArray = 0x100,
NoReturnValue = 0x200,
ReturnValueVoid = 0x400,
ReturnValueInline = 0x800,
ReturnValueInArray = 0x1000,
ExceptionInArray = 0x2000,
GenericMethod = 0x8000
}
// ValueType Fixup Enum
[Serializable]
enum ValueFixupEnum
{
Empty = 0,
Array = 1,
Header = 2,
Member = 3,
}
// name space
[Serializable]
internal enum InternalNameSpaceE
{
None = 0,
Soap = 1,
XdrPrimitive = 2,
XdrString = 3,
UrtSystem = 4,
UrtUser = 5,
UserNameSpace = 6,
MemberName = 7,
Interop = 8,
CallElement = 9
}
[Serializable]
internal enum SoapAttributeType
{
None = 0x0,
SchemaType = 0x1,
Embedded = 0x2,
XmlElement = 0x4,
XmlAttribute = 0x8
}
}

View File

@@ -0,0 +1,253 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: BinaryFormatter
**
**
** Purpose: Soap XML Formatter
**
**
===========================================================*/
namespace System.Runtime.Serialization.Formatters.Binary {
using System;
using System.IO;
using System.Reflection;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
#if FEATURE_REMOTING
using System.Runtime.Remoting.Proxies;
#endif
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Diagnostics.Contracts;
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class BinaryFormatter :
#if !FEATURE_REMOTING
IFormatter
#else
IRemotingFormatter
#endif
{
internal ISurrogateSelector m_surrogates;
internal StreamingContext m_context;
internal SerializationBinder m_binder;
//internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesWhenNeeded;
internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesAlways; // For version resiliency, always put out types
internal FormatterAssemblyStyle m_assemblyFormat = FormatterAssemblyStyle.Simple;
internal TypeFilterLevel m_securityLevel = TypeFilterLevel.Full;
internal Object[] m_crossAppDomainArray = null;
private static Dictionary<Type, TypeInformation> typeNameCache = new Dictionary<Type, TypeInformation>();
// Property which specifies how types are serialized,
// FormatterTypeStyle Enum specifies options
public FormatterTypeStyle TypeFormat
{
get { return m_typeFormat; }
set { m_typeFormat = value; }
}
// Property which specifies how types are serialized,
// FormatterAssemblyStyle Enum specifies options
public FormatterAssemblyStyle AssemblyFormat
{
get { return m_assemblyFormat; }
set { m_assemblyFormat = value; }
}
// Property which specifies the security level of formatter
// TypeFilterLevel Enum specifies options
public TypeFilterLevel FilterLevel
{
get { return m_securityLevel; }
set { m_securityLevel = value; }
}
public ISurrogateSelector SurrogateSelector {
get { return m_surrogates; }
set { m_surrogates = value; }
}
public SerializationBinder Binder {
get { return m_binder; }
set { m_binder = value; }
}
public StreamingContext Context {
get { return m_context; }
set { m_context = value; }
}
// Constructor
public BinaryFormatter()
{
m_surrogates = null;
m_context = new StreamingContext(StreamingContextStates.All);
}
// Constructor
public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) {
m_surrogates = selector;
m_context = context;
}
// Deserialize the stream into an object graph.
public Object Deserialize(Stream serializationStream)
{
return Deserialize(serializationStream, null);
}
[System.Security.SecurityCritical] // auto-generated
internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck)
{
#if FEATURE_REMOTING
return Deserialize(serializationStream, handler, fCheck, null);
#else
if (serializationStream == null)
{
throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream));
}
Contract.EndContractBlock();
if (serializationStream.CanSeek && (serializationStream.Length == 0))
throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));
SerTrace.Log(this, "Deserialize Entry");
InternalFE formatterEnums = new InternalFE();
formatterEnums.FEtypeFormat = m_typeFormat;
formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
formatterEnums.FEassemblyFormat = m_assemblyFormat;
formatterEnums.FEsecurityLevel = m_securityLevel;
ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder);
sor.crossAppDomainArray = m_crossAppDomainArray;
return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck);
#endif
}
// Deserialize the stream into an object graph.
[System.Security.SecuritySafeCritical] // auto-generated
public Object Deserialize(Stream serializationStream, HeaderHandler handler) {
return Deserialize(serializationStream, handler, true);
}
#if FEATURE_REMOTING
[System.Security.SecuritySafeCritical] // auto-generated
public Object DeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) {
return Deserialize(serializationStream, handler, true, methodCallMessage);
}
#endif
[System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(false)]
public Object UnsafeDeserialize(Stream serializationStream, HeaderHandler handler) {
return Deserialize(serializationStream, handler, false);
}
#if FEATURE_REMOTING
[System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(false)]
public Object UnsafeDeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) {
return Deserialize(serializationStream, handler, false, methodCallMessage);
}
[System.Security.SecurityCritical] // auto-generated
internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, IMethodCallMessage methodCallMessage) {
return Deserialize(serializationStream, handler, fCheck, false/*isCrossAppDomain*/, methodCallMessage);
}
// Deserialize the stream into an object graph.
[System.Security.SecurityCritical] // auto-generated
internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) {
if (serializationStream==null)
{
throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName",serializationStream));
}
Contract.EndContractBlock();
if (serializationStream.CanSeek && (serializationStream.Length == 0))
throw new SerializationException(Environment.GetResourceString("Serialization_Stream"));
SerTrace.Log(this, "Deserialize Entry");
InternalFE formatterEnums = new InternalFE();
formatterEnums.FEtypeFormat = m_typeFormat;
formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
formatterEnums.FEassemblyFormat = m_assemblyFormat;
formatterEnums.FEsecurityLevel = m_securityLevel;
ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder);
sor.crossAppDomainArray = m_crossAppDomainArray;
return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage);
}
#endif // FEATURE_REMOTING
public void Serialize(Stream serializationStream, Object graph)
{
Serialize(serializationStream, graph, null);
}
// Commences the process of serializing the entire graph. All of the data (in the appropriate format
// is emitted onto the stream).
[System.Security.SecuritySafeCritical] // auto-generated
public void Serialize(Stream serializationStream, Object graph, Header[] headers)
{
Serialize(serializationStream, graph, headers, true);
}
// Commences the process of serializing the entire graph. All of the data (in the appropriate format
// is emitted onto the stream).
[System.Security.SecurityCritical] // auto-generated
internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck)
{
if (serializationStream == null)
{
throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream));
}
Contract.EndContractBlock();
SerTrace.Log(this, "Serialize Entry");
InternalFE formatterEnums = new InternalFE();
formatterEnums.FEtypeFormat = m_typeFormat;
formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary;
formatterEnums.FEassemblyFormat = m_assemblyFormat;
ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums, m_binder);
__BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat);
sow.Serialize(graph, headers, binaryWriter, fCheck);
m_crossAppDomainArray = sow.crossAppDomainArray;
}
internal static TypeInformation GetTypeInformation(Type type)
{
lock (typeNameCache)
{
TypeInformation typeInformation = null;
if (!typeNameCache.TryGetValue(type, out typeInformation))
{
bool hasTypeForwardedFrom;
string assemblyName = FormatterServices.GetClrAssemblyName(type, out hasTypeForwardedFrom);
typeInformation = new TypeInformation(FormatterServices.GetClrTypeFullName(type), assemblyName, hasTypeForwardedFrom);
typeNameCache.Add(type, typeInformation);
}
return typeInformation;
}
}
}
}

View File

@@ -0,0 +1,168 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
#if FEATURE_REMOTING
namespace System.Runtime.Serialization.Formatters.Binary
{
using System;
using System.Collections;
using System.Runtime.Remoting.Messaging;
using System.Reflection;
[Serializable]
internal sealed class BinaryMethodCallMessage
{
Object[] _inargs = null;
String _methodName = null;
String _typeName = null;
Object _methodSignature = null;
Type[] _instArgs = null;
Object[] _args = null;
[System.Security.SecurityCritical] // auto-generated
LogicalCallContext _logicalCallContext = null;
Object[] _properties = null;
[System.Security.SecurityCritical] // auto-generated
internal BinaryMethodCallMessage(String uri, String methodName, String typeName, Type[] instArgs, Object[] args, Object methodSignature, LogicalCallContext callContext, Object[] properties)
{
_methodName = methodName;
_typeName = typeName;
//_uri = uri;
if (args == null)
args = new Object[0];
_inargs = args;
_args = args;
_instArgs = instArgs;
_methodSignature = methodSignature;
if (callContext == null)
_logicalCallContext = new LogicalCallContext();
else
_logicalCallContext = callContext;
_properties = properties;
}
public String MethodName
{
get {return _methodName;}
}
public String TypeName
{
get {return _typeName;}
}
public Type[] InstantiationArgs
{
get {return _instArgs;}
}
public Object MethodSignature
{
get {return _methodSignature;}
}
public Object[] Args
{
get {return _args;}
}
public LogicalCallContext LogicalCallContext
{
[System.Security.SecurityCritical] // auto-generated
get {return _logicalCallContext;}
}
public bool HasProperties
{
get {return (_properties != null);}
}
internal void PopulateMessageProperties(IDictionary dict)
{
foreach (DictionaryEntry de in _properties)
{
dict[de.Key] = de.Value;
}
}
}
[Serializable]
internal class BinaryMethodReturnMessage
{
Object[] _outargs = null;
Exception _exception = null;
Object _returnValue = null;
Object[] _args = null;
[System.Security.SecurityCritical] // auto-generated
LogicalCallContext _logicalCallContext = null;
Object[] _properties = null;
[System.Security.SecurityCritical] // auto-generated
internal BinaryMethodReturnMessage(Object returnValue, Object[] args, Exception e, LogicalCallContext callContext, Object[] properties)
{
_returnValue = returnValue;
if (args == null)
args = new Object[0];
_outargs = args;
_args= args;
_exception = e;
if (callContext == null)
_logicalCallContext = new LogicalCallContext();
else
_logicalCallContext = callContext;
_properties = properties;
}
public Exception Exception
{
get {return _exception;}
}
public Object ReturnValue
{
get {return _returnValue;}
}
public Object[] Args
{
get {return _args;}
}
public LogicalCallContext LogicalCallContext
{
[System.Security.SecurityCritical] // auto-generated
get {return _logicalCallContext;}
}
public bool HasProperties
{
get {return (_properties != null);}
}
internal void PopulateMessageProperties(IDictionary dict)
{
foreach (DictionaryEntry de in _properties)
{
dict[de.Key] = de.Value;
}
}
}
}
#endif // FEATURE_REMOTING

View File

@@ -0,0 +1,45 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: FormatterEnums
**
**
** Purpose: Soap XML Formatter Enums
**
**
===========================================================*/
namespace System.Runtime.Serialization.Formatters {
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System;
// Enums which specify options to the XML and Binary formatters
// These will be public so that applications can use them
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FormatterTypeStyle
{
TypesWhenNeeded = 0, // Types are outputted only for Arrays of Objects, Object Members of type Object, and ISerializable non-primitive value types
TypesAlways = 0x1, // Types are outputted for all Object members and ISerialiable object members.
XsdString = 0x2 // Strings are outputed as xsd rather then SOAP-ENC strings. No string ID's are transmitted
}
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FormatterAssemblyStyle
{
Simple = 0,
Full = 1,
}
[System.Runtime.InteropServices.ComVisible(true)]
public enum TypeFilterLevel {
Low = 0x2,
Full = 0x3
}
}

View File

@@ -0,0 +1,42 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: IFieldInfo
**
**
** Purpose: Interface For Returning FieldNames and FieldTypes
**
**
===========================================================*/
namespace System.Runtime.Serialization.Formatters {
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System;
[System.Runtime.InteropServices.ComVisible(true)]
public interface IFieldInfo
{
// Name of parameters, if null the default param names will be used
String[] FieldNames
{
[System.Security.SecurityCritical] // auto-generated_required
get;
[System.Security.SecurityCritical] // auto-generated_required
set;
}
Type[] FieldTypes
{
[System.Security.SecurityCritical] // auto-generated_required
get;
[System.Security.SecurityCritical] // auto-generated_required
set;
}
}
}

View File

@@ -0,0 +1,49 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: ISoapMessage
**
**
** Purpose: Interface For Soap Method Call
**
**
===========================================================*/
#if FEATURE_REMOTING
namespace System.Runtime.Serialization.Formatters {
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Runtime.Remoting.Messaging;
using System;
// Used to specify a call record to either the binary or xml serializer
// The call record can be transmitted as the SOAP Top record which contains
// a method name instead of an object name as the Top record's element name
[System.Runtime.InteropServices.ComVisible(true)]
public interface ISoapMessage
{
// Name of parameters, if null the default param names will be used
String[] ParamNames {get; set;}
// Parameter Values
Object[] ParamValues {get; set;}
// Parameter Types
Type[] ParamTypes {get; set;}
// MethodName
String MethodName {get; set;}
// MethodName XmlNameSpace
String XmlNameSpace {get; set;}
// Headers
Header[] Headers {get; set;}
}
}
#endif // FEATURE_REMOTING

View File

@@ -0,0 +1,145 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SerTrace
**
**
** Purpose: Routine used for Debugging
**
**
===========================================================*/
namespace System.Runtime.Serialization.Formatters {
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Reflection;
using System.Diagnostics;
using System.Diagnostics.Contracts;
#if FEATURE_PAL
// To turn on tracing, add the following to the per-machine
// rotor.ini file, inside the [Rotor] section:
// ManagedLogFacility=0x32
// where:
#else
// To turn on tracing the set registry
// HKEY_CURRENT_USER -> Software -> Microsoft -> .NETFramework
// new DWORD value ManagedLogFacility 0x32 where
#endif
// 0x2 is System.Runtime.Serialization
// 0x10 is Binary Formatter
// 0x20 is Soap Formatter
//
// Turn on Logging in the jitmgr
// remoting Wsdl logging
/// <internalonly/>
[System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InternalRM
{
/// <internalonly/>
[System.Diagnostics.Conditional("_LOGGING")]
public static void InfoSoap(params Object[]messages)
{
BCLDebug.Trace("SOAP", messages);
}
//[System.Diagnostics.Conditional("_LOGGING")]
/// <internalonly/>
public static bool SoapCheckEnabled()
{
return BCLDebug.CheckEnabled("SOAP");
}
}
/// <internalonly/>
[System.Security.SecurityCritical] // auto-generated_required
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class InternalST
{
private InternalST()
{
}
/// <internalonly/>
[System.Diagnostics.Conditional("_LOGGING")]
public static void InfoSoap(params Object[]messages)
{
BCLDebug.Trace("SOAP", messages);
}
//[System.Diagnostics.Conditional("_LOGGING")]
/// <internalonly/>
public static bool SoapCheckEnabled()
{
return BCLDebug.CheckEnabled("Soap");
}
/// <internalonly/>
[System.Diagnostics.Conditional("SER_LOGGING")]
public static void Soap(params Object[]messages)
{
if (!(messages[0] is String))
messages[0] = (messages[0].GetType()).Name+" ";
else
messages[0] = messages[0]+" ";
BCLDebug.Trace("SOAP",messages);
}
/// <internalonly/>
[System.Diagnostics.Conditional("_DEBUG")]
public static void SoapAssert(bool condition, String message)
{
Contract.Assert(condition, message);
}
/// <internalonly/>
public static void SerializationSetValue(FieldInfo fi, Object target, Object value)
{
if (fi == null)
throw new ArgumentNullException("fi");
if (target == null)
throw new ArgumentNullException("target");
if (value == null)
throw new ArgumentNullException("value");
Contract.EndContractBlock();
FormatterServices.SerializationSetValue(fi, target, value);
}
/// <internalonly/>
public static Assembly LoadAssemblyFromString(String assemblyString)
{
return FormatterServices.LoadAssemblyFromString(assemblyString);
}
}
internal static class SerTrace
{
[Conditional("_LOGGING")]
internal static void InfoLog(params Object[]messages)
{
BCLDebug.Trace("BINARY", messages);
}
[Conditional("SER_LOGGING")]
internal static void Log(params Object[]messages)
{
if (!(messages[0] is String))
messages[0] = (messages[0].GetType()).Name+" ";
else
messages[0] = messages[0]+" ";
BCLDebug.Trace("BINARY",messages);
}
}
}

View File

@@ -0,0 +1,164 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SoapFault
**
** <EMAIL>Author: Peter de Jong ([....])</EMAIL>
**
** Purpose: Specifies information for a Soap Fault
**
** Date: June 27, 2000
**
===========================================================*/
#if FEATURE_REMOTING
namespace System.Runtime.Serialization.Formatters
{
using System;
using System.Runtime.Serialization;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Metadata;
using System.Globalization;
using System.Security.Permissions;
//* Class holds soap fault information
[Serializable]
[SoapType(Embedded=true)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class SoapFault : ISerializable
{
String faultCode;
String faultString;
String faultActor;
[SoapField(Embedded=true)] Object detail;
public SoapFault()
{
}
public SoapFault(String faultCode, String faultString, String faultActor, ServerFault serverFault)
{
this.faultCode = faultCode;
this.faultString = faultString;
this.faultActor = faultActor;
this.detail = serverFault;
}
internal SoapFault(SerializationInfo info, StreamingContext context)
{
SerializationInfoEnumerator siEnum = info.GetEnumerator();
while(siEnum.MoveNext())
{
String name = siEnum.Name;
Object value = siEnum.Value;
SerTrace.Log(this, "SetObjectData enum ",name," value ",value);
if (String.Compare(name, "faultCode", true, CultureInfo.InvariantCulture) == 0)
{
int index = ((String)value).IndexOf(':');
if (index > -1)
faultCode = ((String)value).Substring(++index);
else
faultCode = (String)value;
}
else if (String.Compare(name, "faultString", true, CultureInfo.InvariantCulture) == 0)
faultString = (String)value;
else if (String.Compare(name, "faultActor", true, CultureInfo.InvariantCulture) == 0)
faultActor = (String)value;
else if (String.Compare(name, "detail", true, CultureInfo.InvariantCulture) == 0)
detail = value;
}
}
[System.Security.SecurityCritical] // auto-generated_required
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("faultcode", "SOAP-ENV:"+faultCode);
info.AddValue("faultstring", faultString);
if (faultActor != null)
info.AddValue("faultactor", faultActor);
info.AddValue("detail", detail, typeof(Object));
}
public String FaultCode
{
get {return faultCode;}
set { faultCode = value;}
}
public String FaultString
{
get {return faultString;}
set { faultString = value;}
}
public String FaultActor
{
get {return faultActor;}
set { faultActor = value;}
}
public Object Detail
{
get {return detail;}
set {detail = value;}
}
}
[Serializable]
[SoapType(Embedded=true)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ServerFault
{
String exceptionType;
String message;
String stackTrace;
Exception exception;
internal ServerFault(Exception exception)
{
this.exception = exception;
//this.exceptionType = exception.GetType().AssemblyQualifiedName;
//this.message = exception.Message;
}
public ServerFault(String exceptionType, String message, String stackTrace)
{
this.exceptionType = exceptionType;
this.message = message;
this.stackTrace = stackTrace;
}
public String ExceptionType
{
get {return exceptionType;}
set { exceptionType = value;}
}
public String ExceptionMessage
{
get {return message;}
set { message = value;}
}
public String StackTrace
{
get {return stackTrace;}
set {stackTrace = value;}
}
internal Exception Exception
{
get {return exception;}
}
}
}
#endif // FEATURE_REMOTING

View File

@@ -0,0 +1,79 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SoapMessage
**
**
** Purpose: Interface For Soap Method Call
**
**
===========================================================*/
#if FEATURE_REMOTING
namespace System.Runtime.Serialization.Formatters {
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Serialization;
using System;
// Class is used to return the call object for a SOAP call.
// This is used when the top SOAP object is a fake object, it contains
// a method name as the element name instead of the object name.
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class SoapMessage : ISoapMessage
{
internal String[] paramNames;
internal Object[] paramValues;
internal Type[] paramTypes;
internal String methodName;
internal String xmlNameSpace;
internal Header[] headers;
// Name of parameters, if null the default param names will be used
public String[] ParamNames
{
get {return paramNames;}
set {paramNames = value;}
}
// Parameter Values
public Object[] ParamValues
{
get {return paramValues;}
set {paramValues = value;}
}
public Type[] ParamTypes
{
get {return paramTypes;}
set {paramTypes = value;}
}
// MethodName
public String MethodName
{
get {return methodName;}
set {methodName = value;}
}
// MethodName XmlNameSpace
public String XmlNameSpace
{
get {return xmlNameSpace;}
set {xmlNameSpace = value;}
}
// Headers
public Header[] Headers
{
get {return headers;}
set {headers = value;}
}
}
}
#endif // FEATURE_REMOTING

Some files were not shown because too many files have changed in this diff Show More