MikValSor.EnsuredImmutable 1.0.2

Package Description

Install-Package MikValSor.EnsuredImmutable -Version 1.0.2
dotnet add package MikValSor.EnsuredImmutable --version 1.0.2
<PackageReference Include="MikValSor.EnsuredImmutable" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MikValSor.EnsuredImmutable --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Library build on top of MikValSor.ImmutableValidator that encapsulated immutable objects ensured types for to ease development and minimize redundant validation check.

Example:

class MyClass
{
	public string Value;
}

class MyOtherClass
{
	public readonly string Value;
	public MyOtherClass(string value)
	{
		Value = value;
	}
}

void Example()
{
	//Muttable
	var myObject = new MyClass { Value = "Value" };
	try
	{
		MikValSor.Immutable.EnsuredImmutable<MyClass> myEnsuredObject = MikValSor.Immutable.EnsuredImmutable.Create(myObject);
	}
	catch (MikValSor.Immutable.NotImmutableException)
	{
		System.Console.WriteLine($"myObject is mutable.");
	}

	//Immutable
	var myOtherObject = new MyOtherClass("Value");
	MikValSor.Immutable.EnsuredImmutable<MyOtherClass> myOtherEnsuredObject = MikValSor.Immutable.EnsuredImmutable.Create(myOtherObject);
	System.Console.WriteLine($"myOtherEnsuredObject is immutable.");

	System.Console.WriteLine($"myOtherEnsuredObject.Value: {myOtherEnsuredObject.Value}");

	//Using extensions (using MikValSor.Immutable.Extensions)
	MikValSor.Immutable.EnsuredImmutable<MyOtherClass> myOtherEnsuredObject2 = myOtherObject.EnsureImmutable();
	System.Console.WriteLine($"myOtherEnsuredObject2.Value: {myOtherEnsuredObject2.Value}");
}
/**
	Output:
	myObject is mutable.
	myOtherEnsuredObject is immutable.
	myOtherEnsuredObject.Value: MyOtherClass
	myOtherEnsuredObject2.Value: MyOtherClass
**/

Library build on top of MikValSor.ImmutableValidator that encapsulated immutable objects ensured types for to ease development and minimize redundant validation check.

Example:

class MyClass
{
	public string Value;
}

class MyOtherClass
{
	public readonly string Value;
	public MyOtherClass(string value)
	{
		Value = value;
	}
}

void Example()
{
	//Muttable
	var myObject = new MyClass { Value = "Value" };
	try
	{
		MikValSor.Immutable.EnsuredImmutable<MyClass> myEnsuredObject = MikValSor.Immutable.EnsuredImmutable.Create(myObject);
	}
	catch (MikValSor.Immutable.NotImmutableException)
	{
		System.Console.WriteLine($"myObject is mutable.");
	}

	//Immutable
	var myOtherObject = new MyOtherClass("Value");
	MikValSor.Immutable.EnsuredImmutable<MyOtherClass> myOtherEnsuredObject = MikValSor.Immutable.EnsuredImmutable.Create(myOtherObject);
	System.Console.WriteLine($"myOtherEnsuredObject is immutable.");

	System.Console.WriteLine($"myOtherEnsuredObject.Value: {myOtherEnsuredObject.Value}");

	//Using extensions (using MikValSor.Immutable.Extensions)
	MikValSor.Immutable.EnsuredImmutable<MyOtherClass> myOtherEnsuredObject2 = myOtherObject.EnsureImmutable();
	System.Console.WriteLine($"myOtherEnsuredObject2.Value: {myOtherEnsuredObject2.Value}");
}
/**
	Output:
	myObject is mutable.
	myOtherEnsuredObject is immutable.
	myOtherEnsuredObject.Value: MyOtherClass
	myOtherEnsuredObject2.Value: MyOtherClass
**/

Release Notes

v1.0.2
- Fixed missing documentation

v1.0.1
- Upgraded to v1.0.9 of ImmutableValidator and utilize its singleton.
- Added EnsuredImmutableAndSerializable<T>

v1.0.0
- Initial release

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.2 3,509 5/22/2018
1.0.1 314 5/22/2018
1.0.0 301 5/17/2018