// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of the DAM Engine. // // The DAM Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections; namespace Deltares.DamEngine.Calculators.General { /// /// Entry point for the current context /// public static class Context { [ThreadStatic] private static IContext currentContext; /// /// Application wide context /// public static IContext CurrentContext { get { return currentContext; } set { currentContext = value; } } public static bool? IsVisible(object source, string member) { bool? visibility = null; if (currentContext != null) { visibility = currentContext.IsVisible(source, member); } return visibility; } public static bool? IsEnabled(object source, string member) { bool? enabled = null; if (currentContext != null) { enabled = currentContext.IsEnabled(source, member); } return enabled; } public static bool ShouldValidate(object source, string member, bool defaultValidate) { if (currentContext == null) { return defaultValidate; } bool? validate = currentContext.ShouldValidate(source, member); return validate.HasValue ? validate.Value : defaultValidate; } public static ICollection GetDomain(object source, string member, ICollection defaultDomain) { if (currentContext == null) { return defaultDomain; } ICollection domain = currentContext.GetDomain(source, member); return domain ?? defaultDomain; } public static object GetFormat(Type type, object source, string property) { return currentContext != null ? currentContext.GetFormat(type, source, property) : null; } public static int[] GetPropertyOrder(Type type, string property) { return currentContext != null ? currentContext.GetPropertyOrder(type, property) : null; } public static double? GetMinimum(object source, string property) { return currentContext != null ? currentContext.GetMinimum(source, property) : null; } public static double? GetMaximum(object source, string property) { return currentContext != null ? currentContext.GetMaximum(source, property) : null; } public static object GetDefault(Type type, string property) { return currentContext != null ? currentContext.GetDefault(type, property) : null; } } }