using System; using System.Collections.Generic; namespace Csla.Validation { /// /// Maintains a list of all the per-type /// objects /// loaded in memory. /// internal static class SharedValidationRules { private static Dictionary _managers = new Dictionary(); /// /// Gets the for the /// specified object type, optionally creating a new instance /// of the object if necessary. /// /// /// Type of business object for which the rules apply. /// /// Indicates whether to create /// a new instance of the object if one doesn't exist. internal static ValidationRulesManager GetManager(Type objectType, bool create) { ValidationRulesManager result = null; if (!_managers.TryGetValue(objectType, out result) && create) { lock (_managers) { result = new ValidationRulesManager(); _managers.Add(objectType, result); } } return result; } /// /// Gets a value indicating whether a set of rules /// have been created for a given . /// /// /// Type of business object for which the rules apply. /// /// if rules exist for the type. public static bool RulesExistFor(Type objectType) { return _managers.ContainsKey(objectType); } } }