I have a class with many decimal properties which is used for financial calculation, there are rules that complete each number How many decimal places are used to use when doing so. There is no global rule - some are two decimal places, some 0, some 8, etc.
I am trying to find the easiest way to reach this. I want to spread the spherical logic all over my code. I know that I can write a custom setter for each property which rounds the value when specifying it.
It looks like I can do with a custom attribute. However, I have not written a custom attribute before, and I can not find a good example that I want to do just as I do, so I can bark the wrong tree.
Is this possible? If so, how is it a good example to approach?
If not, should any other methods consider me other than custom setter?
You can do this or with some other .NET-based AOP framework.
[serialable] public class golgling: attribute: onmathboundary aspect {public override eventArgs} {base.OnExit (eventArgs); EventArgs.ReturnValue = Math.Round ((dual) eventArgs.ReturnValue, 2); }} Class MyClass {public double notarized {get; Set; } Public Double Round ({rounding}); Set; }} Class program {static zero main (string [] args) {var c = new MyClass {round = 1.99999, notarited = 1.99 99}; Console.lightline ("round = {0}", c.ounded); // writes 2 console.light line ("not rounded = {0}", c.NotRounded); // writing 1.99999}}
No comments:
Post a Comment