StyleCop clean.
[dotnetoauth.git] / src / DotNetOpenAuth / OpenId / Extensions / OpenIdExtensionFactory.cs
blob1c4428293e70eb60bb5a21e63cac563558ffc2c6
1 //-----------------------------------------------------------------------
2 // <copyright file="OpenIdExtensionFactory.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth.OpenId.Extensions {
8 using System.Collections.Generic;
9 using DotNetOpenAuth.Messaging;
10 using DotNetOpenAuth.OpenId.ChannelElements;
11 using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
12 using DotNetOpenAuth.OpenId.Extensions.ProviderAuthenticationPolicy;
13 using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
14 using DotNetOpenAuth.OpenId.Messages;
16 /// <summary>
17 /// An OpenID extension factory that supports registration so that third-party
18 /// extensions can add themselves to this library's supported extension list.
19 /// </summary>
20 internal class OpenIdExtensionFactory : IOpenIdExtensionFactory {
21 /// <summary>
22 /// A collection of the registered OpenID extensions.
23 /// </summary>
24 private List<CreateDelegate> registeredExtensions = new List<CreateDelegate>();
26 /// <summary>
27 /// Initializes a new instance of the <see cref="OpenIdExtensionFactory"/> class.
28 /// </summary>
29 internal OpenIdExtensionFactory() {
30 this.RegisterExtension(ClaimsRequest.Factory);
31 this.RegisterExtension(ClaimsResponse.Factory);
32 this.RegisterExtension(FetchRequest.Factory);
33 this.RegisterExtension(FetchResponse.Factory);
34 this.RegisterExtension(StoreRequest.Factory);
35 this.RegisterExtension(StoreResponse.Factory);
36 this.RegisterExtension(PolicyRequest.Factory);
37 this.RegisterExtension(PolicyResponse.Factory);
40 /// <summary>
41 /// A delegate that individual extensions may register with this factory.
42 /// </summary>
43 /// <param name="typeUri">The type URI of the extension.</param>
44 /// <param name="data">The parameters associated specifically with this extension.</param>
45 /// <param name="baseMessage">The OpenID message carrying this extension.</param>
46 /// <returns>
47 /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
48 /// the extension described in the input parameters; <c>null</c> otherwise.
49 /// </returns>
50 internal delegate IOpenIdMessageExtension CreateDelegate(string typeUri, IDictionary<string, string> data, IProtocolMessageWithExtensions baseMessage);
52 #region IOpenIdExtensionFactory Members
54 /// <summary>
55 /// Creates a new instance of some extension based on the received extension parameters.
56 /// </summary>
57 /// <param name="typeUri">The type URI of the extension.</param>
58 /// <param name="data">The parameters associated specifically with this extension.</param>
59 /// <param name="baseMessage">The OpenID message carrying this extension.</param>
60 /// <returns>
61 /// An instance of <see cref="IOpenIdMessageExtension"/> if the factory recognizes
62 /// the extension described in the input parameters; <c>null</c> otherwise.
63 /// </returns>
64 /// <remarks>
65 /// This factory method need only initialize properties in the instantiated extension object
66 /// that are not bound using <see cref="MessagePartAttribute"/>.
67 /// </remarks>
68 public IOpenIdMessageExtension Create(string typeUri, IDictionary<string, string> data, IProtocolMessageWithExtensions baseMessage) {
69 foreach (var factoryMethod in this.registeredExtensions) {
70 IOpenIdMessageExtension result = factoryMethod(typeUri, data, baseMessage);
71 if (result != null) {
72 return result;
76 return null;
79 #endregion
81 /// <summary>
82 /// Registers a new extension delegate.
83 /// </summary>
84 /// <param name="creator">The factory method that can create the extension.</param>
85 internal void RegisterExtension(CreateDelegate creator) {
86 this.registeredExtensions.Add(creator);