Skip to content

Instantly share code, notes, and snippets.

@codereflection
Created February 25, 2011 18:17
Show Gist options
  • Select an option

  • Save codereflection/844226 to your computer and use it in GitHub Desktop.

Select an option

Save codereflection/844226 to your computer and use it in GitHub Desktop.
Linq awesomeness for selecting items from a list by their domain name
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...
});
}
}
@codereflection

Copy link
Copy Markdown
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