C# toolkit Newbe.ObjectVisitor 0.3.7 released, automatically generate FluentAPI

Newbe.Claptrap 0.3.7 is released, and FluentAPI is automatically generated.

update content

Originally, we hoped to introduce one of mapper or validation in 0.3. But we found that we need to complete a higher level of abstraction to better carry out the follow-up work.

therefore. In version 0.3, we have completed a cool and novel feature that is both thought-provoking and full of joy:

Automatically generate any designed FluentAPI based on the state diagram.

The detailed description is very long and can be viewed by referring to the following article:

" I drew a picture, and FluentAPI generated it by herself "

project instruction

Newbe.ObjectVisitor helps developers to access all the attributes of an ordinary class in the simplest and most efficient way. So as to achieve: verification, mapping, collection and other operations.

For example, there is such a simple class in your code.

var order = new OrderInfo();

You want to print out all the attributes and values ​​of this class, then you can use reflection to complete:

for(var pInfo in typeof(OrderInfo).GetProperties())
{
    Console.Writeline($"{pInfo.Name}: {pInfo.GetValue(order)}");
}

If you use this library, you can use the following methods to achieve the same effect:

// call .V what is a static extension method
// you get a visitor object for order
var visitor = order.V();

visitor.ForEach(context=>{
    var name = context.Name;
    var value = context.Value;
    Console.Writeline($"{name}: {value}");
}).Run();

// you can also make it into one line
order.V().ForEach(c=> Console.Writeline($"{c.Name}: {c.Value}")).Run();

// or using quick style
order.FormatToString();

Then why should I do this?

  • Because it's faster! This library is implemented using expression trees , so it has 10 times faster performance than using reflection directly.
  • Because it is more readable! Through this library, you can use chain API and naming methods to create a delegate, so that your code can achieve the same readable effect as hard-coded.
  • Because it is more scalable! If you use this class library, you have an easy way to access all the properties of a class. Therefore, you do a lot of things you want to do, such as: create a validator to verify your model, modify some attributes that may contain sensitive data to avoid output to the log, create an object mapper similar to AutoMapper but have Better performance, and so on.

GitHub project address: https://github.com/newbe36524/Newbe.ObjectVisitor

Gitee project address: https://gitee.com/yks/Newbe.ObjectVisitor

Newbe.ObjectVisitor

Guess you like

Origin www.oschina.net/news/120761/newbe-objectvisitor-0-3-7-released