.NET library to mock object properties with attributes.
I initially designed this library for writing tests for Command Line Parser Library. Although it's main purpose is testing, it can be helpful in the scope of dynamic programming.
- .NET Standard 2.0
- .NET Framework 4.6.1
$ dotnet add package Tagger.Reflect --version 1.6.9-beta
The latest stable version is 1.0.3.
interface IMyInterface
{
string Foo { get; set; }
int Bar { get; set; }
bool Baz { get; set; }
}
// define an anonymous template limited to target properties
var mirror = new Mirror(new { Foo = default(string) })
.Implement<IMyInterface>()
.Add(x => x.ForProperty("Foo")
.Define<MyAttribute>()
.AttributeCtor(new { index = 0 })
// define an anonymous instance for each attribute
// property to set
.AttributeProperty(new { Dir = "/etc/app" })
.AttributeProperty(new { Config = "file.dat" });
var instance = mirror.Unwrap<IMyInterface>();
// instance layout:
// class anonymous : IMyInterface {
// ...
// [MyAttribute(0, Dir = "/etc/app", Config = "file.dat")]
// public string Foo { get; set; }
// ...
// }
See this unit test for more examples.
- New fluent interface.
- Tests refactoring.
- New tests.
Tag icon designed by Eucalyp from The Noun Project.