Created
May 21, 2013 11:24
-
-
Save davepermen/5619143 to your computer and use it in GitHub Desktop.
This file contains 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
// your code, shortened | |
public class FilterFactory | |
{ | |
public Expression<Func<Message, bool>> Filter(FilterGroupParameter filterGroupParameter) | |
{ | |
var factory = FiltererFactoryFactory.Get(filterGroupParameter.Key); | |
return factory.Get(filterGroupParameter); | |
} | |
} | |
// my code, and you'll going to hate me for it.. | |
interface IFiltererFactory | |
{ | |
Expression<Func<Message, bool>> Get(FilterGroupParameter param); | |
} | |
class FiltererFactoryFactory | |
{ | |
public static IFiltererFactory Get(FilterParameterKeysEnum bla) | |
{ | |
switch (bla) | |
{ | |
case FilterParameterKeysEnum.Content: | |
return new ContentFilterFactory(); | |
case FilterParameterKeysEnum.FeedId: | |
return new FeedIdFilterFactory(); | |
} | |
throw new NotImplementedException(); | |
} | |
} | |
class ContentFilterFactory : IFiltererFactory | |
{ | |
public Expression<Func<Message, bool>> Get(FilterGroupParameter param) | |
{ | |
var contentFilter = Filterer.Get(param.Key, message => message.Body, null); | |
return contentFilter.FilterString(param.Value); | |
} | |
} | |
class FeedIdFilterFactory : IFiltererFactory | |
{ | |
public Expression<Func<Message, bool>> Get(FilterGroupParameter param) | |
{ | |
var feedidFilter = Filterer.Get(param.Operator, null, message => message.TeamFeedId); | |
return feedidFilter.FilterInt(int.Parse(param.Value)); | |
} | |
} | |
// some temp fakes to make code work, partially.. | |
public struct FilterGroupParameter | |
{ | |
public FilterParameterKeysEnum Key; | |
public FilterParameterOperatorEnum Operator; | |
public string Value; | |
} | |
public enum FilterParameterKeysEnum | |
{ | |
Content, | |
FeedId | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment