|
|
|
@ -81,10 +81,10 @@ namespace TinyIoC
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if NETFX_CORE
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.Storage.Search;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Windows.Storage.Search;
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
using Windows.UI.Xaml.Shapes;
|
|
|
|
|
using Windows.UI.Xaml.Shapes;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#region SafeDictionary
|
|
|
|
@ -322,32 +322,32 @@ namespace TinyIoC
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// Gets a generic method from a type given the method name, generic types and parameter types
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="sourceType">Source type</param>
|
|
|
|
|
// /// <param name="methodName">Name of the method</param>
|
|
|
|
|
// /// <param name="genericTypes">Generic types to use to make the method generic</param>
|
|
|
|
|
// /// <param name="parameterTypes">Method parameters</param>
|
|
|
|
|
// /// <returns>MethodInfo or null if no matches found</returns>
|
|
|
|
|
// /// <exception cref="System.Reflection.AmbiguousMatchException"/>
|
|
|
|
|
// /// <exception cref="System.ArgumentException"/>
|
|
|
|
|
// public static MethodInfo GetGenericMethod(this Type sourceType, string methodName, Type[] genericTypes, Type[] parameterTypes)
|
|
|
|
|
// {
|
|
|
|
|
// MethodInfo method;
|
|
|
|
|
// var cacheKey = new GenericMethodCacheKey(sourceType, methodName, genericTypes, parameterTypes);
|
|
|
|
|
|
|
|
|
|
// // Shouldn't need any additional locking
|
|
|
|
|
// // we don't care if we do the method info generation
|
|
|
|
|
// // more than once before it gets cached.
|
|
|
|
|
// if (!_genericMethodCache.TryGetValue(cacheKey, out method))
|
|
|
|
|
// {
|
|
|
|
|
// method = GetMethod(sourceType, methodName, genericTypes, parameterTypes);
|
|
|
|
|
// _genericMethodCache[cacheKey] = method;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return method;
|
|
|
|
|
// }
|
|
|
|
|
// /// <summary>
|
|
|
|
|
// /// Gets a generic method from a type given the method name, generic types and parameter types
|
|
|
|
|
// /// </summary>
|
|
|
|
|
// /// <param name="sourceType">Source type</param>
|
|
|
|
|
// /// <param name="methodName">Name of the method</param>
|
|
|
|
|
// /// <param name="genericTypes">Generic types to use to make the method generic</param>
|
|
|
|
|
// /// <param name="parameterTypes">Method parameters</param>
|
|
|
|
|
// /// <returns>MethodInfo or null if no matches found</returns>
|
|
|
|
|
// /// <exception cref="System.Reflection.AmbiguousMatchException"/>
|
|
|
|
|
// /// <exception cref="System.ArgumentException"/>
|
|
|
|
|
// public static MethodInfo GetGenericMethod(this Type sourceType, string methodName, Type[] genericTypes, Type[] parameterTypes)
|
|
|
|
|
// {
|
|
|
|
|
// MethodInfo method;
|
|
|
|
|
// var cacheKey = new GenericMethodCacheKey(sourceType, methodName, genericTypes, parameterTypes);
|
|
|
|
|
|
|
|
|
|
// // Shouldn't need any additional locking
|
|
|
|
|
// // we don't care if we do the method info generation
|
|
|
|
|
// // more than once before it gets cached.
|
|
|
|
|
// if (!_genericMethodCache.TryGetValue(cacheKey, out method))
|
|
|
|
|
// {
|
|
|
|
|
// method = GetMethod(sourceType, methodName, genericTypes, parameterTypes);
|
|
|
|
|
// _genericMethodCache[cacheKey] = method;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return method;
|
|
|
|
|
// }
|
|
|
|
|
//#else
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a generic method from a type given the method name, binding flags, generic types and parameter types
|
|
|
|
@ -514,14 +514,14 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
// @mbrit - 2012-05-22 - shim for ForEach call on List<T>...
|
|
|
|
|
#if NETFX_CORE
|
|
|
|
|
internal static class ListExtender
|
|
|
|
|
{
|
|
|
|
|
internal static void ForEach<T>(this List<T> list, Action<T> callback)
|
|
|
|
|
{
|
|
|
|
|
foreach (T obj in list)
|
|
|
|
|
callback(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static class ListExtender
|
|
|
|
|
{
|
|
|
|
|
internal static void ForEach<T>(this List<T> list, Action<T> callback)
|
|
|
|
|
{
|
|
|
|
|
foreach (T obj in list)
|
|
|
|
|
callback(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
@ -771,33 +771,33 @@ namespace TinyIoC
|
|
|
|
|
CurrentDomain = new AppDomain();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @mbrit - 2012-05-30 - in WinRT, this should be done async...
|
|
|
|
|
// @mbrit - 2012-05-30 - in WinRT, this should be done async...
|
|
|
|
|
public async Task<List<Assembly>> GetAssembliesAsync()
|
|
|
|
|
{
|
|
|
|
|
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
|
|
|
|
|
|
|
|
|
|
List<Assembly> assemblies = new List<Assembly>();
|
|
|
|
|
|
|
|
|
|
var files = await folder.GetFilesAsync();
|
|
|
|
|
var files = await folder.GetFilesAsync();
|
|
|
|
|
|
|
|
|
|
foreach (StorageFile file in files)
|
|
|
|
|
{
|
|
|
|
|
if (file.FileType == ".dll" || file.FileType == ".exe")
|
|
|
|
|
{
|
|
|
|
|
AssemblyName name = new AssemblyName() { Name = System.IO.Path.GetFileNameWithoutExtension(file.Name) };
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var asm = Assembly.Load(name);
|
|
|
|
|
assemblies.Add(asm);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignore exceptions here...
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var asm = Assembly.Load(name);
|
|
|
|
|
assemblies.Add(asm);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignore exceptions here...
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return assemblies;
|
|
|
|
|
return assemblies;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
@ -1387,7 +1387,7 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
foreach (var type in implementationTypes)
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (!registrationType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
|
|
|
|
|
// if (!registrationType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
|
|
|
|
|
//#else
|
|
|
|
|
if (!registrationType.IsAssignableFrom(type))
|
|
|
|
|
//#endif
|
|
|
|
@ -2446,8 +2446,8 @@ namespace TinyIoC
|
|
|
|
|
public MultiInstanceFactory(Type registerType, Type registerImplementation)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
// throw new TinyIoCRegistrationTypeException(registerImplementation, "MultiInstanceFactory");
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
// throw new TinyIoCRegistrationTypeException(registerImplementation, "MultiInstanceFactory");
|
|
|
|
|
//#else
|
|
|
|
|
if (registerImplementation.IsAbstract() || registerImplementation.IsInterface())
|
|
|
|
|
throw new TinyIoCRegistrationTypeException(registerImplementation, "MultiInstanceFactory");
|
|
|
|
@ -2713,7 +2713,7 @@ namespace TinyIoC
|
|
|
|
|
public SingletonFactory(Type registerType, Type registerImplementation)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
//#else
|
|
|
|
|
if (registerImplementation.IsAbstract() || registerImplementation.IsInterface())
|
|
|
|
|
//#endif
|
|
|
|
@ -2789,7 +2789,7 @@ namespace TinyIoC
|
|
|
|
|
throw new TinyIoCRegistrationTypeException(registerImplementation, "SingletonFactory");
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
// if (registerImplementation.GetTypeInfo().IsAbstract() || registerImplementation.GetTypeInfo().IsInterface())
|
|
|
|
|
//#else
|
|
|
|
|
if (registerImplementation.IsAbstract() || registerImplementation.IsInterface())
|
|
|
|
|
//#endif
|
|
|
|
@ -3093,7 +3093,7 @@ namespace TinyIoC
|
|
|
|
|
private ObjectFactoryBase GetDefaultObjectFactory(Type registerType, Type registerImplementation)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (registerType.GetTypeInfo().IsInterface() || registerType.GetTypeInfo().IsAbstract())
|
|
|
|
|
// if (registerType.GetTypeInfo().IsInterface() || registerType.GetTypeInfo().IsAbstract())
|
|
|
|
|
//#else
|
|
|
|
|
if (registerType.IsInterface() || registerType.IsAbstract())
|
|
|
|
|
//#endif
|
|
|
|
@ -3185,7 +3185,7 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
// 2 parameter func with string as first parameter (name)
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if ((genericType == typeof(Func<,>) && type.GetTypeInfo().GenericTypeArguments[0] == typeof(string)))
|
|
|
|
|
// if ((genericType == typeof(Func<,>) && type.GetTypeInfo().GenericTypeArguments[0] == typeof(string)))
|
|
|
|
|
//#else
|
|
|
|
|
if ((genericType == typeof(Func<,>) && type.GetGenericArguments()[0] == typeof(string)))
|
|
|
|
|
//#endif
|
|
|
|
@ -3193,7 +3193,7 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
// 3 parameter func with string as first parameter (name) and IDictionary<string, object> as second (parameters)
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if ((genericType == typeof(Func<,,>) && type.GetTypeInfo().GenericTypeArguments[0] == typeof(string) && type.GetTypeInfo().GenericTypeArguments[1] == typeof(IDictionary<String, object>)))
|
|
|
|
|
// if ((genericType == typeof(Func<,,>) && type.GetTypeInfo().GenericTypeArguments[0] == typeof(string) && type.GetTypeInfo().GenericTypeArguments[1] == typeof(IDictionary<String, object>)))
|
|
|
|
|
//#else
|
|
|
|
|
if ((genericType == typeof(Func<,,>) && type.GetGenericArguments()[0] == typeof(string) && type.GetGenericArguments()[1] == typeof(IDictionary<string, object>)))
|
|
|
|
|
//#endif
|
|
|
|
@ -3331,7 +3331,7 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
Type genericType = type.GetGenericTypeDefinition();
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// Type[] genericArguments = type.GetTypeInfo().GenericTypeArguments.ToArray();
|
|
|
|
|
// Type[] genericArguments = type.GetTypeInfo().GenericTypeArguments.ToArray();
|
|
|
|
|
//#else
|
|
|
|
|
Type[] genericArguments = type.GetGenericArguments();
|
|
|
|
|
//#endif
|
|
|
|
@ -3342,7 +3342,7 @@ namespace TinyIoC
|
|
|
|
|
Type returnType = genericArguments[0];
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => !mi.GetParameters().Any());
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => !mi.GetParameters().Any());
|
|
|
|
|
//#else
|
|
|
|
|
MethodInfo resolveMethod = typeof(TinyIoCContainer).GetMethod("Resolve", new Type[] { });
|
|
|
|
|
//#endif
|
|
|
|
@ -3361,7 +3361,7 @@ namespace TinyIoC
|
|
|
|
|
Type returnType = genericArguments[1];
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => mi.GetParameters().Length == 1 && mi.GetParameters()[0].GetType() == typeof(String));
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => mi.GetParameters().Length == 1 && mi.GetParameters()[0].GetType() == typeof(String));
|
|
|
|
|
//#else
|
|
|
|
|
MethodInfo resolveMethod = typeof(TinyIoCContainer).GetMethod("Resolve", new Type[] { typeof(string) });
|
|
|
|
|
//#endif
|
|
|
|
@ -3377,7 +3377,7 @@ namespace TinyIoC
|
|
|
|
|
|
|
|
|
|
// 3 parameter func with string as first parameter (name) and IDictionary<string, object> as second (parameters)
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if ((genericType == typeof(Func<,,>) && type.GenericTypeArguments[0] == typeof(string) && type.GenericTypeArguments[1] == typeof(IDictionary<string, object>)))
|
|
|
|
|
// if ((genericType == typeof(Func<,,>) && type.GenericTypeArguments[0] == typeof(string) && type.GenericTypeArguments[1] == typeof(IDictionary<string, object>)))
|
|
|
|
|
//#else
|
|
|
|
|
if ((genericType == typeof(Func<,,>) && type.GetGenericArguments()[0] == typeof(string) && type.GetGenericArguments()[1] == typeof(IDictionary<string, object>)))
|
|
|
|
|
//#endif
|
|
|
|
@ -3388,7 +3388,7 @@ namespace TinyIoC
|
|
|
|
|
var parameters = Expression.Parameter(typeof(IDictionary<string, object>), "parameters");
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => mi.GetParameters().Length == 2 && mi.GetParameters()[0].GetType() == typeof(String) && mi.GetParameters()[1].GetType() == typeof(NamedParameterOverloads));
|
|
|
|
|
// MethodInfo resolveMethod = typeof(TinyIoCContainer).GetTypeInfo().GetDeclaredMethods("Resolve").First(mi => mi.GetParameters().Length == 2 && mi.GetParameters()[0].GetType() == typeof(String) && mi.GetParameters()[1].GetType() == typeof(NamedParameterOverloads));
|
|
|
|
|
//#else
|
|
|
|
|
MethodInfo resolveMethod = typeof(TinyIoCContainer).GetMethod("Resolve", new Type[] { typeof(string), typeof(NamedParameterOverloads) });
|
|
|
|
|
//#endif
|
|
|
|
@ -3407,7 +3407,7 @@ namespace TinyIoC
|
|
|
|
|
private object GetIEnumerableRequest(Type type)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// var genericResolveAllMethod = this.GetType().GetGenericMethod("ResolveAll", type.GenericTypeArguments, new[] { typeof(bool) });
|
|
|
|
|
// var genericResolveAllMethod = this.GetType().GetGenericMethod("ResolveAll", type.GenericTypeArguments, new[] { typeof(bool) });
|
|
|
|
|
//#else
|
|
|
|
|
var genericResolveAllMethod = this.GetType().GetGenericMethod(BindingFlags.Public | BindingFlags.Instance, "ResolveAll", type.GetGenericArguments(), new[] { typeof(bool) });
|
|
|
|
|
//#endif
|
|
|
|
@ -3428,7 +3428,7 @@ namespace TinyIoC
|
|
|
|
|
var isParameterOverload = parameters.ContainsKey(parameter.Name);
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (parameter.ParameterType.GetTypeInfo().IsPrimitive && !isParameterOverload)
|
|
|
|
|
// if (parameter.ParameterType.GetTypeInfo().IsPrimitive && !isParameterOverload)
|
|
|
|
|
//#else
|
|
|
|
|
if (parameter.ParameterType.IsPrimitive() && !isParameterOverload)
|
|
|
|
|
//#endif
|
|
|
|
@ -3447,7 +3447,7 @@ namespace TinyIoC
|
|
|
|
|
throw new ArgumentNullException("parameters");
|
|
|
|
|
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// if (type.GetTypeInfo().IsValueType)
|
|
|
|
|
// if (type.GetTypeInfo().IsValueType)
|
|
|
|
|
//#else
|
|
|
|
|
if (type.IsValueType())
|
|
|
|
|
//#endif
|
|
|
|
@ -3469,7 +3469,7 @@ namespace TinyIoC
|
|
|
|
|
private IEnumerable<ConstructorInfo> GetTypeConstructors(Type type)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// return type.GetTypeInfo().DeclaredConstructors.OrderByDescending(ctor => ctor.GetParameters().Count());
|
|
|
|
|
// return type.GetTypeInfo().DeclaredConstructors.OrderByDescending(ctor => ctor.GetParameters().Count());
|
|
|
|
|
//#else
|
|
|
|
|
return type.GetConstructors().OrderByDescending(ctor => ctor.GetParameters().Count());
|
|
|
|
|
//#endif
|
|
|
|
@ -3605,9 +3605,9 @@ namespace TinyIoC
|
|
|
|
|
private void BuildUpInternal(object input, ResolveOptions resolveOptions)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// var properties = from property in input.GetType().GetTypeInfo().DeclaredProperties
|
|
|
|
|
// where (property.GetMethod != null) && (property.SetMethod != null) && !property.PropertyType.GetTypeInfo().IsValueType
|
|
|
|
|
// select property;
|
|
|
|
|
// var properties = from property in input.GetType().GetTypeInfo().DeclaredProperties
|
|
|
|
|
// where (property.GetMethod != null) && (property.SetMethod != null) && !property.PropertyType.GetTypeInfo().IsValueType
|
|
|
|
|
// select property;
|
|
|
|
|
//#else
|
|
|
|
|
var properties = from property in input.GetType().GetProperties()
|
|
|
|
|
where (property.GetGetMethod() != null) && (property.GetSetMethod() != null) && !property.PropertyType.IsValueType()
|
|
|
|
@ -3653,26 +3653,26 @@ namespace TinyIoC
|
|
|
|
|
private static bool IsValidAssignment(Type registerType, Type registerImplementation)
|
|
|
|
|
{
|
|
|
|
|
//#if NETFX_CORE
|
|
|
|
|
// var registerTypeDef = registerType.GetTypeInfo();
|
|
|
|
|
// var registerImplementationDef = registerImplementation.GetTypeInfo();
|
|
|
|
|
|
|
|
|
|
// if (!registerTypeDef.IsGenericTypeDefinition)
|
|
|
|
|
// {
|
|
|
|
|
// if (!registerTypeDef.IsAssignableFrom(registerImplementationDef))
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// if (registerTypeDef.IsInterface())
|
|
|
|
|
// {
|
|
|
|
|
// if (!registerImplementationDef.ImplementedInterfaces.Any(t => t.GetTypeInfo().Name == registerTypeDef.Name))
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// else if (registerTypeDef.IsAbstract() && registerImplementationDef.BaseType() != registerType)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// var registerTypeDef = registerType.GetTypeInfo();
|
|
|
|
|
// var registerImplementationDef = registerImplementation.GetTypeInfo();
|
|
|
|
|
|
|
|
|
|
// if (!registerTypeDef.IsGenericTypeDefinition)
|
|
|
|
|
// {
|
|
|
|
|
// if (!registerTypeDef.IsAssignableFrom(registerImplementationDef))
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// if (registerTypeDef.IsInterface())
|
|
|
|
|
// {
|
|
|
|
|
// if (!registerImplementationDef.ImplementedInterfaces.Any(t => t.GetTypeInfo().Name == registerTypeDef.Name))
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// else if (registerTypeDef.IsAbstract() && registerImplementationDef.BaseType() != registerType)
|
|
|
|
|
// {
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//#else
|
|
|
|
|
if (!registerType.IsGenericTypeDefinition())
|
|
|
|
|
{
|
|
|
|
|