https://github.com/gsscoder/tagger
.NET library to mock object properties with attributes
https://github.com/gsscoder/tagger
csharp dotnet dotnet-core library mocking testing
Last synced: 4 months ago
JSON representation
.NET library to mock object properties with attributes
- Host: GitHub
- URL: https://github.com/gsscoder/tagger
- Owner: gsscoder
- License: mit
- Created: 2015-07-12T12:57:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-06-25T14:17:12.000Z (over 5 years ago)
- Last Synced: 2025-08-23T13:46:34.935Z (4 months ago)
- Topics: csharp, dotnet, dotnet-core, library, mocking, testing
- Language: C#
- Homepage:
- Size: 626 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://nuget.org/packages/tagger.reflect)
[](https://nuget.org/packages/tagger.reflect)
#
Tagger.Reflect
.NET library to mock object properties with attributes.
## What is for?
I initially designed this library for writing tests for [Command Line Parser Library](https://github.com/commandlineparser/commandline). Although it's main purpose is testing, it can be helpful in the scope of dynamic programming.
## Targets
- .NET Standard 2.0
- .NET Framework 4.6.1
## Install via NuGet
```sh
$ dotnet add package Tagger.Reflect --version 1.6.9-beta
```
The latest stable version is [1.0.3](https://github.com/gsscoder/tagger/tree/v1.0.3).
## At a glance
```csharp
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()
.Add(x => x.ForProperty("Foo")
.Define()
.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();
// instance layout:
// class anonymous : IMyInterface {
// ...
// [MyAttribute(0, Dir = "/etc/app", Config = "file.dat")]
// public string Foo { get; set; }
// ...
// }
```
See this [unit test](https://github.com/gsscoder/tagger/blob/master/tests/Tagger.Reflect.Tests/Unit/MirrorTests.cs) for more examples.
## Latest Changes
- New fluent interface.
- Tests refactoring.
- New tests.
## Icon
[Tag](https://thenounproject.com/search/?q=tagger&i=3051269) icon designed by Eucalyp from [The Noun Project](https://thenounproject.com/).