internal static Exception NewUnpackToIsNotSupported(Type type, Exception inner) { #if DEBUG Contract.Requires(type != null); #endif // DEBUG return(new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "This operation is not supported for '{0}' because it does not have accesible Add(T) method.", type), inner)); }
/// <summary> /// Returns a new exception which represents <c>UnpackFrom</c> is not supported in this asymmetric serializer. /// </summary> /// <param name="targetType">Deserializing type.</param> /// <returns>The exception. This value will not be <c>null</c>.</returns> public static Exception NewCreateInstanceIsNotSupported(Type targetType) { #if DEBUG Contract.Requires(targetType != null); #endif // DEBUG return(new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "This operation is not supported for '{0}' because the serializer does not support CreateInstance method.", targetType))); }
/// <summary> /// Initializes a new instance of the <see cref="SerializerEmitter"/> class. /// </summary> /// <param name="host">The host <see cref="ModuleBuilder"/>.</param> /// <param name="specification">The specification of the serializer.</param> /// <param name="baseClass">Type of the base class of the serializer.</param> /// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param> public SerializerEmitter(ModuleBuilder host, SerializerSpecification specification, Type baseClass, bool isDebuggable) { Contract.Requires(host != null); Contract.Requires(specification != null); Contract.Requires(baseClass != null); Tracer.Emit.TraceEvent(Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName); this._methodTable = new Dictionary <string, MethodBuilder>(); this._fieldTable = new Dictionary <string, FieldBuilder>(); this._specification = specification; this._host = host; this._typeBuilder = host.DefineType( specification.SerializerTypeFullName, TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit, baseClass ); #if DEBUG Contract.Assert(this._typeBuilder.BaseType != null, "baseType != null"); #endif // DEBUG this._isDebuggable = isDebuggable; #if DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0 if (isDebuggable && SerializerDebugging.DumpEnabled) { SerializerDebugging.PrepareDump(host.Assembly as AssemblyBuilder); } #endif // DEBUG && !NET35 && !NETSTANDARD1_1 && !NETSTANDARD1_3 && !NETSTANDARD2_0 }
/// <summary> /// Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>. /// </summary> /// <param name="specification">The specification of the serializer.</param> /// <param name="baseClass">Type of the base class of the serializer.</param> /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns> public SerializerEmitter CreateObjectEmitter(SerializerSpecification specification, Type baseClass) { Contract.Requires(specification != null); Contract.Requires(baseClass != null); Contract.Ensures(Contract.Result <SerializerEmitter>() != null); return(new SerializerEmitter(this._module, specification, baseClass, this._isDebuggable)); }
/// <summary> /// Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>. /// </summary> /// <param name="context">The <see cref="SerializationContext"/>.</param> /// <param name="specification">The specification of the serializer.</param> /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns> public SerializerEmitter CreateEnumEmitter(SerializationContext context, SerializerSpecification specification) { Contract.Requires(context != null); Contract.Requires(specification != null); Contract.Ensures(Contract.Result <SerializerEmitter>() != null); return(new SerializerEmitter(context, this._module, specification, this._isDebuggable)); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that the unpacking collection value is not a collection. /// </summary> /// <param name="memberName">The name of the member.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewStreamDoesNotContainCollectionForMember(string memberName) { #if DEBUG Contract.Requires(!String.IsNullOrEmpty(memberName)); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot deserialize member '{0}' because the underlying stream does not contain collection.", memberName))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that target type is not serializable because it does not have public default constructor. /// </summary> /// <param name="type">The target type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> internal static Exception NewTargetDoesNotHavePublicDefaultConstructor(Type type) { #if !UNITY Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // !UNITY return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Type '{0}' does not have default (parameterless) public constructor.", type))); }
public static Exception NewTupleCardinarityIsNotMatch(int expectedTupleCardinality, int actualArrayLength) { #if DEBUG Contract.Requires(expectedTupleCardinality > 0); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}).", actualArrayLength, expectedTupleCardinality))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that operation is not supported because <paramref name="type"/> cannot be instanciated. /// </summary> /// <param name="type">Type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewNotSupportedBecauseCannotInstanciateAbstractType(Type type) { #if DEBUG Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new NotSupportedException(String.Format(CultureInfo.CurrentCulture, "This operation is not supported because '{0}' cannot be instanciated.", type))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that target collection type does not declare appropriate Add(T) method. /// </summary> /// <param name="type">The target type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewMissingAddMethod(Type type) { #if DEBUG Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Type '{0}' does not have appropriate Add method.", type))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that required field is not found on the unpacking stream. /// </summary> /// <param name="name">The name of the property.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewMissingProperty(string name) { #if DEBUG Contract.Requires(!String.IsNullOrEmpty(name)); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Property '{0}' is missing.", name))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that target type is not serializable because it does not have both of public default constructor and public constructor with an Int32 parameter. /// </summary> /// <param name="type">The target type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> internal static Exception NewTargetDoesNotHavePublicDefaultConstructorNorInitialCapacity(Type type) { #if DEBUG Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Type '{0}' does not have both of default (parameterless) public constructor and public constructor with an Int32 parameter.", type))); }
public static Exception NewMissingItem(int index) // For compatibility only. { #if DEBUG Contract.Requires(index >= 0); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new InvalidMessagePackStreamException(String.Format(CultureInfo.CurrentCulture, "Items at index '{0}' is missing.", index))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that value type cannot serialize. /// </summary> /// <param name="type">The target type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewTypeCannotSerialize(Type type) { #if !UNITY Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // !UNITY return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot serialize '{0}' type.", type))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that the member cannot be <c>null</c> or the unpacking value cannot be nil because nil value is explicitly prohibitted. /// </summary> /// <param name="memberName">The name of the member.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewNullIsProhibited(string memberName) { #if DEBUG Contract.Requires(!String.IsNullOrEmpty(memberName)); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "The member '{0}' cannot be nil.", memberName))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that value type cannot be <c>null</c> on deserialization. /// </summary> /// <param name="type">The target type.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewValueTypeCannotBeNull(Type type) { #if DEBUG Contract.Requires(type != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot be null '{0}' type value.", type))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that the unpacking value cannot be nil because the target member is read only and its type is collection. /// </summary> /// <param name="memberName">The name of the member.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewReadOnlyMemberItemsMustNotBeNull(string memberName) { #if DEBUG Contract.Requires(!String.IsNullOrEmpty(memberName)); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "The member '{0}' cannot be nil because it is read only member.", memberName))); }
/// <summary> /// Initializes a new instance of the <see cref="DataMemberContract"/> struct. /// </summary> /// <param name="member">The target member.</param> public DataMemberContract(MemberInfo member) { #if !UNITY Contract.Requires(member != null); #endif // !UNITY this._name = member.Name; this._nilImplication = NilImplication.MemberDefault; this._id = UnspecifiedId; }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that the unpacking array size is not expected length. /// </summary> /// <param name="expectedLength">Expected, required for deserialization array length.</param> /// <param name="actualLength">Actual array length.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewUnexpectedArrayLength(int expectedLength, int actualLength) { #if DEBUG Contract.Requires(expectedLength >= 0); Contract.Requires(actualLength >= 0); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "The MessagePack stream is invalid. Expected array length is {0}, but actual is {1}.", expectedLength, actualLength))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws an exception to notify that the array length does not match to expected tuple cardinality. /// </summary> /// <param name="expectedTupleCardinality">The expected cardinality of the tuple.</param> /// <param name="actualArrayLength">The actual serialized array length.</param> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static void ThrowTupleCardinarityIsNotMatch( int expectedTupleCardinality, long actualArrayLength, Unpacker unpacker ) { #if DEBUG Contract.Requires(expectedTupleCardinality > 0); #endif // DEBUG long offsetOrPosition = -1; bool isRealPosition = false; if (unpacker != null) { isRealPosition = unpacker.GetPreviousPosition(out offsetOrPosition); } if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at position {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at offset {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}).", actualArrayLength, expectedTupleCardinality ) ); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that value type cannot be <c>null</c> on deserialization. /// </summary> /// <param name="name">The name of the member.</param> /// <param name="memberType">The type of the member.</param> /// <param name="declaringType">The type that declares the member.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewValueTypeCannotBeNull(string name, Type memberType, Type declaringType) { #if DEBUG Contract.Requires(!String.IsNullOrEmpty(name)); Contract.Requires(memberType != null); Contract.Requires(declaringType != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Member '{0}' of type '{1}' cannot be null because it is value type('{2}').", name, declaringType, memberType))); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that it is failed to deserialize member. /// </summary> /// <param name="targetType">Deserializing type.</param> /// <param name="memberName">The name of the deserializing member.</param> /// <param name="inner">The exception which caused current error.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewFailedToDeserializeMember(Type targetType, string memberName, Exception inner) { #if DEBUG Contract.Requires(targetType != null); Contract.Requires(!String.IsNullOrEmpty(memberName)); Contract.Requires(inner != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // DEBUG return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot deserialize member '{0}' of type '{1}'.", memberName, targetType), inner)); }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Returns new exception to notify that value type cannot deserialize. /// </summary> /// <param name="type">The target type.</param> /// <param name="memberName">The name of deserializing member.</param> /// <param name="inner">The inner exception.</param> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static Exception NewTypeCannotDeserialize(Type type, string memberName, Exception inner) { #if !UNITY Contract.Requires(type != null); Contract.Requires(!String.IsNullOrEmpty(memberName)); Contract.Requires(inner != null); Contract.Ensures(Contract.Result <Exception>() != null); #endif // !UNITY return(new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot deserialize member '{1}' of type '{0}'.", type, memberName), inner)); }
/// <summary> /// Initializes a new instance of the <see cref="DataMemberContract"/> struct. /// </summary> /// <param name="member">The target member.</param> /// <param name="name">The name of member.</param> /// <param name="nilImplication">The implication of the nil value for the member.</param> /// <param name="id">The ID of the member. This value cannot be negative and must be unique in the type.</param> public DataMemberContract(MemberInfo member, string name, NilImplication nilImplication, int?id) { #if !UNITY Contract.Requires(member != null); #endif // !UNITY if (id < 0) { throw new SerializationException(String.Format(CultureInfo.CurrentCulture, "The member ID cannot be negative. The member is '{0}' in the '{1}' type.", member.Name, member.DeclaringType)); } this._name = String.IsNullOrEmpty(name) ? member.Name : name; this._nilImplication = nilImplication; this._id = id ?? UnspecifiedId; }
/// <summary> /// Initializes a new instance of the <see cref="DataMemberContract"/> struct from <see cref="MessagePackMemberAttribute"/>. /// </summary> /// <param name="member">The target member.</param> /// <param name="attribute">The MessagePack member attribute.</param> public DataMemberContract(MemberInfo member, MessagePackMemberAttribute attribute) { #if !UNITY Contract.Requires(member != null); Contract.Requires(attribute != null); #endif // !UNITY if (attribute.Id < 0) { throw new SerializationException(String.Format(CultureInfo.CurrentCulture, "The member ID cannot be negative. The member is '{0}' in the '{1}' type.", member.Name, member.DeclaringType)); } this._name = String.IsNullOrEmpty(attribute.Name) ? member.Name : attribute.Name; this._nilImplication = attribute.NilImplication; this._id = attribute.Id; }