document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System.Collections;
  2. using System.Data.SqlTypes;
  3. using Microsoft.SqlServer.Server;
  4.  
  5. namespace RSAID
  6. {
  7.     public partial class UserDefinedFunctions
  8.     {
  9.         [SqlFunction(FillRowMethodName = "ValidateRSAIDFillRow",
  10.                      TableDefinition   = "IsValid bit, IsCitizen bit, Gender nchar(1), DateOfBirth DateTime")]
  11.         public static IEnumerator ValidateRSAID(SqlString IdNumber)
  12.         {
  13.             yield return IdNumber.IsNull ? null : new ValidatedRSAID(IdNumber.Value);
  14.         }
  15.  
  16.         public static void ValidateRSAIDFillRow(object obj,
  17.                                                 out SqlBoolean IsValid,
  18.                                                 out SqlBoolean IsCitizen,
  19.                                                 out SqlString Gender,
  20.                                                 out SqlDateTime DateOfBirth)
  21.         {
  22.             var id = obj as ValidatedRSAID;
  23.             if (id == null)
  24.             {
  25.                 IsValid = false;
  26.                 IsCitizen = SqlBoolean.Null;
  27.                 Gender = SqlString.Null;
  28.                 DateOfBirth = SqlDateTime.Null;
  29.             }
  30.             else
  31.             {
  32.                 IsValid = id.IsValid;
  33.                 IsCitizen = id.IsCitizen.HasValue ? id.IsCitizen.Value : SqlBoolean.Null;
  34.                 DateOfBirth = id.DateOfBirth.HasValue ? id.DateOfBirth.Value : SqlDateTime.Null;
  35.                 Gender = id.Gender.HasValue
  36.                              ? (id.Gender.Value == RSAID.Gender.Female ? "F" : "M")
  37.                              : SqlString.Null;
  38.             }
  39.         }
  40.     };
  41. }
');