2008-12-06 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / class / System.Configuration / System.Configuration / ProtectedConfiguration.cs
index 8eaa6e91ef578c9cdaec8b9cdc79aa59760dcc5d..42cdd11be4023eb45352afeab3ea8821d777ef13 100644 (file)
@@ -40,19 +40,25 @@ namespace System.Configuration
                public const string RsaProviderName = "RsaProtectedConfigurationProvider";
 
                public static string DefaultProvider {
-                       get {
-                               ProtectedConfigurationSection section = (ProtectedConfigurationSection)ConfigurationManager.GetSection ("configProtectedData");
-
-                               return section.DefaultProvider;
-                       }
+                       get { return Section.DefaultProvider; }
                }
 
                public static ProtectedConfigurationProviderCollection Providers {
-                       get {
-                               ProtectedConfigurationSection section = (ProtectedConfigurationSection)ConfigurationManager.GetSection ("configProtectedData");
+                       get { return Section.GetAllProviders(); }
+               }
+
+               internal static ProtectedConfigurationSection Section {
+                       get { return (ProtectedConfigurationSection)ConfigurationManager.GetSection ("configProtectedData"); }
+               }
+
+               internal static ProtectedConfigurationProvider GetProvider (string name, bool throwOnError)
+               {
+                       ProtectedConfigurationProvider p = Providers[name];
+
+                       if (p == null && throwOnError)
+                               throw new Exception (String.Format ("The protection provider '{0}' was not found.", name));
 
-                               return section.GetAllProviders();
-                       }
+                       return p;
                }
        }