summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Core/Configuration
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.Core/Configuration')
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/DotNetOpenAuthSection.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/HostNameElement.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs5
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/MessagingElement.cs3
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/ReportingElement.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs15
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs44
-rw-r--r--src/DotNetOpenAuth.Core/Configuration/UntrustedWebRequestElement.cs1
9 files changed, 33 insertions, 43 deletions
diff --git a/src/DotNetOpenAuth.Core/Configuration/DotNetOpenAuthSection.cs b/src/DotNetOpenAuth.Core/Configuration/DotNetOpenAuthSection.cs
index 7c03c48..cdcd670 100644
--- a/src/DotNetOpenAuth.Core/Configuration/DotNetOpenAuthSection.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/DotNetOpenAuthSection.cs
@@ -7,7 +7,6 @@
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
- using System.Diagnostics.Contracts;
using System.Web;
using System.Web.Configuration;
@@ -15,7 +14,6 @@ namespace DotNetOpenAuth.Configuration {
/// Represents the section in the host's .config file that configures
/// this library's settings.
/// </summary>
- [ContractVerification(true)]
public class DotNetOpenAuthSection : ConfigurationSectionGroup {
/// <summary>
/// The name of the section under which this library's settings must be found.
diff --git a/src/DotNetOpenAuth.Core/Configuration/HostNameElement.cs b/src/DotNetOpenAuth.Core/Configuration/HostNameElement.cs
index b46ece9..5386314 100644
--- a/src/DotNetOpenAuth.Core/Configuration/HostNameElement.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/HostNameElement.cs
@@ -6,12 +6,10 @@
namespace DotNetOpenAuth.Configuration {
using System.Configuration;
- using System.Diagnostics.Contracts;
/// <summary>
/// Represents the name of a single host or a regex pattern for host names.
/// </summary>
- [ContractVerification(true)]
internal class HostNameElement : ConfigurationElement {
/// <summary>
/// Gets the name of the @name attribute.
diff --git a/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs b/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs
index f009ce5..8f537c3 100644
--- a/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/HostNameOrRegexCollection.cs
@@ -7,13 +7,12 @@
namespace DotNetOpenAuth.Configuration {
using System.Collections.Generic;
using System.Configuration;
- using System.Diagnostics.Contracts;
using System.Text.RegularExpressions;
+ using Validation;
/// <summary>
/// Represents a collection of child elements that describe host names either as literal host names or regex patterns.
/// </summary>
- [ContractVerification(true)]
internal class HostNameOrRegexCollection : ConfigurationElementCollection {
/// <summary>
/// Initializes a new instance of the <see cref="HostNameOrRegexCollection"/> class.
@@ -63,7 +62,7 @@ namespace DotNetOpenAuth.Configuration {
/// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
/// </returns>
protected override object GetElementKey(ConfigurationElement element) {
- Contract.Assume(element != null); // this should be Contract.Requires in base class.
+ Requires.NotNull(element, "element");
return ((HostNameElement)element).Name ?? string.Empty;
}
}
diff --git a/src/DotNetOpenAuth.Core/Configuration/MessagingElement.cs b/src/DotNetOpenAuth.Core/Configuration/MessagingElement.cs
index ff98d36..64dfba3 100644
--- a/src/DotNetOpenAuth.Core/Configuration/MessagingElement.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/MessagingElement.cs
@@ -7,14 +7,12 @@
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
- using System.Diagnostics.Contracts;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
/// <summary>
/// Represents the &lt;messaging&gt; element in the host's .config file.
/// </summary>
- [ContractVerification(true)]
public class MessagingElement : ConfigurationSection {
/// <summary>
/// The name of the &lt;webResourceUrlProvider&gt; sub-element.
@@ -75,7 +73,6 @@ namespace DotNetOpenAuth.Configuration {
/// </summary>
public static MessagingElement Configuration {
get {
- Contract.Ensures(Contract.Result<MessagingElement>() != null);
return (MessagingElement)ConfigurationManager.GetSection(MessagingElementName) ?? new MessagingElement();
}
}
diff --git a/src/DotNetOpenAuth.Core/Configuration/ReportingElement.cs b/src/DotNetOpenAuth.Core/Configuration/ReportingElement.cs
index 0af8205..f0184a6 100644
--- a/src/DotNetOpenAuth.Core/Configuration/ReportingElement.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/ReportingElement.cs
@@ -8,7 +8,6 @@ namespace DotNetOpenAuth.Configuration {
using System;
using System.Collections.Generic;
using System.Configuration;
- using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
@@ -76,7 +75,6 @@ namespace DotNetOpenAuth.Configuration {
/// </summary>
public static ReportingElement Configuration {
get {
- Contract.Ensures(Contract.Result<ReportingElement>() != null);
return (ReportingElement)ConfigurationManager.GetSection(ReportingElementName) ?? new ReportingElement();
}
}
diff --git a/src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs b/src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs
index 96f60bf..de70f64 100644
--- a/src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/TrustedProviderConfigurationCollection.cs
@@ -9,7 +9,7 @@ namespace DotNetOpenAuth.Configuration {
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
+ using Validation;
/// <summary>
/// A configuration collection of trusted OP Endpoints.
diff --git a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs
index 3e72722..fa146a2 100644
--- a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs
@@ -8,16 +8,15 @@ namespace DotNetOpenAuth.Configuration {
using System;
using System.Collections.Generic;
using System.Configuration;
- using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using Validation;
/// <summary>
/// A collection of <see cref="TypeConfigurationElement&lt;T&gt;"/>.
/// </summary>
/// <typeparam name="T">The type that all types specified in the elements must derive from.</typeparam>
- [ContractVerification(true)]
internal class TypeConfigurationCollection<T> : ConfigurationElementCollection
where T : class {
/// <summary>
@@ -42,12 +41,14 @@ namespace DotNetOpenAuth.Configuration {
/// Creates instances of all the types listed in the collection.
/// </summary>
/// <param name="allowInternals">if set to <c>true</c> then internal types may be instantiated.</param>
- /// <returns>A sequence of instances generated from types in this collection. May be empty, but never null.</returns>
- internal IEnumerable<T> CreateInstances(bool allowInternals) {
- Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);
+ /// <param name="hostFactories">The host factories.</param>
+ /// <returns>
+ /// A sequence of instances generated from types in this collection. May be empty, but never null.
+ /// </returns>
+ internal IEnumerable<T> CreateInstances(bool allowInternals, IHostFactories hostFactories) {
return from element in this.Cast<TypeConfigurationElement<T>>()
where !element.IsEmpty
- select element.CreateInstance(default(T), allowInternals);
+ select element.CreateInstance(default(T), allowInternals, hostFactories);
}
/// <summary>
@@ -68,7 +69,7 @@ namespace DotNetOpenAuth.Configuration {
/// An <see cref="T:System.Object"/> that acts as the key for the specified <see cref="T:System.Configuration.ConfigurationElement"/>.
/// </returns>
protected override object GetElementKey(ConfigurationElement element) {
- Contract.Assume(element != null); // this should be Contract.Requires in base class.
+ Requires.NotNull(element, "element");
TypeConfigurationElement<T> typedElement = (TypeConfigurationElement<T>)element;
return (!string.IsNullOrEmpty(typedElement.TypeName) ? typedElement.TypeName : typedElement.XamlSource) ?? string.Empty;
}
diff --git a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs
index edbb614..bcf199f 100644
--- a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs
@@ -8,15 +8,10 @@ namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
- using System.Diagnostics.Contracts;
using System.IO;
using System.Reflection;
using System.Web;
-#if CLR4
using System.Xaml;
-#else
- using System.Windows.Markup;
-#endif
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -80,11 +75,12 @@ namespace DotNetOpenAuth.Configuration {
/// Creates an instance of the type described in the .config file.
/// </summary>
/// <param name="defaultValue">The value to return if no type is given in the .config file.</param>
- /// <returns>The newly instantiated type.</returns>
- public T CreateInstance(T defaultValue) {
- Contract.Ensures(Contract.Result<T>() != null || Contract.Result<T>() == defaultValue);
-
- return this.CreateInstance(defaultValue, false);
+ /// <param name="hostFactories">The host factories.</param>
+ /// <returns>
+ /// The newly instantiated type.
+ /// </returns>
+ public T CreateInstance(T defaultValue, IHostFactories hostFactories) {
+ return this.CreateInstance(defaultValue, false, hostFactories);
}
/// <summary>
@@ -92,11 +88,13 @@ namespace DotNetOpenAuth.Configuration {
/// </summary>
/// <param name="defaultValue">The value to return if no type is given in the .config file.</param>
/// <param name="allowInternals">if set to <c>true</c> then internal types may be instantiated.</param>
- /// <returns>The newly instantiated type.</returns>
+ /// <param name="hostFactories">The host factories.</param>
+ /// <returns>
+ /// The newly instantiated type.
+ /// </returns>
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
- public T CreateInstance(T defaultValue, bool allowInternals) {
- Contract.Ensures(Contract.Result<T>() != null || Contract.Result<T>() == defaultValue);
-
+ public T CreateInstance(T defaultValue, bool allowInternals, IHostFactories hostFactories) {
+ T instance;
if (this.CustomType != null) {
if (!allowInternals) {
// Although .NET will usually prevent our instantiating non-public types,
@@ -104,7 +102,7 @@ namespace DotNetOpenAuth.Configuration {
// But we don't want the host site to be able to do this, so we check ourselves.
ErrorUtilities.VerifyArgument((this.CustomType.Attributes & TypeAttributes.Public) != 0, Strings.ConfigurationTypeMustBePublic, this.CustomType.FullName);
}
- return (T)Activator.CreateInstance(this.CustomType);
+ instance = (T)Activator.CreateInstance(this.CustomType);
} else if (!string.IsNullOrEmpty(this.XamlSource)) {
string source = this.XamlSource;
if (source.StartsWith("~/", StringComparison.Ordinal)) {
@@ -112,11 +110,18 @@ namespace DotNetOpenAuth.Configuration {
source = HttpContext.Current.Server.MapPath(source);
}
using (Stream xamlFile = File.OpenRead(source)) {
- return CreateInstanceFromXaml(xamlFile);
+ instance = CreateInstanceFromXaml(xamlFile);
}
} else {
- return defaultValue;
+ instance = defaultValue;
}
+
+ var requiresHostFactories = instance as IRequireHostFactories;
+ if (requiresHostFactories != null) {
+ requiresHostFactories.HostFactories = hostFactories;
+ }
+
+ return instance;
}
/// <summary>
@@ -132,12 +137,7 @@ namespace DotNetOpenAuth.Configuration {
/// be present.
/// </remarks>
private static T CreateInstanceFromXaml(Stream xaml) {
- Contract.Ensures(Contract.Result<T>() != null);
-#if CLR4
return (T)XamlServices.Load(xaml);
-#else
- return (T)XamlReader.Load(xaml);
-#endif
}
}
}
diff --git a/src/DotNetOpenAuth.Core/Configuration/UntrustedWebRequestElement.cs b/src/DotNetOpenAuth.Core/Configuration/UntrustedWebRequestElement.cs
index b49452a..a16522a 100644
--- a/src/DotNetOpenAuth.Core/Configuration/UntrustedWebRequestElement.cs
+++ b/src/DotNetOpenAuth.Core/Configuration/UntrustedWebRequestElement.cs
@@ -7,7 +7,6 @@
namespace DotNetOpenAuth.Configuration {
using System;
using System.Configuration;
- using System.Diagnostics.Contracts;
/// <summary>
/// Represents the section of a .config file where security policies regarding web requests