From ffaacbad9ff69fba00a3ca419cf6d361364c5cbd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 30 Nov 2021 13:14:44 +0100 Subject: [PATCH] Add Configuration type --- .../Properties/Configuration.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 CommunityToolkit.Mvvm/Properties/Configuration.cs diff --git a/CommunityToolkit.Mvvm/Properties/Configuration.cs b/CommunityToolkit.Mvvm/Properties/Configuration.cs new file mode 100644 index 00000000..6f24624d --- /dev/null +++ b/CommunityToolkit.Mvvm/Properties/Configuration.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.ComponentModel; +using System.Diagnostics.Contracts; + +/// +/// A container for all shared configuration switches for the MVVM Toolkit. +/// +internal static class Configuration +{ + /// + /// The configuration property name for . + /// + private const string DisableINotifyPropertyChangingSupport = "MVVMTOOLKIT_DISABLE_INOTIFYPROPERTYCHANGING"; + + /// + /// Indicates whether or not support for is disabled. + /// + public static readonly bool IsINotifyPropertyChangingDisabled = GetConfigurationValue(DisableINotifyPropertyChangingSupport); + + /// + /// Gets a configuration value for a specified property. + /// + /// The property name to retrieve the value for. + /// The value of the specified configuration setting. + [Pure] + private static bool GetConfigurationValue(string propertyName) + { + if (AppContext.TryGetSwitch(propertyName, out bool isEnabled)) + { + return isEnabled; + } + + return false; + } +}