Skip to content

Library for validating that .NET classes are serializable and deserialize with System.Runtime.Serialization.

License

Notifications You must be signed in to change notification settings

mikkelvalentinsorensen/MikValSor.SerializableValidator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library for validating that .NET types are serializable and deserialize with System.Runtime.Serialization.

Nuget package: https://www.nuget.org/packages/MikValSor.SerializableValidator

Example:

class MyClass
{
	public string Value;
}

[System.Serializable]
class MyOtherClass : System.Runtime.Serialization.ISerializable
{
	public string Value;

	public MyOtherClass()
	{
	}

	private MyOtherClass(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
	{
		Value = (string)info.GetValue("Value", typeof(string));
	}

	void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
	{
		info.AddValue("Value", Value, typeof(string));
	}
}

void Validate()
{
	var validator = new MikValSor.Runtime.Serialization.SerializableValidator();

	var myObject = new MyClass();
	bool isMyObjectImmutable = validator.IsSerializable(myObject);
	System.Console.WriteLine($"Is myObject serializable: {isMyObjectImmutable}");

	var myOtherObject = new MyOtherClass();
	bool isMyOtherObjectImmutable = validator.IsSerializable(myOtherObject);
	System.Console.WriteLine($"Is myOtherObject serializable: {isMyOtherObjectImmutable}");
}
/**
	Output:
	Is myObject serializable: False
	Is myOtherObject serializable: True
**/

About

Library for validating that .NET classes are serializable and deserialize with System.Runtime.Serialization.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages