Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 19
Home
Object Analysis Toolkit (OAT) is a rules driven metaprogramming engine for arbitrary C# objects.
OAT is available on NuGet as Microsoft.CST.OAT.
OAT Blazor runs in your browser and allows you to Author Rules and test them in a Sandbox using Objects instantiated from your provided Assembly.
- Authoring Rules specifies how to create Rules for OAT.
- Delegates explores the extensibility points available in OAT via delegate declarations.
- Scripts covers usage of using Scripts directly embedded in your Rules.
Object Anaylsis Toolkit (OAT) is a meta-programming engine for processing objects using a run-time supplied Rule Set.
Rules contain a boolean Expression evaluated over the Clauses inside the rule. Each Clause performs a specified operation on the Target object's Field. See Authoring Rules for a detailed explanation of Rules and Clauses.
The simplest usage of OAT is to check if Rules apply to objects.
objecttarget;IEnumerable<Rule>rules;varanalyzer=newAnalyzer();varrulesWhichApply=analyzer.Analyze(rules,target);This sample from the the Walkthrough captures the weight of Overweight vehicles. It uses a two clause AND expression and a Custom OverweightOperation delegate.
varoverweightTruck=newVehicle(){Weight=30000,Capacity=20000,VehicleType=VehicleType.Truck};varoverweightCar=newVehicle(){Weight=6000,Capacity=5000,VehicleType=VehicleType.Car};varokayTruck=newVehicle(){Weight=20000,Capacity=20000,VehicleType=VehicleType.Truck};// Set up our Analyzer with the Custom Overweight Operation (see below)varanalyzer=newAnalyzer();analyzer.SetOperation(OverWeightOperation);// Collect the captures from Rules which applyvarres=analyzer.GetCaptures(rules,overweightTruck);// We get the First Rule capture and the First Clause Capture// Since this is our OverweightOperation on an int we know we should get back a TypedClauseCapture<int>varweight=((TypedClauseCapture<int>)res.First().Captures[0]).Result;// And we've captured the weight over the overweightTruckAssert.IsTrue(weight==30000);// The Rule doesn't apply to our Car and Truck that isn't overweightAssert.IsFalse(analyzer.Analyze(rules,overweightCar).Any());Assert.IsFalse(analyzer.Analyze(rules,okayTruck).Any());classVehicle{publicintWeight;publicintCapacity{get;set;}publicVehicleTypeVehicleType{get;internalset;}}enumVehicleType{Motorcycle,Car,Truck}varoverweightRule=newVehicleRule("Overweight Truck"){// Both clauses must be true for this Rule to applyExpression="Overweight AND IsTruck",Target="Vehicle",Clauses=newList<Clause>(){newClause(Operation.Custom){Label="Overweight",CustomOperation="OVERWEIGHT",Capture=true},newClause(Operation.Equals){Label="IsTruck",Data=newList<string>(){"Truck"}}}}OatOperationOverweightOperation=newOatOperation(Operation.Custom,analyzer){CustomOperation="OVERWEIGHT",OperationDelegate=OverweightOperationDelegate,ValidationDelegate=OverweightOperationValidationDelegate};publicOperationResultOverweightOperationDelegate(Clauseclause,object?state1,object?state2,IEnumerable<ClauseCapture>?captures){if(state1isVehiclevehicle){varres=vehicle.Weight>vehicle.Capacity;if((res&&!clause.Invert)||(clause.Invert&&!res)){// The rule applies and is true and the capture is available if capture is enabledreturnnewOperationResult(true,clause.Capture?newTypedClauseCapture<int>(clause,vehicle.Weight,state1,state2):null);}}returnnewOperationResult(false,null);}publicIEnumerable<Violation>OverweightOperationValidationDelegate(Ruler,Clausec){varviolations=newList<Violation>();if(r.Target!="Vehicle"){violations.Add(newViolation("Overweight operation requires a Vehicle object",r,c));}if(c.Data!=null||c.DictData!=null){violations.Add(newViolation("Overweight operation takes no data.",r,c));}returnviolations;}This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.