internal static void SetValue <TValue>(this PropertyInfo property, object target, TValue value) { property.SetValue(target, value, Empty.Array <object>()); }
public static object InvokeEx([NotNull] this MethodInfo method, object target) { return(method.InvokeEx(target, Empty.Array <object>())); }
private bool TryResolveSelfBindable(Type service, IIocParameter[] parameters, out object value) { BindingRegistration registration; lock (_selfActivatedRegistrations) { if (!_selfActivatedRegistrations.TryGetValue(service, out registration)) { if (IsSelfBindableType(service)) { registration = new BindingRegistration(this, service, DependencyLifecycle.TransientInstance, Empty.Array <IIocParameter>()); } _selfActivatedRegistrations[service] = registration; } } if (registration == null) { value = null; return(false); } value = registration.Resolve(parameters); return(true); }
public static object InvokeEx([NotNull] this ConstructorInfo constructor) { return(constructor.InvokeEx(Empty.Array <object>())); }
private bool TryResolve(Type service, IIocParameter[] parameters, out object value) { if (service.IsArray) { Type elementType = service.GetElementType(); value = ConvertToArray(service, elementType); return(true); } #if NET4 if (!service.IsGenericType) #else if (!service.GetTypeInfo().IsGenericType) #endif { return(TryResolveSelfBindable(service, parameters, out value)); } Type definition = service.GetGenericTypeDefinition(); ConstructorInfo constructor = null; var originalType = service.GetGenericArguments()[0]; #if NET4 if (definition.IsInterface) #else if (definition.GetTypeInfo().IsInterface) #endif { if (definition == typeof(ICollection <>) || definition == typeof(IEnumerable <>) || definition == typeof(IList <>) #if !NET4 || definition == typeof(IReadOnlyCollection <>) || definition == typeof(IReadOnlyList <>) #endif ) { constructor = typeof(List <>).MakeGenericType(originalType).GetConstructor(Empty.Array <Type>()); } } else { if (typeof(ICollection <>).MakeGenericType(originalType).IsAssignableFrom(service)) { constructor = service.GetConstructor(Empty.Array <Type>()); } } if (constructor == null) { return(TryResolveSelfBindable(service, parameters, out value)); } #if NET4 MethodInfo methodInfo = constructor.DeclaringType?.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new[] { originalType }, null); #else MethodInfo methodInfo = constructor.DeclaringType?.GetRuntimeMethod("Add", new[] { originalType }); #endif if (methodInfo == null || methodInfo.IsStatic) { return(TryResolveSelfBindable(service, parameters, out value)); } IList <object> objects = GetAll(originalType); value = constructor.InvokeEx(); var args = new object[1]; foreach (object o in objects) { args[0] = o; methodInfo.InvokeEx(value, args); } return(true); }