Created
February 25, 2011 18:17
-
-
Save codereflection/844226 to your computer and use it in GitHub Desktop.
Linq awesomeness for selecting items from a list by their domain name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Trade | |
| { | |
| public virtual int TradeId { get; set; } | |
| // some other fields... | |
| public virtual int? PrimaryOrOpposingIndicator { get; set; } | |
| public static Func<Trade, bool> isStreetSide = x => x.PrimaryOrOpposingIndicator == 1; | |
| public static Func<Trade, bool> isClientAllocation = x => x.PrimaryOrOpposingIndicator == 3; | |
| public static Func<Trade, bool> isBlockLevel = x => x.PrimaryOrOpposingIndicator == 4; | |
| public static Func<Trade, bool> isStreetSideOrBlockLevel = x => x.PrimaryOrOpposingIndicator == 1 || x.PrimaryOrOpposingIndicator == 4; | |
| public static Func<Trade, bool> isClientAllocationOrBlockLevel = x => x.PrimaryOrOpposingIndicator == 3 || x.PrimaryOrOpposingIndicator == 4; | |
| } | |
| public class TradeCalculator : ICalculate | |
| { | |
| public void Calculate(IEnumerable<Trade> trades) | |
| { | |
| trades.Where(Trade.isClientAllocationOrBlockLevel).Each(trade => | |
| { | |
| // perform some calculation here... | |
| }); | |
| } | |
| } |
Author
They're public (but should be readonly) because other classes, such as calculators, use them..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Those fields are public so you can change them, I presume? Like dynamically change how the class behaves?