An add setter Fody plugin.
Adds private setter to properties. To be used for example in combination with read-only properties in EF Core, that would otherwise not be mapped by convention. Read more in our blog post.
See also Fody usage.
Install the SpatialFocus.AddSetter.Fody NuGet package and update the Fody NuGet package:
PM> Install-Package Fody
PM> Install-Package SpatialFocus.AddSetter.Fody
The Install-Package Fody
is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.
Add <SpatialFocus.AddSetter/>
to FodyWeavers.xml
<Weavers>
<SpatialFocus.AddSetter/>
</Weavers>
Before code:
public class Person
{
public int Id { get; }
public string FirstName { get; }
public string LastName { get; }
}
What gets compiled
public class Person
{
public int Id { get; private set; }
public string FirstName { get; private set; }
public string LastName { get; private set; }
}
If no include or exclude namespaces are defined, all classes in the package are included by default. To change this behavior, add the following attribute to the SpatialFocus.AddSetter
node in FodyWeavers.
<Weavers>
<SpatialFocus.AddSetter DoNotIncludeByDefault='True'/>
</Weavers>
To include a specific class you can mark it with a AddSetter
. This works in both of the following cases, when either the DoNotIncludeByDefault
setting is turned on, or the namespace is excluded.
[AddSetter]
public class ClassToInclude
{
...
}
These config options are configured by modifying the SpatialFocus.AddSetter
node in FodyWeavers.xml
A list of namespaces to exclude.
Can take two forms.
As an element with items delimited by a newline.
<SpatialFocus.AddSetter>
<ExcludeNamespaces>
Foo
Bar
</ExcludeNamespaces>
</SpatialFocus.AddSetter>
Or as a attribute with items delimited by a pipe |
.
<SpatialFocus.AddSetter ExcludeNamespaces='Foo|Bar'/>
A list of namespaces to include.
Can take two forms.
As an element with items delimited by a newline.
<SpatialFocus.AddSetter>
<IncludeNamespaces>
Foo
Bar
</IncludeNamespaces>
</SpatialFocus.AddSetter>
Or as a attribute with items delimited by a pipe |
.
<SpatialFocus.AddSetter IncludeNamespaces='Foo|Bar'/>
Use *
at the beginning or at the end of an in- or exclude for wildcard matching.
To include the namespace and all sub-namespaces, simply define it like this:
<SpatialFocus.AddSetter>
<IncludeNamespaces>
Foo
Foo.*
</IncludeNamespaces>
</SpatialFocus.AddSetter>
You can combine excludes and includes, excludes overrule the includes if both match. But classes with an explicit [AddSetter]
attribute overrule the excludes.
Made with ❤️ by Spatial Focus