//✔️ from 0.1 // V is a static extension method var visitor = o.V();
//✔️ from 0.1 // create visitor from factory method var visitor = typeof(Yueluo).V();
//✔️ from 0.1 // create and fire way. // this is the most simple structure about this lib // there are Name, Value, PropertyInfo, SourceObj, SourceObjType and etc in the context o.V().ForEach((context)=>{}).Run(); o.V().ForEach((name,value)=>{}).Run();
//✔️ from 0.1 // create a visitor with extend object as parameter o.V().WithExtendObject<Yueluo, StringBuilder>() .ForEach((context)=>{var _ = context.ExtendObject}) .Run(new StringBuilder()); o.V().WithExtendObject<Yueluo, StringBuilder>() .ForEach((name,value,stringBuilder)=>{}) .Run(new StringBuilder());
//✔️ from 0.1 // create and cache way. This is suggested way to use. // cache object visitor to run it with anothor object var cachedVisitor = deafult(Yueluo).V().ForEach((context)=>{}).Cache(); cachedVisitor.Run(new Yueluo());
//✔️ from 0.1 // cache object visitor with extend object var cachedVisitor = deafult(Yueluo).V() .WithExtendObject<Yueluo, StringBuilder>() .ForEach((context)=>{var _ = context.ExtendObject}) .Cache(); cachedVisitor.Run(new Yueluo(), new StringBuilder());
//🚧 you can modify value if return a new value o.V().ForEach((context)=>context.Value.SubString(0,1)).Run();
//✔️ from 0.1 // get debug info about expression now var debugInfo = o.V().ForEach((context)=>{}).GetDebugInfo();
//🚧 generate code in C# as a string about expression now var code = o.V().ForEach((context)=>{}).GenerateCode();
//✔️ from 0.1 // generate a lambda func var func = o.V().ForEach((context)=>{}).GetLambda();
//🚧 foreach properties with specified type o.V().ForEach<string>((context)=>{}).Run();
//🚧 using linq to filter o.V().AsEnumerable().Where((context)=>context.Name == "YueLuo").ForEach((context)=>{}).Run();
//🚧 suppending visiting sub object o.V().SuppendSubObject().ForEach((context)=>{}).Run();
/** ✔️ from 0.1 sample to join all properties to string */ var sb = new StringBuilder(); o.V().ForEach((context)=>{ sb.Append(context.Name); sb.Append(context.Value); sb.Append(Enviroment.Newline); }).Run(); var s = sb.ToString();
//✔️ from 0.1 // quick style for above var s = o.FormatString();
//🚧 Deconstruct as C# 7 but more flexible var destructor1 = Destructor<Yueluo> .Property(x=>x.Name) .Property(x=>x.Age)
var destructor2 = Destructor<Yueluo> .Property(x=>x.Name) .Property(x=>(long)x.Age)
var destructor3 = Destructor<Yueluo> .Property(x=>x.Name) .Property(x=>x.NickName) .Property(x=>x.Age)
var (name, age) = o.V().Destruct(destructor1).Run(); var (name, ageInLong) = o.V().Destruct(destructor2).Run(); var (name, nickName, age) = o.V().Destruct(destructor3).Run();
// namespace for operation with collections using Newbe.ObjectVisitor.Collections;
/** 🚧collect properties into a dictionary */
var dic1 = o.V().CollectAsDictionary().Run(); // quick style for above var dic1 = o.V().ToDictionary();
/** 🚧apply value from a dictionary to object */ o.V().ApplyFromDictionary(dic).Run(); // quick style for above o.V().FromDictionary(dic);
// namespace for data validation using Newbe.ObjectVisitor.Validation;
// 🚧create rule to validation var rule = ValidateRule<Yueluo> .GetBuilder() .Property(x=>x.Name).Required().Length(2,10) .Property(x=>x.Age).Range(0, int.MaxValue) .Property(x=>x.Password).Validate(value=>ValidatePassword(value)) .Property(x=>x.Level).Validate(value=>value + 1 >= 0) .Build();
o.V().Validate(rule).Run(); o.Validate(rule);
// 🚧validate data in flunet api // attribute-based enabled by default o.V().Validate(v=> v .Property(x=>x.Name).Required().Length(2,10) .Property(x=>x.Age).Range(0, int.MaxValue) .Property(x=>x.Password).Validate(value=>ValidatePassword(value)) .Property(x=>x.Level).Validate(value=>value + 1 >= 0) ).Run();
// namespace for Microsoft.Extensions.DependencyInjection using Newbe.ObjectVistory.DepencyInjection;
// 🚧inject services to the properties of this object this.V().ForEach(context=>this.ServiceProvider.GetService(context.PropertyInfo.PorpertyType)).Run();
// 🚧quick style for above this.V().PropertyInject(this.ServiceProvider);