Click here to Skip to main content
15,894,017 members
Articles / Programming Languages / C#

UniversalSerializer

Rate me:
Please Sign up or sign in to vote.
4.97/5 (108 votes)
15 Apr 2018Ms-RL31 min read 263K   4K   299  
An universal and easy serialization library for .NET and .NET Core.

// Copyright Christophe Bertrand.

namespace UniversalSerializerLib3
{
	/// <summary>
	/// Public error messages.
	/// </summary>
	public static class ErrorMessages
	{
		/// <summary>
		/// Error descriptor.
		/// </summary>
		public struct ErrorDescriptor
		{
			/// <summary>
			/// Unique error number.
			/// </summary>
			public int ErrorNumber;
			/// <summary>
			/// Short error description.
			/// </summary>
			public string Text;
		}

		/// <summary>
		/// List of errors.
		/// </summary>
		public static ErrorDescriptor[] Errors = new ErrorDescriptor[]
		{

			new ErrorDescriptor() { ErrorNumber=0,
				Text= "Not an error (very strange !!)." },

			new ErrorDescriptor() { ErrorNumber=1,
				Text= "This version of UniversalSerializer can not manage multi-dimensional arrays." },

			new ErrorDescriptor() { ErrorNumber=2,
				Text= "Unknown CustomFormatter." },

			new ErrorDescriptor() { ErrorNumber=3,
				Text= "Unknown CustomDeFormatter." },

			new ErrorDescriptor() { ErrorNumber=4,
				Text= "Can not set field '{0}'.'{1}' of type '{2}' with value '{3}' of type '{4}'" },

			new ErrorDescriptor() { ErrorNumber=5,
				Text= "Can not set property '{0}'.'{1}' of type '{2}' with value '{3}' of type '{4}'" },

			new ErrorDescriptor() { ErrorNumber=6,
				Text= "Type not found: \"{0}\"." },

			new ErrorDescriptor() { ErrorNumber=7,
				Text= "Unknown file version." },

			new ErrorDescriptor() { ErrorNumber=8,
				Text= "Type '{0}' (or one of its sub-data) is not serializable by BCL's BinaryFormatter. (suggestion: try to remove attribute [Serializable], or add an exploitable constructor)." },

			new ErrorDescriptor() { ErrorNumber=9,
				Text= "data is not a Primitive type" },

			new ErrorDescriptor() { ErrorNumber=10,
				Text= "Can not cast deserialized type \"{0}\" to wanted type \"{1}\"." },

			new ErrorDescriptor() { ErrorNumber=11,
				Text= "Construction (instanciation) of type \"{0}\" caused an error: {1}." },

			new ErrorDescriptor() { ErrorNumber=12,
				Text= "No exploitable constructor for type {0}" },

			new ErrorDescriptor() { ErrorNumber=13,
				Text= "Type {0} has no Add() method nor [Insert() method and Count get method], we can not set its items." },

			new ErrorDescriptor() { ErrorNumber=14,
				Text= "Type \"{0}\" can not be constructed because this parameter's type has been disallowed by a filter: Parameter's name=\"{1}\", Corresponding field's name=\"{2}\", Type=\"{3}\".\n\tSuggestion: use a filter to disallow the main type, or to allow the parameter's type." },

			new ErrorDescriptor() { ErrorNumber=15,
				Text= "The type '{0}' uses {1} as TypeConverter, but it does not convert to string correctly. Please investigate or contact the type's author." },

			new ErrorDescriptor() { ErrorNumber=16,
				Text= "The type '{0}' uses {1} as TypeConverter, but its transcoding type is unknown. Please investigate or contact the type's author." },

			new ErrorDescriptor() { ErrorNumber=17,
				Text= "Listed assembly in stream can not be loaded: \"{0}\". Error={1}" },

			new ErrorDescriptor() { ErrorNumber=18,
				Text= "Warning: DateTimeKind has more than 4 items now. That will cause problems in DateTimes. See ToTicksAndKind()." },

			new ErrorDescriptor() { ErrorNumber=19,
				Text= "Type {0} can not be deserialized because of 1) an error in its Container and 2) a refused private field." },

            new ErrorDescriptor() { ErrorNumber=20,
				Text= "(internal) Can not create a TypeManager for type {0}." },

            new ErrorDescriptor() { ErrorNumber=21,
				Text= "Silverlight does not allow creation of a TypeManager for private type {0}." },
		};

		/// <summary>
		/// Get a short error description from its number.
		/// </summary>
		/// <param name="ErrorNumber"></param>
		/// <returns></returns>
		public static string GetText(int ErrorNumber)
		{
			return string.Format("Error {0} : {1}", ErrorMessages.Errors[ErrorNumber].ErrorNumber.ToString(), ErrorMessages.Errors[ErrorNumber].Text);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under Microsoft Reciprocal License


Written By
Software Developer (Senior) independent
France France
Hi !

I made my first program on a Sinclair ZX-81.
Since that day, I have the virus of computers. Smile | :)

Here is my website:
https://chrisbertrand.net

And my blog:
https://chrisbertrandprogramer.wordpress.com/

Comments and Discussions