Created
January 12, 2011 18:25
-
-
Save robashton/776607 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
public static IEngineConfigurationTypeBuilder<TPoco> Collection<TPoco, TCollection>( | |
this IEngineConfigurationTypeMemberBuilder<TPoco, TCollection> memberConfig, int min, int max) where TCollection : IEnumerable | |
{ | |
var collectionType = typeof (TCollection); | |
// Nefarious, I know - shocking, this will get is Y from X<Y> where X = IEnumerable/List/Etc and Y = Type | |
// So List<Y> etc | |
var genericcollectionArgument = collectionType.GetGenericArguments()[0]; | |
// So this will give us AutoSource<Y> | |
var autoSourceType = typeof (AutoSource<>).MakeGenericType(genericcollectionArgument); | |
//// And this will give us FlexibleEnumerableSource<AutoSource<Y>, X<Y>, Y> | |
var enumerableSourceType = typeof (FlexibleEnumerableSource<,,>).MakeGenericType( | |
autoSourceType, collectionType, genericcollectionArgument | |
); | |
// I can't believe I'm doing this, if anybody can give us a good method definition that just_works and | |
// negates the need for this tomfoolery I'm all ears | |
var method = memberConfig.GetType().GetMethod("Use", | |
System.Reflection.BindingFlags.Public | | |
System.Reflection.BindingFlags.Instance, null, new[] { typeof(Object[]) }, null); | |
var genericMethod = method.MakeGenericMethod(new[] {enumerableSourceType}); | |
return (IEngineConfigurationTypeBuilder<TPoco>)genericMethod.Invoke(memberConfig, new object[] { new object[] { min, max}}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment