|
View:
New views
19 Messages
—
Rating Filter:
Alert me
|
|
|
Suggestions for printing runtime C#I'm doing some work for an insurance company and have a cooky requirement that I've never dealt with. I'm hoping some people here have some ideas to share.
I need to write a rating engine, but they want the runtime execution code to be output for each rating so the business can read through the execution code for a given rating as a QC measure. This is very odd and makes little sense to me, but this is the requirement and there's nothing I can do but work with it. I've looked at reflection and don't see any way to dynamically write my execution code to a string/file at runtime. I considered trying T4 templates in some capacity, but I don't want to compile before each rating. Any ideas? |
|
|
Re: Suggestions for printing runtime C#Corey,
Are you generating somehow the code, i.e. using Expressions in C# 3.0, or using some table-driven method for determining what code to execute? There really isn't a realistic way that you can write out the C# code if it never was C# code to begin with, but if you are working with C# code to begin with, and you can abstract your "processing" interface so that you're injecting the "engine" as a dependency, you could theoretically build a composite that runs the steps and writes them in some "fake" C# code or pseudocode that the people can review as part of their QA process. If you're writing Expression trees to do the execution, then it would be pretty easy to walk the expression tree and write it in some "normalized C# code" that might be readable as well. I've used the first abstraction I referred to on several occasions to turn a file API into a code generator, or to turn a rules engine into a "trace" of the steps that got applied. I've never actually written out C# code because I never really felt that to be the best representation of business rules (for QA purposes) anyway. This might be a place where you try to ask the five why's and see if you can get to some core need and satisfy it in another way (in other words, wouldn't having a more business oriented trace of what's happening be more useful than seeing the exact trace of the C# code?). Kelly Corey Coogan <coreycoogan@...> Sent by: altdotnet@... 09/30/2009 11:40 AM Please respond to altdotnet@... To altdotnet@... cc Subject [altdotnet] Suggestions for printing runtime C# I'm doing some work for an insurance company and have a cooky requirement that I've never dealt with. I'm hoping some people here have some ideas to share. I need to write a rating engine, but they want the runtime execution code to be output for each rating so the business can read through the execution code for a given rating as a QC measure. This is very odd and makes little sense to me, but this is the requirement and there's nothing I can do but work with it. I've looked at reflection and don't see any way to dynamically write my execution code to a string/file at runtime. I considered trying T4 templates in some capacity, but I don't want to compile before each rating. Any ideas? ************************************************************************************** This communication is intended solely for the addressee and is confidential. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Unless indicated to the contrary: it does not constitute professional advice or opinions upon which reliance may be made by the addressee or any other party, and it should be considered to be a work in progress. Unless otherwise noted in this email or its attachments, this communication does not form a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. ************************************************************************************** |
|
|
Re: Suggestions for printing runtime C#Thanks Kelly,
this helps alot. I assume when you say C# expressions you are talking about Lambdas? I haven't written any code yet, so it's wide open at this point. It won't be table driven or code-generated, so I'd be interested in hearing how it would be easy to evaluate expression trees and dynamically write logic. I don't necessarily need exact C#, but what you described as "turn a rules engine into a "trace" of the steps that got applied" sounds like exactly what I need. I'm trying to avoid having to write code and also write some meta code to achieve my tracing. I guess I was hoping for an all-in-one solution. If you are willing to provide more detail into your solutions, I'd be a happy camper. Thanks, Corey --- In altdotnet@..., Kelly Leahy <kelly.leahy@...> wrote: > > Corey, > > Are you generating somehow the code, i.e. using Expressions in C# 3.0, or > using some table-driven method for determining what code to execute? > > There really isn't a realistic way that you can write out the C# code if > it never was C# code to begin with, but if you are working with C# code to > begin with, and you can abstract your "processing" interface so that > you're injecting the "engine" as a dependency, you could theoretically > build a composite that runs the steps and writes them in some "fake" C# > code or pseudocode that the people can review as part of their QA process. > > If you're writing Expression trees to do the execution, then it would be > pretty easy to walk the expression tree and write it in some "normalized > C# code" that might be readable as well. > > I've used the first abstraction I referred to on several occasions to turn > a file API into a code generator, or to turn a rules engine into a "trace" > of the steps that got applied. I've never actually written out C# code > because I never really felt that to be the best representation of business > rules (for QA purposes) anyway. > > This might be a place where you try to ask the five why's and see if you > can get to some core need and satisfy it in another way (in other words, > wouldn't having a more business oriented trace of what's happening be more > useful than seeing the exact trace of the C# code?). > > Kelly > > > > > Corey Coogan <coreycoogan@...> > > Sent by: altdotnet@... > 09/30/2009 11:40 AM > Please respond to > altdotnet@... > > > To > altdotnet@... > cc > > Subject > [altdotnet] Suggestions for printing runtime C# > > > > > > > > > > > I'm doing some work for an insurance company and have a cooky requirement > that I've never dealt with. I'm hoping some people here have some ideas > to share. > > I need to write a rating engine, but they want the runtime execution code > to be output for each rating so the business can read through the > execution code for a given rating as a QC measure. This is very odd and > makes little sense to me, but this is the requirement and there's nothing > I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write my > execution code to a string/file at runtime. I considered trying T4 > templates in some capacity, but I don't want to compile before each > rating. Any ideas? > > > > > > ************************************************************************************** > This communication is intended solely for the addressee and is > confidential. If you are not the intended recipient, any disclosure, > copying, distribution or any action taken or omitted to be taken in > reliance on it, is prohibited and may be unlawful. Unless indicated > to the contrary: it does not constitute professional advice or opinions > upon which reliance may be made by the addressee or any other party, > and it should be considered to be a work in progress. Unless otherwise > noted in this email or its attachments, this communication does not form > a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. > ************************************************************************************** > |
|
|
Re: Suggestions for printing runtime C#Compile the code at runtime as a dll. You only recompile when the code
changes, then you cache it, not compile everytime. Similar to how asp.net works Sent from my iPhone On 2009-09-30, at 20:40, Corey Coogan <coreycoogan@...> wrote: > I'm doing some work for an insurance company and have a cooky > requirement that I've never dealt with. I'm hoping some people here > have some ideas to share. > > I need to write a rating engine, but they want the runtime execution > code to be output for each rating so the business can read through > the execution code for a given rating as a QC measure. This is very > odd and makes little sense to me, but this is the requirement and > there's nothing I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write > my execution code to a string/file at runtime. I considered trying > T4 templates in some capacity, but I don't want to compile before > each rating. Any ideas? > > |
|
|
Re: Suggestions for printing runtime C#Thanks Greg. That's how I was thinking it would work to, but the code would be different for each rating since the variables that drive the rating would be different. The only reason I would consider the latebound compilation is to basically write the executable rating class and the readable output, hopefully by only writing one set of source code. I don't think it would get me what I want, unless you have some insight into something I may be missing.
corey --- In altdotnet@..., Greg Young <gregoryyoung1@...> wrote: > > Compile the code at runtime as a dll. You only recompile when the code > changes, then you cache it, not compile everytime. Similar to how asp.net > works > > Sent from my iPhone > > On 2009-09-30, at 20:40, Corey Coogan <coreycoogan@...> wrote: > > > I'm doing some work for an insurance company and have a cooky > > requirement that I've never dealt with. I'm hoping some people here > > have some ideas to share. > > > > I need to write a rating engine, but they want the runtime execution > > code to be output for each rating so the business can read through > > the execution code for a given rating as a QC measure. This is very > > odd and makes little sense to me, but this is the requirement and > > there's nothing I can do but work with it. > > > > I've looked at reflection and don't see any way to dynamically write > > my execution code to a string/file at runtime. I considered trying > > T4 templates in some capacity, but I don't want to compile before > > each rating. Any ideas? > > > > > |
|
|
Re: Suggestions for printing runtime C#Do they really want the raw code or would it sufficent to emit an
accountant-friendly pseudo-code description of the algorithm used along with the values of relevant parameters (rates, amounts, etc)? If the code must really be identical to the source used then you could extract the relevant algorithm (one function) and write it in a simple no nonsense language like Boo. Then at runtime load up the Boo compiler and run the routine. Make sure to cache it in memory for the lifetime of the process but there's not much need to save it across runs. Jeff On Sep 30, 2009, at 12:21 PM, Greg Young <gregoryyoung1@...> wrote: > > > Compile the code at runtime as a dll. You only recompile when the > code changes, then you cache it, not compile everytime. Similar to > how asp.net works > > Sent from my iPhone > > On 2009-09-30, at 20:40, Corey Coogan <coreycoogan@...> wrote: > >> I'm doing some work for an insurance company and have a cooky >> requirement that I've never dealt with. I'm hoping some people >> here have some ideas to share. >> >> I need to write a rating engine, but they want the runtime >> execution code to be output for each rating so the business can >> read through the execution code for a given rating as a QC >> measure. This is very odd and makes little sense to me, but this >> is the requirement and there's nothing I can do but work with it. >> >> I've looked at reflection and don't see any way to dynamically >> write my execution code to a string/file at runtime. I considered >> trying T4 templates in some capacity, but I don't want to compile >> before each rating. Any ideas? >> > > > |
|
|
Re: Re: Suggestions for printing runtime C#Corey,
I think a first start is to look at what you think you want your rule classes to look like and how you want to interact with them to get the "work" done of doing the rating (ignoring the tracing needs). Then, once you're there, we can talk about how to adjust / modify that design, and/or use other tools to instrument it for tracing (such as using PostSharp or some other AOP-like approach, or hand writing the tracing support, depending on which is more maintainable). Kelly "yerocdotnet" <coreycoogan@...> Sent by: altdotnet@... 09/30/2009 12:20 PM Please respond to altdotnet@... To altdotnet@... cc Subject [altdotnet] Re: Suggestions for printing runtime C# Thanks Kelly, this helps alot. I assume when you say C# expressions you are talking about Lambdas? I haven't written any code yet, so it's wide open at this point. It won't be table driven or code-generated, so I'd be interested in hearing how it would be easy to evaluate expression trees and dynamically write logic. I don't necessarily need exact C#, but what you described as "turn a rules engine into a "trace" of the steps that got applied" sounds like exactly what I need. I'm trying to avoid having to write code and also write some meta code to achieve my tracing. I guess I was hoping for an all-in-one solution. If you are willing to provide more detail into your solutions, I'd be a happy camper. Thanks, Corey --- In altdotnet@..., Kelly Leahy <kelly.leahy@...> wrote: > > Corey, > > Are you generating somehow the code, i.e. using Expressions in C# 3.0, or > using some table-driven method for determining what code to execute? > > There really isn't a realistic way that you can write out the C# code if > it never was C# code to begin with, but if you are working with C# code to > begin with, and you can abstract your "processing" interface so that > you're injecting the "engine" as a dependency, you could theoretically > build a composite that runs the steps and writes them in some "fake" C# > code or pseudocode that the people can review as part of their QA process. > > If you're writing Expression trees to do the execution, then it would be > pretty easy to walk the expression tree and write it in some "normalized > C# code" that might be readable as well. > > I've used the first abstraction I referred to on several occasions to turn > a file API into a code generator, or to turn a rules engine into a "trace" > of the steps that got applied. I've never actually written out C# code > because I never really felt that to be the best representation of business > rules (for QA purposes) anyway. > > This might be a place where you try to ask the five why's and see if you > can get to some core need and satisfy it in another way (in other words, > wouldn't having a more business oriented trace of what's happening be more > useful than seeing the exact trace of the C# code?). > > Kelly > > > > > Corey Coogan <coreycoogan@...> > > Sent by: altdotnet@... > 09/30/2009 11:40 AM > Please respond to > altdotnet@... > > > To > altdotnet@... > cc > > Subject > [altdotnet] Suggestions for printing runtime C# > > > > > > > > > > > I'm doing some work for an insurance company and have a cooky > that I've never dealt with. I'm hoping some people here have some ideas > to share. > > I need to write a rating engine, but they want the runtime execution code > to be output for each rating so the business can read through the > execution code for a given rating as a QC measure. This is very odd and > makes little sense to me, but this is the requirement and there's nothing > I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write my > execution code to a string/file at runtime. I considered trying T4 > templates in some capacity, but I don't want to compile before each > rating. Any ideas? > > > > > > > This communication is intended solely for the addressee and is > confidential. If you are not the intended recipient, any disclosure, > copying, distribution or any action taken or omitted to be taken in > reliance on it, is prohibited and may be unlawful. Unless indicated > to the contrary: it does not constitute professional advice or opinions > upon which reliance may be made by the addressee or any other party, > and it should be considered to be a work in progress. Unless otherwise > noted in this email or its attachments, this communication does not form > a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. > ************************************************************************************** > ************************************************************************************** This communication is intended solely for the addressee and is confidential. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Unless indicated to the contrary: it does not constitute professional advice or opinions upon which reliance may be made by the addressee or any other party, and it should be considered to be a work in progress. Unless otherwise noted in this email or its attachments, this communication does not form a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. ************************************************************************************** |
|
|
Re: Re: Suggestions for printing runtime C#It depends on how flexible the construction of a rating can be. Is it
only varing values of variables or can one insert arbitrary calculations? I remember a project where we had the latter. We had created a language in which one could create highlevel functions. From its as-tree we could create anything, from an interpreter that was used by the user to debug their functions, to c# dll that would be used to run the functions in 'release'-mode against millions of records. We used ANTLR to define and parse the language. I also remember debugging those generated dlls which gave a very surreal feeling to read the users functions as if written in c# ;) // Ryan |
|
|
Re: Suggestions for printing runtime C#I think either would suffice - pseudo or actual code. Whatever is easiest to implement. The biggest thing I'm trying to avoid is having to either duplicate execution code for logging or go through helper objects for my operators that do the logging.
--- In altdotnet@..., Corey Coogan <coreycoogan@...> wrote: > > I'm doing some work for an insurance company and have a cooky requirement that I've never dealt with. I'm hoping some people here have some ideas to share. > > I need to write a rating engine, but they want the runtime execution code to be output for each rating so the business can read through the execution code for a given rating as a QC measure. This is very odd and makes little sense to me, but this is the requirement and there's nothing I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write my execution code to a string/file at runtime. I considered trying T4 templates in some capacity, but I don't want to compile before each rating. Any ideas? > |
|
|
Re: Suggestions for printing runtime C#I would write some sort of expression generator. Something like:
interface IRule<T> { bool ShouldApply(T obj); Expression<Func<T,T>> Function { get; } } In my rule engine: var convert = ExpressionExtensions.Expand<Func<BusinessObject, decimal>>(obj=>obj.a*(obj.b/obj.c)); var result = ExpressionExtensions.Expand<Func<BusinessObject, BusinessObject>>(x=>x); var rules = Container.ResolveAll<IRule<BusinessObject>>(); foreach(var rule in rules) { if(rule.ShouldApply(obj)) { result = ExpressionExtensions.Expand<Func<BusinessObject, BusinessObject>>(x=>rule.Function.Invoke(result)); } } var finalResult = ExpressionExtensions.Expand<Func<BusinessObject,decimal>>(x=>convert.Invoke(result)); Console.WriteLine("Calculation: "+result.ToString()); Console.WriteLine("Result: " + result(obj)); (utilizing http://tomasp.net/blog/linq-expand.aspx) Depending on the complexity of the expressions and the requirements you could probably get away with an easier to read version: interface IRule<T> { bool ShouldApply(T obj); Expression<Func<decimal,decimal>> Function(T obj); } In my rule engine: var result = ExpressionExtensions.Expand<Func<decimal,decimal>>(x=>x); var rules = Container.ResolveAll<IRule<BusinessObject>>(); foreach(var rule in rules) { if(rule.ShouldApply(obj)) { result = ExpressionExtensions.Expand<Func<BusinessObject, BusinessObject>>(x=>rule.Function(obj).Invoke(result)); } } While the first version may wind up with something like: (new BusinessObject(new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new BusinessObject(obj.a,obj.b,obj.c),new BusinessObject(obj.a,obj.b,obj.c))).c)) the second could be: (obj.a+1)*((obj.b*2)/obj.c) Corey Coogan wrote: > > > I'm doing some work for an insurance company and have a cooky > requirement that I've never dealt with. I'm hoping some people here > have some ideas to share. > > I need to write a rating engine, but they want the runtime execution > code to be output for each rating so the business can read through the > execution code for a given rating as a QC measure. This is very odd > and makes little sense to me, but this is the requirement and there's > nothing I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write > my execution code to a string/file at runtime. I considered trying T4 > templates in some capacity, but I don't want to compile before each > rating. Any ideas? > > > > |
|
|
Re: Suggestions for printing runtime C#Sounds pretty slick Ryan. I don't need adhoc calculations, but I'm looking for a more sophisticated rating engine down the road, where rules are defined externally and compiled at run time, like you describe. For now, I just need to convert some outdated version into C# and give the same output values. It's a phase I thing right now.
--- In altdotnet@..., Ryan Heath <ryan.Q.heath@...> wrote: > > It depends on how flexible the construction of a rating can be. Is it > only varing values of variables or can one insert arbitrary > calculations? > > I remember a project where we had the latter. We had created a > language in which one could create highlevel functions. From its > as-tree we could create anything, from an interpreter that was used by > the user to debug their functions, to c# dll that would be used to run > the functions in 'release'-mode against millions of records. > We used ANTLR to define and parse the language. > > I also remember debugging those generated dlls which gave a very > surreal feeling to read the users functions as if written in c# ;) > > // Ryan > |
|
|
Re: Re: Suggestions for printing runtime C#I just realized I didn't really answer your pointed question.
When I said C# expressions I was talking about Expression<T> in System.Linq.Expressions. Basically, you can take a lambda and pass it as an expression, which is similar to a AST in a compiler, so you can walk the AST and make decisions / print the contents of the nodes / etc. in the process of walking the tree. The other nice thing is that you can compile (on the fly) the expressions and execute them, so that the work can actually be done by the code rather than you "interpreting" them. On the other hand, if you do need to interpret an AST-like data structure in order to apply your business rules, you're probably better off building your own, rather than using Expressions, because they are a bit limited in their scope (because they were designed with a particular purpose in mind) and a bit harder to work with than your own data structures would be (since you can customize yours precisely to your needs). It might be interesting to talk a bit about the "source" for these business rules and how you expect them to get "into" the system. You say it won't be codegened or table-driven, so does that mean you expect each business rule to be hand coded in C#? Are your business rules going to form some sort of "workflow" where you are basically executing something that looks like a flowchart built from custom classes that all implement some common interface? The answers to all these questions help guide how you do the instrumentation - for instance, if you're building a basic state-machine rules engine, then an obvious place to do the instrumentation is in the state machine "execution engine" itself, rather than in the rules themselves. Of course, you still need to rules (or some separate serializer would be better) to give you the information about "how" they're making their decisions (parameters, etc.). Kelly "yerocdotnet" <coreycoogan@...> Sent by: altdotnet@... 09/30/2009 12:20 PM Please respond to altdotnet@... To altdotnet@... cc Subject [altdotnet] Re: Suggestions for printing runtime C# Thanks Kelly, this helps alot. I assume when you say C# expressions you are talking about Lambdas? I haven't written any code yet, so it's wide open at this point. It won't be table driven or code-generated, so I'd be interested in hearing how it would be easy to evaluate expression trees and dynamically write logic. I don't necessarily need exact C#, but what you described as "turn a rules engine into a "trace" of the steps that got applied" sounds like exactly what I need. I'm trying to avoid having to write code and also write some meta code to achieve my tracing. I guess I was hoping for an all-in-one solution. If you are willing to provide more detail into your solutions, I'd be a happy camper. Thanks, Corey --- In altdotnet@..., Kelly Leahy <kelly.leahy@...> wrote: > > Corey, > > Are you generating somehow the code, i.e. using Expressions in C# 3.0, or > using some table-driven method for determining what code to execute? > > There really isn't a realistic way that you can write out the C# code if > it never was C# code to begin with, but if you are working with C# code to > begin with, and you can abstract your "processing" interface so that > you're injecting the "engine" as a dependency, you could theoretically > build a composite that runs the steps and writes them in some "fake" C# > code or pseudocode that the people can review as part of their QA process. > > If you're writing Expression trees to do the execution, then it would be > pretty easy to walk the expression tree and write it in some "normalized > C# code" that might be readable as well. > > I've used the first abstraction I referred to on several occasions to turn > a file API into a code generator, or to turn a rules engine into a "trace" > of the steps that got applied. I've never actually written out C# code > because I never really felt that to be the best representation of business > rules (for QA purposes) anyway. > > This might be a place where you try to ask the five why's and see if you > can get to some core need and satisfy it in another way (in other words, > wouldn't having a more business oriented trace of what's happening be more > useful than seeing the exact trace of the C# code?). > > Kelly > > > > > Corey Coogan <coreycoogan@...> > > Sent by: altdotnet@... > 09/30/2009 11:40 AM > Please respond to > altdotnet@... > > > To > altdotnet@... > cc > > Subject > [altdotnet] Suggestions for printing runtime C# > > > > > > > > > > > I'm doing some work for an insurance company and have a cooky > that I've never dealt with. I'm hoping some people here have some ideas > to share. > > I need to write a rating engine, but they want the runtime execution code > to be output for each rating so the business can read through the > execution code for a given rating as a QC measure. This is very odd and > makes little sense to me, but this is the requirement and there's nothing > I can do but work with it. > > I've looked at reflection and don't see any way to dynamically write my > execution code to a string/file at runtime. I considered trying T4 > templates in some capacity, but I don't want to compile before each > rating. Any ideas? > > > > > > > This communication is intended solely for the addressee and is > confidential. If you are not the intended recipient, any disclosure, > copying, distribution or any action taken or omitted to be taken in > reliance on it, is prohibited and may be unlawful. Unless indicated > to the contrary: it does not constitute professional advice or opinions > upon which reliance may be made by the addressee or any other party, > and it should be considered to be a work in progress. Unless otherwise > noted in this email or its attachments, this communication does not form > a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. > ************************************************************************************** > ************************************************************************************** This communication is intended solely for the addressee and is confidential. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Unless indicated to the contrary: it does not constitute professional advice or opinions upon which reliance may be made by the addressee or any other party, and it should be considered to be a work in progress. Unless otherwise noted in this email or its attachments, this communication does not form a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. ************************************************************************************** |
|
|
Re: Suggestions for printing runtime C#Thanks again Kelly,
I was thinking AOP for logging originally, but I'm not sure how I would get at the source code. I was looking at this differently - I need a handle on how to handle output as my design can make that easier or more difficult. As for the Expressions - this is what I thought you were talking about, but I wasn't sure how to get those to spit out their own code with variable values, etc. I guess that's something I could figure out later. I talked about grandios schemes of a rules engine, or buying one, to include workflow and a way to create externalized rules, etc. etc. etc. At this point, the business just wants C#, hand-coded rules. I was going to create a bunch of different specification class for each of the common scenarios and chain them together for the ratings. At least that was a thought before they sprung this code output requirement on me. --- In altdotnet@..., Kelly Leahy <kelly.leahy@...> wrote: > > I just realized I didn't really answer your pointed question. > > When I said C# expressions I was talking about Expression<T> in > System.Linq.Expressions. Basically, you can take a lambda and pass it as > an expression, which is similar to a AST in a compiler, so you can walk > the AST and make decisions / print the contents of the nodes / etc. in the > process of walking the tree. > > The other nice thing is that you can compile (on the fly) the expressions > and execute them, so that the work can actually be done by the code rather > than you "interpreting" them. On the other hand, if you do need to > interpret an AST-like data structure in order to apply your business > rules, you're probably better off building your own, rather than using > Expressions, because they are a bit limited in their scope (because they > were designed with a particular purpose in mind) and a bit harder to work > with than your own data structures would be (since you can customize yours > precisely to your needs). > > It might be interesting to talk a bit about the "source" for these > business rules and how you expect them to get "into" the system. You say > it won't be codegened or table-driven, so does that mean you expect each > business rule to be hand coded in C#? Are your business rules going to > form some sort of "workflow" where you are basically executing something > that looks like a flowchart built from custom classes that all implement > some common interface? The answers to all these questions help guide how > you do the instrumentation - for instance, if you're building a basic > state-machine rules engine, then an obvious place to do the > instrumentation is in the state machine "execution engine" itself, rather > than in the rules themselves. Of course, you still need to rules (or some > separate serializer would be better) to give you the information about > "how" they're making their decisions (parameters, etc.). > > Kelly > > > > > "yerocdotnet" <coreycoogan@...> > > Sent by: altdotnet@... > 09/30/2009 12:20 PM > Please respond to > altdotnet@... > > > To > altdotnet@... > cc > > Subject > [altdotnet] Re: Suggestions for printing runtime C# > > > > > > > > > > > Thanks Kelly, > this helps alot. I assume when you say C# expressions you are talking > about Lambdas? I haven't written any code yet, so it's wide open at this > point. > > It won't be table driven or code-generated, so I'd be interested in > hearing how it would be easy to evaluate expression trees and dynamically > write logic. I don't necessarily need exact C#, but what you described as > "turn a rules engine into a "trace" of the steps that got applied" sounds > like exactly what I need. > > I'm trying to avoid having to write code and also write some meta code to > achieve my tracing. I guess I was hoping for an all-in-one solution. > > If you are willing to provide more detail into your solutions, I'd be a > happy camper. > > Thanks, > Corey > > --- In altdotnet@..., Kelly Leahy <kelly.leahy@> wrote: > > > > Corey, > > > > Are you generating somehow the code, i.e. using Expressions in C# 3.0, > or > > using some table-driven method for determining what code to execute? > > > > There really isn't a realistic way that you can write out the C# code if > > > it never was C# code to begin with, but if you are working with C# code > to > > begin with, and you can abstract your "processing" interface so that > > you're injecting the "engine" as a dependency, you could theoretically > > build a composite that runs the steps and writes them in some "fake" C# > > code or pseudocode that the people can review as part of their QA > process. > > > > If you're writing Expression trees to do the execution, then it would be > > > pretty easy to walk the expression tree and write it in some "normalized > > > C# code" that might be readable as well. > > > > I've used the first abstraction I referred to on several occasions to > turn > > a file API into a code generator, or to turn a rules engine into a > "trace" > > of the steps that got applied. I've never actually written out C# code > > because I never really felt that to be the best representation of > business > > rules (for QA purposes) anyway. > > > > This might be a place where you try to ask the five why's and see if you > > > can get to some core need and satisfy it in another way (in other words, > > > wouldn't having a more business oriented trace of what's happening be > more > > useful than seeing the exact trace of the C# code?). > > > > Kelly > > > > > > > > > > Corey Coogan <coreycoogan@> > > > > Sent by: altdotnet@... > > 09/30/2009 11:40 AM > > Please respond to > > altdotnet@... > > > > > > To > > altdotnet@... > > cc > > > > Subject > > [altdotnet] Suggestions for printing runtime C# > > > > > > > > > > > > > > > > > > > > > > I'm doing some work for an insurance company and have a cooky > requirement > > that I've never dealt with. I'm hoping some people here have some ideas > > to share. > > > > I need to write a rating engine, but they want the runtime execution > code > > to be output for each rating so the business can read through the > > execution code for a given rating as a QC measure. This is very odd and > > makes little sense to me, but this is the requirement and there's > nothing > > I can do but work with it. > > > > I've looked at reflection and don't see any way to dynamically write my > > execution code to a string/file at runtime. I considered trying T4 > > templates in some capacity, but I don't want to compile before each > > rating. Any ideas? > > > > > > > > > > > > > ************************************************************************************** > > This communication is intended solely for the addressee and is > > confidential. If you are not the intended recipient, any disclosure, > > copying, distribution or any action taken or omitted to be taken in > > reliance on it, is prohibited and may be unlawful. Unless indicated > > to the contrary: it does not constitute professional advice or opinions > > upon which reliance may be made by the addressee or any other party, > > and it should be considered to be a work in progress. Unless otherwise > > noted in this email or its attachments, this communication does not form > > > a Statement of Actuarial Opinion under American Academy of Actuaries > guidelines. > > > ************************************************************************************** > > > > > > > > ************************************************************************************** > This communication is intended solely for the addressee and is > confidential. If you are not the intended recipient, any disclosure, > copying, distribution or any action taken or omitted to be taken in > reliance on it, is prohibited and may be unlawful. Unless indicated > to the contrary: it does not constitute professional advice or opinions > upon which reliance may be made by the addressee or any other party, > and it should be considered to be a work in progress. Unless otherwise > noted in this email or its attachments, this communication does not form > a Statement of Actuarial Opinion under American Academy of Actuaries guidelines. > ************************************************************************************** > |
|
|
Re: Suggestions for printing runtime C#Thanks for the advice here Bill. This is almost exactly what I was thinking, but you've given me some great things to think about.
Any idea how I could spit out execution path from this? I.e. State=WA, DualAirbags=true, Drivers=3.... --- In altdotnet@..., Bill Barry <after.fallout@...> wrote: > > I would write some sort of expression generator. Something like: > > interface IRule<T> { > bool ShouldApply(T obj); > Expression<Func<T,T>> Function { get; } > } > > In my rule engine: > var convert = ExpressionExtensions.Expand<Func<BusinessObject, > decimal>>(obj=>obj.a*(obj.b/obj.c)); > var result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>x); > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > foreach(var rule in rules) { > if(rule.ShouldApply(obj)) { > result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>rule.Function.Invoke(result)); > } > } > var finalResult = > ExpressionExtensions.Expand<Func<BusinessObject,decimal>>(x=>convert.Invoke(result)); > > Console.WriteLine("Calculation: "+result.ToString()); > Console.WriteLine("Result: " + result(obj)); > > (utilizing http://tomasp.net/blog/linq-expand.aspx) > > Depending on the complexity of the expressions and the requirements you > could probably get away with an easier to read version: > interface IRule<T> { > bool ShouldApply(T obj); > Expression<Func<decimal,decimal>> Function(T obj); > } > > In my rule engine: > var result = ExpressionExtensions.Expand<Func<decimal,decimal>>(x=>x); > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > foreach(var rule in rules) { > if(rule.ShouldApply(obj)) { > result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>rule.Function(obj).Invoke(result)); > } > } > > While the first version may wind up with something like: > (new BusinessObject(new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))).c)) > > > the second could be: > (obj.a+1)*((obj.b*2)/obj.c) > > Corey Coogan wrote: > > > > > > I'm doing some work for an insurance company and have a cooky > > requirement that I've never dealt with. I'm hoping some people here > > have some ideas to share. > > > > I need to write a rating engine, but they want the runtime execution > > code to be output for each rating so the business can read through the > > execution code for a given rating as a QC measure. This is very odd > > and makes little sense to me, but this is the requirement and there's > > nothing I can do but work with it. > > > > I've looked at reflection and don't see any way to dynamically write > > my execution code to a string/file at runtime. I considered trying T4 > > templates in some capacity, but I don't want to compile before each > > rating. Any ideas? > > > > > > > > > |
|
|
RE: Re: Suggestions for printing runtime C#Find a good business rules engine integrate it into your system...train your accountants how to use the language and be done with it ;)
From: altdotnet@... [mailto:altdotnet@...] On Behalf Of yerocdotnet Sent: Wednesday, September 30, 2009 4:53 PM To: altdotnet@... Subject: [altdotnet] Re: Suggestions for printing runtime C# Thanks for the advice here Bill. This is almost exactly what I was thinking, but you've given me some great things to think about. Any idea how I could spit out execution path from this? I.e. State=WA, DualAirbags=true, Drivers=3.... --- In altdotnet@...<mailto:altdotnet%40yahoogroups.com>, Bill Barry <after.fallout@...> wrote: > > I would write some sort of expression generator. Something like: > > interface IRule<T> { > bool ShouldApply(T obj); > Expression<Func<T,T>> Function { get; } > } > > In my rule engine: > var convert = ExpressionExtensions.Expand<Func<BusinessObject, > decimal>>(obj=>obj.a*(obj.b/obj.c)); > var result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>x); > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > foreach(var rule in rules) { > if(rule.ShouldApply(obj)) { > result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>rule.Function.Invoke(result)); > } > } > var finalResult = > ExpressionExtensions.Expand<Func<BusinessObject,decimal>>(x=>convert.Invoke(result)); > > Console.WriteLine("Calculation: "+result.ToString()); > Console.WriteLine("Result: " + result(obj)); > > (utilizing http://tomasp.net/blog/linq-expand.aspx) > > Depending on the complexity of the expressions and the requirements you > could probably get away with an easier to read version: > interface IRule<T> { > bool ShouldApply(T obj); > Expression<Func<decimal,decimal>> Function(T obj); > } > > In my rule engine: > var result = ExpressionExtensions.Expand<Func<decimal,decimal>>(x=>x); > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > foreach(var rule in rules) { > if(rule.ShouldApply(obj)) { > result = ExpressionExtensions.Expand<Func<BusinessObject, > BusinessObject>>(x=>rule.Function(obj).Invoke(result)); > } > } > > While the first version may wind up with something like: > (new BusinessObject(new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > BusinessObject(obj.a,obj.b,obj.c).a+1,new > BusinessObject(obj.a,obj.b,obj.c),new > BusinessObject(obj.a,obj.b,obj.c))).c)) > > > the second could be: > (obj.a+1)*((obj.b*2)/obj.c) > > Corey Coogan wrote: > > > > > > I'm doing some work for an insurance company and have a cooky > > requirement that I've never dealt with. I'm hoping some people here > > have some ideas to share. > > > > I need to write a rating engine, but they want the runtime execution > > code to be output for each rating so the business can read through the > > execution code for a given rating as a QC measure. This is very odd > > and makes little sense to me, but this is the requirement and there's > > nothing I can do but work with it. > > > > I've looked at reflection and don't see any way to dynamically write > > my execution code to a string/file at runtime. I considered trying T4 > > templates in some capacity, but I don't want to compile before each > > rating. Any ideas? > > > > > > > > > |
|
|
Re: Suggestions for printing runtime C#Agreed, that was my first thoughts to. But as you may know, corporate america is not known for its budgetary efficiency. They can pay a consultant thousands to write something but no budget to buy one. Go figure... I guess it means more for me!
--- In altdotnet@..., "Michael D. Brown" <mdbrown@...> wrote: > > Find a good business rules engine integrate it into your system...train your accountants how to use the language and be done with it ;) > > From: altdotnet@... [mailto:altdotnet@...] On Behalf Of yerocdotnet > Sent: Wednesday, September 30, 2009 4:53 PM > To: altdotnet@... > Subject: [altdotnet] Re: Suggestions for printing runtime C# > > > > Thanks for the advice here Bill. This is almost exactly what I was thinking, but you've given me some great things to think about. > > Any idea how I could spit out execution path from this? I.e. > > State=WA, DualAirbags=true, Drivers=3.... > > --- In altdotnet@...<mailto:altdotnet%40yahoogroups.com>, Bill Barry <after.fallout@> wrote: > > > > I would write some sort of expression generator. Something like: > > > > interface IRule<T> { > > bool ShouldApply(T obj); > > Expression<Func<T,T>> Function { get; } > > } > > > > In my rule engine: > > var convert = ExpressionExtensions.Expand<Func<BusinessObject, > > decimal>>(obj=>obj.a*(obj.b/obj.c)); > > var result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>x); > > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > > foreach(var rule in rules) { > > if(rule.ShouldApply(obj)) { > > result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>rule.Function.Invoke(result)); > > } > > } > > var finalResult = > > ExpressionExtensions.Expand<Func<BusinessObject,decimal>>(x=>convert.Invoke(result)); > > > > Console.WriteLine("Calculation: "+result.ToString()); > > Console.WriteLine("Result: " + result(obj)); > > > > (utilizing http://tomasp.net/blog/linq-expand.aspx) > > > > Depending on the complexity of the expressions and the requirements you > > could probably get away with an easier to read version: > > interface IRule<T> { > > bool ShouldApply(T obj); > > Expression<Func<decimal,decimal>> Function(T obj); > > } > > > > In my rule engine: > > var result = ExpressionExtensions.Expand<Func<decimal,decimal>>(x=>x); > > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > > foreach(var rule in rules) { > > if(rule.ShouldApply(obj)) { > > result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>rule.Function(obj).Invoke(result)); > > } > > } > > > > While the first version may wind up with something like: > > (new BusinessObject(new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new > > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new > > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))).c)) > > > > > > the second could be: > > (obj.a+1)*((obj.b*2)/obj.c) > > > > Corey Coogan wrote: > > > > > > > > > I'm doing some work for an insurance company and have a cooky > > > requirement that I've never dealt with. I'm hoping some people here > > > have some ideas to share. > > > > > > I need to write a rating engine, but they want the runtime execution > > > code to be output for each rating so the business can read through the > > > execution code for a given rating as a QC measure. This is very odd > > > and makes little sense to me, but this is the requirement and there's > > > nothing I can do but work with it. > > > > > > I've looked at reflection and don't see any way to dynamically write > > > my execution code to a string/file at runtime. I considered trying T4 > > > templates in some capacity, but I don't want to compile before each > > > rating. Any ideas? > > > > > > > > > > > > > > > |
|
|
Re: Re: Suggestions for printing runtime C#Only if you quit and the get yourself hired on again as a
consultant. :-) On Sep 30, 2009, at 4:10 PM, "yerocdotnet" <coreycoogan@...> wrote: > Agreed, that was my first thoughts to. But as you may know, > corporate america is not known for its budgetary efficiency. They > can pay a consultant thousands to write something but no budget to > buy one. Go figure... I guess it means more for me! > > --- In altdotnet@..., "Michael D. Brown" <mdbrown@...> > wrote: >> >> Find a good business rules engine integrate it into your >> system...train your accountants how to use the language and be done >> with it ;) >> >> From: altdotnet@... [mailto:altdotnet@...] >> On Behalf Of yerocdotnet >> Sent: Wednesday, September 30, 2009 4:53 PM >> To: altdotnet@... >> Subject: [altdotnet] Re: Suggestions for printing runtime C# >> >> >> >> Thanks for the advice here Bill. This is almost exactly what I was >> thinking, but you've given me some great things to think about. >> >> Any idea how I could spit out execution path from this? I.e. >> >> State=WA, DualAirbags=true, Drivers=3.... >> >> --- In altdotnet@...<mailto:altdotnet >> %40yahoogroups.com>, Bill Barry <after.fallout@> wrote: >>> >>> I would write some sort of expression generator. Something like: >>> >>> interface IRule<T> { >>> bool ShouldApply(T obj); >>> Expression<Func<T,T>> Function { get; } >>> } >>> >>> In my rule engine: >>> var convert = ExpressionExtensions.Expand<Func<BusinessObject, >>> decimal>>(obj=>obj.a*(obj.b/obj.c)); >>> var result = ExpressionExtensions.Expand<Func<BusinessObject, >>> BusinessObject>>(x=>x); >>> var rules = Container.ResolveAll<IRule<BusinessObject>>(); >>> foreach(var rule in rules) { >>> if(rule.ShouldApply(obj)) { >>> result = ExpressionExtensions.Expand<Func<BusinessObject, >>> BusinessObject>>(x=>rule.Function.Invoke(result)); >>> } >>> } >>> var finalResult = >>> ExpressionExtensions.Expand<Func<BusinessObject,decimal>> >>> (x=>convert.Invoke(result)); >>> >>> Console.WriteLine("Calculation: "+result.ToString()); >>> Console.WriteLine("Result: " + result(obj)); >>> >>> (utilizing http://tomasp.net/blog/linq-expand.aspx) >>> >>> Depending on the complexity of the expressions and the >>> requirements you >>> could probably get away with an easier to read version: >>> interface IRule<T> { >>> bool ShouldApply(T obj); >>> Expression<Func<decimal,decimal>> Function(T obj); >>> } >>> >>> In my rule engine: >>> var result = ExpressionExtensions.Expand<Func<decimal,decimal>> >>> (x=>x); >>> var rules = Container.ResolveAll<IRule<BusinessObject>>(); >>> foreach(var rule in rules) { >>> if(rule.ShouldApply(obj)) { >>> result = ExpressionExtensions.Expand<Func<BusinessObject, >>> BusinessObject>>(x=>rule.Function(obj).Invoke(result)); >>> } >>> } >>> >>> While the first version may wind up with something like: >>> (new BusinessObject(new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new >>> BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new >>> BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new >>> BusinessObject(obj.a,obj.b,obj.c),new >>> BusinessObject(obj.a,obj.b,obj.c))).c)) >>> >>> >>> the second could be: >>> (obj.a+1)*((obj.b*2)/obj.c) >>> >>> Corey Coogan wrote: >>>> >>>> >>>> I'm doing some work for an insurance company and have a cooky >>>> requirement that I've never dealt with. I'm hoping some people here >>>> have some ideas to share. >>>> >>>> I need to write a rating engine, but they want the runtime >>>> execution >>>> code to be output for each rating so the business can read >>>> through the >>>> execution code for a given rating as a QC measure. This is very odd >>>> and makes little sense to me, but this is the requirement and >>>> there's >>>> nothing I can do but work with it. >>>> >>>> I've looked at reflection and don't see any way to dynamically >>>> write >>>> my execution code to a string/file at runtime. I considered >>>> trying T4 >>>> templates in some capacity, but I don't want to compile before each >>>> rating. Any ideas? >>>> >>>> >>>> >>>> >>> >> > > > > > ------------------------------------ > > Yahoo! Groups Links > > > |
|
|
Re: Suggestions for printing runtime C#I am the consultant :))
Thanks for the ideas, cc --- In altdotnet@..., Jeff Brown <jeff.brown@...> wrote: > > Only if you quit and the get yourself hired on again as a > consultant. :-) > > > > On Sep 30, 2009, at 4:10 PM, "yerocdotnet" <coreycoogan@...> > wrote: > > > Agreed, that was my first thoughts to. But as you may know, > > corporate america is not known for its budgetary efficiency. They > > can pay a consultant thousands to write something but no budget to > > buy one. Go figure... I guess it means more for me! > > > > --- In altdotnet@..., "Michael D. Brown" <mdbrown@> > > wrote: > >> > >> Find a good business rules engine integrate it into your > >> system...train your accountants how to use the language and be done > >> with it ;) > >> > >> From: altdotnet@... [mailto:altdotnet@...] > >> On Behalf Of yerocdotnet > >> Sent: Wednesday, September 30, 2009 4:53 PM > >> To: altdotnet@... > >> Subject: [altdotnet] Re: Suggestions for printing runtime C# > >> > >> > >> > >> Thanks for the advice here Bill. This is almost exactly what I was > >> thinking, but you've given me some great things to think about. > >> > >> Any idea how I could spit out execution path from this? I.e. > >> > >> State=WA, DualAirbags=true, Drivers=3.... > >> > >> --- In altdotnet@...<mailto:altdotnet > >> %40yahoogroups.com>, Bill Barry <after.fallout@> wrote: > >>> > >>> I would write some sort of expression generator. Something like: > >>> > >>> interface IRule<T> { > >>> bool ShouldApply(T obj); > >>> Expression<Func<T,T>> Function { get; } > >>> } > >>> > >>> In my rule engine: > >>> var convert = ExpressionExtensions.Expand<Func<BusinessObject, > >>> decimal>>(obj=>obj.a*(obj.b/obj.c)); > >>> var result = ExpressionExtensions.Expand<Func<BusinessObject, > >>> BusinessObject>>(x=>x); > >>> var rules = Container.ResolveAll<IRule<BusinessObject>>(); > >>> foreach(var rule in rules) { > >>> if(rule.ShouldApply(obj)) { > >>> result = ExpressionExtensions.Expand<Func<BusinessObject, > >>> BusinessObject>>(x=>rule.Function.Invoke(result)); > >>> } > >>> } > >>> var finalResult = > >>> ExpressionExtensions.Expand<Func<BusinessObject,decimal>> > >>> (x=>convert.Invoke(result)); > >>> > >>> Console.WriteLine("Calculation: "+result.ToString()); > >>> Console.WriteLine("Result: " + result(obj)); > >>> > >>> (utilizing http://tomasp.net/blog/linq-expand.aspx) > >>> > >>> Depending on the complexity of the expressions and the > >>> requirements you > >>> could probably get away with an easier to read version: > >>> interface IRule<T> { > >>> bool ShouldApply(T obj); > >>> Expression<Func<decimal,decimal>> Function(T obj); > >>> } > >>> > >>> In my rule engine: > >>> var result = ExpressionExtensions.Expand<Func<decimal,decimal>> > >>> (x=>x); > >>> var rules = Container.ResolveAll<IRule<BusinessObject>>(); > >>> foreach(var rule in rules) { > >>> if(rule.ShouldApply(obj)) { > >>> result = ExpressionExtensions.Expand<Func<BusinessObject, > >>> BusinessObject>>(x=>rule.Function(obj).Invoke(result)); > >>> } > >>> } > >>> > >>> While the first version may wind up with something like: > >>> (new BusinessObject(new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new > >>> BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new > >>> BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > >>> BusinessObject(obj.a,obj.b,obj.c).a+1,new > >>> BusinessObject(obj.a,obj.b,obj.c),new > >>> BusinessObject(obj.a,obj.b,obj.c))).c)) > >>> > >>> > >>> the second could be: > >>> (obj.a+1)*((obj.b*2)/obj.c) > >>> > >>> Corey Coogan wrote: > >>>> > >>>> > >>>> I'm doing some work for an insurance company and have a cooky > >>>> requirement that I've never dealt with. I'm hoping some people here > >>>> have some ideas to share. > >>>> > >>>> I need to write a rating engine, but they want the runtime > >>>> execution > >>>> code to be output for each rating so the business can read > >>>> through the > >>>> execution code for a given rating as a QC measure. This is very odd > >>>> and makes little sense to me, but this is the requirement and > >>>> there's > >>>> nothing I can do but work with it. > >>>> > >>>> I've looked at reflection and don't see any way to dynamically > >>>> write > >>>> my execution code to a string/file at runtime. I considered > >>>> trying T4 > >>>> templates in some capacity, but I don't want to compile before each > >>>> rating. Any ideas? > >>>> > >>>> > >>>> > >>>> > >>> > >> > > > > > > > > > > ------------------------------------ > > > > Yahoo! Groups Links > > > > > > > |
|
|
RE: Re: Suggestions for printing runtime C#If you show them your estimate for building that portion yourself versus buying and integrating an existing framework, I think they'll see things your way. Of course if you're up for the challenge, you have enough time in the schedule, and you want the extra income, I say go for it :)
From: altdotnet@... [mailto:altdotnet@...] On Behalf Of yerocdotnet Sent: Wednesday, September 30, 2009 7:11 PM To: altdotnet@... Subject: [altdotnet] Re: Suggestions for printing runtime C# Agreed, that was my first thoughts to. But as you may know, corporate america is not known for its budgetary efficiency. They can pay a consultant thousands to write something but no budget to buy one. Go figure... I guess it means more for me! --- In altdotnet@...<mailto:altdotnet%40yahoogroups.com>, "Michael D. Brown" <mdbrown@...<mailto:mdbrown@...>> wrote: > > Find a good business rules engine integrate it into your system...train your accountants how to use the language and be done with it ;) > > From: altdotnet@...<mailto:altdotnet%40yahoogroups.com> [mailto:altdotnet@...<mailto:altdotnet%40yahoogroups.com>] On Behalf Of yerocdotnet > Sent: Wednesday, September 30, 2009 4:53 PM > To: altdotnet@...<mailto:altdotnet%40yahoogroups.com> > Subject: [altdotnet] Re: Suggestions for printing runtime C# > > > > Thanks for the advice here Bill. This is almost exactly what I was thinking, but you've given me some great things to think about. > > Any idea how I could spit out execution path from this? I.e. > > State=WA, DualAirbags=true, Drivers=3.... > > --- In altdotnet@...<mailto:altdotnet%40yahoogroups.com><mailto:altdotnet%40yahoogroups.com>, Bill Barry <after.fallout@> wrote: > > > > I would write some sort of expression generator. Something like: > > > > interface IRule<T> { > > bool ShouldApply(T obj); > > Expression<Func<T,T>> Function { get; } > > } > > > > In my rule engine: > > var convert = ExpressionExtensions.Expand<Func<BusinessObject, > > decimal>>(obj=>obj.a*(obj.b/obj.c)); > > var result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>x); > > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > > foreach(var rule in rules) { > > if(rule.ShouldApply(obj)) { > > result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>rule.Function.Invoke(result)); > > } > > } > > var finalResult = > > ExpressionExtensions.Expand<Func<BusinessObject,decimal>>(x=>convert.Invoke(result)); > > > > Console.WriteLine("Calculation: "+result.ToString()); > > Console.WriteLine("Result: " + result(obj)); > > > > (utilizing http://tomasp.net/blog/linq-expand.aspx) > > > > Depending on the complexity of the expressions and the requirements you > > could probably get away with an easier to read version: > > interface IRule<T> { > > bool ShouldApply(T obj); > > Expression<Func<decimal,decimal>> Function(T obj); > > } > > > > In my rule engine: > > var result = ExpressionExtensions.Expand<Func<decimal,decimal>>(x=>x); > > var rules = Container.ResolveAll<IRule<BusinessObject>>(); > > foreach(var rule in rules) { > > if(rule.ShouldApply(obj)) { > > result = ExpressionExtensions.Expand<Func<BusinessObject, > > BusinessObject>>(x=>rule.Function(obj).Invoke(result)); > > } > > } > > > > While the first version may wind up with something like: > > (new BusinessObject(new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)))).a*((new BusinessObject(new > > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))).b/(new BusinessObject(new > > BusinessObject(new BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c)),new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))*2,new BusinessObject(new > > BusinessObject(obj.a,obj.b,obj.c).a+1,new > > BusinessObject(obj.a,obj.b,obj.c),new > > BusinessObject(obj.a,obj.b,obj.c))).c)) > > > > > > the second could be: > > (obj.a+1)*((obj.b*2)/obj.c) > > > > Corey Coogan wrote: > > > > > > > > > I'm doing some work for an insurance company and have a cooky > > > requirement that I've never dealt with. I'm hoping some people here > > > have some ideas to share. > > > > > > I need to write a rating engine, but they want the runtime execution > > > code to be output for each rating so the business can read through the > > > execution code for a given rating as a QC measure. This is very odd > > > and makes little sense to me, but this is the requirement and there's > > > nothing I can do but work with it. > > > > > > I've looked at reflection and don't see any way to dynamically write > > > my execution code to a string/file at runtime. I considered trying T4 > > > templates in some capacity, but I don't want to compile before each > > > rating. Any ideas? > > > > > > > > > > > > > > > |
| Free embeddable forum powered by Nabble | Forum Help |