This is an add-in for Fody
Implements the Freezable pattern
See also Fody usage.
Install the Freezable.Fody NuGet package and update the Fody NuGet package:
PM> Install-Package Fody
PM> Install-Package Freezable.Fody
The Install-Package Fody
is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.
Add <Freezable/>
to FodyWeavers.xml
<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
<Freezable/>
</Weavers>
public interface IFreezable
{
void Freeze();
}
public class Person : IFreezable
{
bool isFrozen;
public string Name { get; set; }
public void Freeze()
{
isFrozen = true;
}
}
public class Person : IFreezable
{
volatile bool isFrozen;
public void Freeze()
{
isFrozen = true;
}
void CheckIfFrozen()
{
if (isFrozen)
{
throw new InvalidOperationException("Attempted to modify a frozen instance");
}
}
string name;
public string Name
{
get { return name; }
set
{
CheckIfFrozen();
name = value;
}
}
}
Icon courtesy of The Noun Project