# HG changeset patch # User Steven Robbins # Date 1295098122 0 # Node ID 236f600b24df9c18eef0faf78aafd19189361cdf # Parent e5f94ad0f58ea37092f7fb5ee69e5137a064763e Fixed one issue with PocketPC Added additional platform tests. diff -r e5f94ad0f58ea37092f7fb5ee69e5137a064763e -r 236f600b24df9c18eef0faf78aafd19189361cdf src/TinyIoC.Tests/PlatformTestSuite/PlatformTests.cs --- a/src/TinyIoC.Tests/PlatformTestSuite/PlatformTests.cs Sat Jan 15 11:53:38 2011 +0000 +++ b/src/TinyIoC.Tests/PlatformTestSuite/PlatformTests.cs Sat Jan 15 13:28:42 2011 +0000 @@ -51,7 +51,7 @@ { } - public class TestClassWithInterface2 : ITestInterface2 + public class TestClassWithInterface2 : ITestInterface { } @@ -195,6 +195,8 @@ #endif ResolveAll, IEnumerableDependency, + RegisterMultiple, + NonGenericRegister, }; } @@ -411,5 +413,25 @@ return (result.EnumerableCount == 3); } + + private bool RegisterMultiple(TinyIoCContainer container, ILogger logger) + { + logger.WriteLine("RegisterMultiple"); + container.RegisterMultiple(new Type[] { typeof(TestClassWithInterface), typeof(TestClassWithInterface2) }); + + var result = container.ResolveAll(); + + return (result.Count() == 2); + } + + private bool NonGenericRegister(TinyIoCContainer container, ILogger logger) + { + logger.WriteLine("NonGenericRegister"); + container.Register(typeof(ITestInterface), typeof(TestClassWithInterface)); + + var result = container.Resolve(ResolveOptions.FailUnregisteredAndNameNotFound); + + return true; + } } } diff -r e5f94ad0f58ea37092f7fb5ee69e5137a064763e -r 236f600b24df9c18eef0faf78aafd19189361cdf src/TinyIoC/TinyIoC.cs --- a/src/TinyIoC/TinyIoC.cs Sat Jan 15 11:53:38 2011 +0000 +++ b/src/TinyIoC/TinyIoC.cs Sat Jan 15 13:28:42 2011 +0000 @@ -13,6 +13,11 @@ // FITNESS FOR A PARTICULAR PURPOSE. //=============================================================================== +// -- MONOTOUCH IMPORTANT -- // +// If you are intending to use MonoTouch you *must* define MONOTOUCH or the code +// will not compile. +// -- MONOTOUCH IMPORTANT -- // + #region Preprocessor Directives // Uncomment this line if you want the container to automatically // register the TinyMessenger messenger/event aggregator @@ -27,7 +32,7 @@ #define GETPARAMETERS_OPEN_GENERICS // Platform supports GetParameters on open generics #define ASPNET // Adds ASP.Net pre-request singleton support -// CompactFramework +// CompactFramework / Windows Phone 7 // By default does not support System.Linq.Expressions. // AppDomain object does not support enumerating all assemblies in the app domain. #if PocketPC || WINDOWS_PHONE @@ -37,6 +42,8 @@ #undef ASPNET #endif +// PocketPC has a bizarre limitation on enumerating parameters on unbound generic methods. +// We need to use a slower workaround in that case. #if PocketPC #undef GETPARAMETERS_OPEN_GENERICS #endif @@ -45,6 +52,10 @@ #undef APPDOMAIN_GETASSEMBLIES #undef ASPNET #endif + +#if MONOTOUCH +#undef ASPNET +#endif #endregion namespace TinyIoC { @@ -2888,12 +2899,25 @@ #endif private object GetIEnumerableRequest(Type type) { +#if GETPARAMETERS_OPEN_GENERICS // Using MakeGenericMethod (slow) because we need to // cast the IEnumerable or constructing the type wil fail. // We may as well use the ResolveAll public // method to do this. var resolveAllMethod = this.GetType().GetMethod("ResolveAll", new Type[] { }); var genericResolveAllMethod = resolveAllMethod.MakeGenericMethod(type.GetGenericArguments()[0]); +#else + var resolveAllMethods = from member in this.GetType().GetMembers() + where member.MemberType == MemberTypes.Method + where member.Name == "ResolveAll" + let method = member as MethodInfo + where method.IsGenericMethod + let genericMethod = method.MakeGenericMethod(type.GetGenericArguments()[0]) + where genericMethod.GetParameters().Count() == 0 + select genericMethod; + + var genericResolveAllMethod = resolveAllMethods.First(); +#endif return genericResolveAllMethod.Invoke(this, new object[] { }); }