Documentation Coverage Report
Current view: top level - Cqrs/Authentication - BasicTokenResolver.cs Hit Total Coverage
Version: 2.2 Artefacts: 3 3 100.0 %
Date: 2017-09-22

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using System.Runtime.Serialization;
      11             : using System.Xml;
      12             : using Cqrs.Services;
      13             : 
      14             : namespace Cqrs.Authentication
      15             : {
      16             :         /// <summary>
      17             :         /// Resolves basic, known parameter types when serialising with WCF.
      18             :         /// </summary>
      19             :         public class BasicTokenResolver : IServiceParameterResolver
      20           1 :         {
      21             :                 #region Implementation of IServiceParameterResolver
      22             : 
      23             :                 /// <summary>
      24             :                 /// Indicates if the provided <paramref name="dataContractType"/> is of type <see cref="Guid"/>, <see cref="Nullable{Guid}"/>, <see cref="int"/>, <see cref="Nullable{integer}"/>, <see cref="string"/>
      25             :                 /// OR if it is other resolvable.
      26             :                 /// </summary>
      27           1 :                 public virtual bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
      28             :                 {
      29             :                         if (dataContractType == typeof(Guid))
      30             :                         {
      31             :                                 XmlDictionary dictionary = new XmlDictionary();
      32             :                                 typeName = dictionary.Add("GuidToken");
      33             :                                 typeNamespace = dictionary.Add("https://getcqrs.net");
      34             :                                 return true;
      35             :                         }
      36             : 
      37             :                         if (dataContractType == typeof(Guid?))
      38             :                         {
      39             :                                 XmlDictionary dictionary = new XmlDictionary();
      40             :                                 typeName = dictionary.Add("NullableGuidToken");
      41             :                                 typeNamespace = dictionary.Add("https://getcqrs.net");
      42             :                                 return true;
      43             :                         }
      44             : 
      45             :                         if (dataContractType == typeof(string))
      46             :                         {
      47             :                                 XmlDictionary dictionary = new XmlDictionary();
      48             :                                 typeName = dictionary.Add("StringToken");
      49             :                                 typeNamespace = dictionary.Add("https://getcqrs.net");
      50             :                                 return true;
      51             :                         }
      52             : 
      53             :                         if (dataContractType == typeof(int))
      54             :                         {
      55             :                                 XmlDictionary dictionary = new XmlDictionary();
      56             :                                 typeName = dictionary.Add("IntegerToken");
      57             :                                 typeNamespace = dictionary.Add("https://getcqrs.net");
      58             :                                 return true;
      59             :                         }
      60             : 
      61             :                         if (dataContractType == typeof(int?))
      62             :                         {
      63             :                                 XmlDictionary dictionary = new XmlDictionary();
      64             :                                 typeName = dictionary.Add("NullableIntegerToken");
      65             :                                 typeNamespace = dictionary.Add("https://getcqrs.net");
      66             :                                 return true;
      67             :                         }
      68             : 
      69             :                         typeName = null;
      70             :                         typeNamespace = null;
      71             :                         return false;
      72             :                 }
      73             : 
      74             :                 /// <summary>
      75             :                 /// Returns the <see cref="Type"/> if the <paramref name="typeName"/> is resolvable or if it is 
      76             :                 /// of type <see cref="Guid"/>, <see cref="Nullable{Guid}"/>, <see cref="int"/>, <see cref="Nullable{integer}"/> and <see cref="string"/>
      77             :                 /// </summary>
      78           1 :                 public virtual Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
      79             :                 {
      80             :                         switch (typeNamespace)
      81             :                         {
      82             :                                 case "https://getcqrs.net":
      83             :                                         switch (typeName)
      84             :                                         {
      85             :                                                 case "GuidToken":
      86             :                                                         return typeof(Guid);
      87             :                                                 case "NullableGuidToken":
      88             :                                                         return typeof(Guid?);
      89             :                                                 case "StringToken":
      90             :                                                         return typeof(string);
      91             :                                                 case "IntegerToken":
      92             :                                                         return typeof(int);
      93             :                                                 case "NullableIntegerToken":
      94             :                                                         return typeof(int?);
      95             :                                         }
      96             :                                         break;
      97             :                         }
      98             : 
      99             :                         return null;
     100             :                 }
     101             : 
     102             :                 #endregion
     103             :         }
     104             : }

Generated by: LCOV version 1.10