/// <summary> /// Construct a ValidationContext for a given object instance, an optional <paramref name="serviceProvider"/>, and an optional /// property bag of <paramref name="items"/>. /// </summary> /// <param name="instance">The object instance being validated. It cannot be null.</param> /// <param name="serviceProvider"> /// Optional <see cref="IServiceProvider"/> to use when <see cref="GetService"/> is called. /// If it is null, <see cref="GetService"/> will always return null. /// </param> /// <param name="items">Optional set of key/value pairs to make available to consumers via <see cref="Items"/>. /// If null, an empty dictionary will be created. If not null, the set of key/value pairs will be copied into a /// new dictionary, preventing consumers from modifying the original dictionary. /// </param> /// <exception cref="ArgumentNullException">When <paramref name="instance"/> is <c>null</c></exception> #else /// <summary> /// Construct a ValidationContext for a given object instance, an optional <paramref name="serviceProvider"/>, and an optional /// property bag of <paramref name="items"/>. /// </summary> /// <param name="instance">The object instance being validated. It cannot be null.</param> /// <param name="serviceProvider"> /// Optional <see cref="IServiceProvider"/> to use when <see cref="GetService"/> is called. /// <para> /// If the <paramref name="serviceProvider"/> specified implements <see cref="Design.IServiceContainer"/>, /// then it will be used as the <see cref="ServiceContainer"/> but its services can still be retrieved /// through <see cref="GetService"/> as well. /// </para> /// </param> /// <param name="items">Optional set of key/value pairs to make available to consumers via <see cref="Items"/>. /// If null, an empty dictionary will be created. If not null, the set of key/value pairs will be copied into a /// new dictionary, preventing consumers from modifying the original dictionary. /// </param> /// <exception cref="ArgumentNullException">When <paramref name="instance"/> is <c>null</c></exception> #endif public ValidationContext(object instance, IServiceProvider serviceProvider, IDictionary <object, object> items) { if (instance == null) { throw new ArgumentNullException("instance"); } this._serviceProvider = serviceProvider; #if !SILVERLIGHT Design.IServiceContainer container = serviceProvider as Design.IServiceContainer; if (container != null) { this._serviceContainer = new ValidationContextServiceContainer(container); } else { this._serviceContainer = new ValidationContextServiceContainer(); } #endif if (items != null) { this._items = new Dictionary <object, object>(items); } else { this._items = new Dictionary <object, object>(); } this._objectInstance = instance; }
/// <summary> /// Contstructs a new service container that has a parent container, making this container /// a wrapper around the parent container. Calls to <c>AddService</c> and <c>RemoveService</c> /// will promote to the parent container by default, unless <paramref name="promote"/> is /// specified as <c>false</c> on those calls. /// </summary> /// <param name="parentContainer">The parent container to wrap into this container.</param> internal ValidationContextServiceContainer(Design.IServiceContainer parentContainer) { this._parentContainer = parentContainer; }