/// <summary> /// Create a new <see cref="GenericResolvedArrayParameter"/> instance that specifies /// that the given named generic parameter should be resolved. /// </summary> /// <param name="genericParameterName">The generic parameter name to resolve.</param> /// <param name="elementValues">The values for the elements, that will /// be converted to <see cref="InjectionParameterValue"/> objects.</param> public GenericResolvedArrayParameter(string genericParameterName, params object[] elementValues) { Guard.ArgumentNotNull(genericParameterName, "genericParameterName"); this.genericParameterName = genericParameterName; this.elementValues.AddRange(ToParameters(elementValues)); }
/// <summary> /// RegisterType an instance with the container. /// </summary> /// <remarks> /// <para> /// Instance registration is much like setting a type as a singleton, except that instead /// of the container creating the instance the first time it is requested, the user /// creates the instance ahead of type and adds that instance to the container. /// </para> /// </remarks> /// <param name="t">Type of instance to register (may be an implemented interface instead of the full type).</param> /// <param name="instance">Object to returned.</param> /// <param name="name">Name for registration.</param> /// <param name="lifetime"> /// <para>If true, the container will take over the lifetime of the instance, /// calling Dispose on it (if it's <see cref="IDisposable"/>) when the container is Disposed.</para> /// <para> /// If false, container will not maintain a strong reference to <paramref name="instance"/>. User is reponsible /// for disposing instance, and for keeping the instance from being garbage collected.</para></param> /// <returns>The <see cref="UnityContainer"/> object that this method was called on (this in C#, Me in Visual Basic).</returns> public override IUnityContainer RegisterInstance(Type t, string name, object instance, LifetimeManager lifetime) { Guard.ArgumentNotNull(instance, "instance"); Guard.ArgumentNotNull(lifetime, "lifetime"); Guard.TypeIsAssignable(t, instance.GetType(), "instance"); registeringInstance(this, new RegisterInstanceEventArgs(t, instance, name, lifetime)); return(this); }
public override IDependencyResolverPolicy GetResolverPolicy(Type typeToBuild) { Guard.ArgumentNotNull(typeToBuild, "typeToBuild"); ReflectionHelper parameterReflector = new ReflectionHelper(ParameterType); Type typeToResolve = parameterReflector.Type; if (parameterReflector.IsOpenGeneric) { typeToResolve = parameterReflector.GetClosedParameterType(typeToBuild.GetGenericArguments()); } return(new NamedTypeDependencyResolverPolicy(typeToResolve, name)); }
public override bool MatchesType(Type t) { Guard.ArgumentNotNull(t, "t"); if (!t.IsArray || t.GetArrayRank() != 1) { return(false); } Type elementType = t.GetElementType(); return(elementType.IsGenericParameter && elementType.Name == genericParameterName); }
public override void AddPolicies(Type typeToCreate, string name, IPolicyList policies) { Guard.ArgumentNotNull(typeToCreate, "typeToCreate"); PropertyInfo propInfo = typeToCreate.GetProperty(propertyName); GuardPropertyExists(propInfo, typeToCreate, propertyName); GuardPropertyIsSettable(propInfo); GuardPropertyIsNotIndexer(propInfo); InitializeParameterValue(propInfo); GuardPropertyValueIsCompatible(propInfo, parameterValue); SpecifiedPropertiesSelectorPolicy selector = GetSelectorPolicy(policies, typeToCreate, name); selector.AddPropertyAndValue(propInfo, parameterValue); }
public override IDependencyResolverPolicy GetResolverPolicy(Type typeToBuild) { Guard.ArgumentNotNull(typeToBuild, "typeToBuild"); var parameterReflector = new ReflectionHelper(ParameterType); if (parameterReflector.IsGenericArray) { return(this.CreateGenericArrayResolverPolicy(typeToBuild, parameterReflector)); } if (parameterReflector.IsOpenGeneric || parameterReflector.Type.IsGenericParameter) { return(this.CreateGenericResolverPolicy(typeToBuild, parameterReflector)); } return(this.CreateResolverPolicy(parameterReflector.Type)); }
// FxCop warning suppressed: false positive, Guard class is doing validation public override object BuildUp(Type t, object existing, string name) { Guard.ArgumentNotNull(existing, "existing"); Guard.TypeIsAssignable(t, existing.GetType(), "existing"); return(DoBuildUp(t, existing, name)); }
public override bool MatchesType(Type t) { Guard.ArgumentNotNull(t, "t"); return(t.IsGenericParameter && t.Name == genericParameterName); }