Skip to content

Instantly share code, notes, and snippets.

@davepermen
Created May 21, 2013 11:24
Show Gist options
  • Save davepermen/5619141 to your computer and use it in GitHub Desktop.
Save davepermen/5619141 to your computer and use it in GitHub Desktop.
// 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