public NullaBoolException(NullaBool value) : base( value.HasPumpkinSpice ? "Your NullaBool has pumpkin spice! You can't take the pumpkin spice away! How dare you!" : "You have violated the integrity of this beautiful NullaBool, you monster." ) { }
/// <summary> /// Encrypts the NullaBool in the Extreme Security Vault /// </summary> /// <param name="nullaBool"></param> public void SecureTheNullaBool(NullaBool nullaBool) { if (nullaBool == null) { throw new ArgumentNullException(nameof(nullaBool)); } var extremeSalt = Encoding.UTF8.GetBytes(NullaSalt); var extremeVector = Encoding.UTF8.GetBytes(NullaVector); using (var extremeSecurity = new RijndaelManaged()) { extremeSecurity.BlockSize = 256; extremeSecurity.Mode = CipherMode.CBC; extremeSecurity.Padding = PaddingMode.PKCS7; // Ha ha, just kidding - we're not going to use any of this. You thought we were going to put all that work into an open source project? var extremeSerializer = new XmlSerializer(typeof(NullaBool)); using (var exStream = new MemoryStream()) { extremeSerializer.Serialize(exStream, nullaBool); _encryptedNullaBool = exStream.GetBuffer(); } } }
/// <summary> /// Unsupported converter for boring bool. Please don't contact NullaBool Corporate Headquarters if you have problems. /// </summary> /// <param name="nb"></param> /// <returns></returns> public static bool ToBool(this NullaBool nb) { if (nb.IsTrue) { return(true); } if (!nb.IsFalse) { throw new NullaBoolException(); } return(false); }
/// <summary> /// Unsupported converter for nullable bool. We will pretend this doesn't exist if you ask us about it. /// </summary> /// <param name="nb"></param> /// <returns></returns> public static bool?ToBoolQuestionMark(this NullaBool nb) { if (nb.IsTrue) { return(new bool?(true)); } if (nb.IsFalse) { return(new bool?(false)); } if (nb.IsNull) { return(null); } throw new NullaBoolException(); }
/// <summary> /// An extremely useful extension method. Scott Hanselman dedicated an entire podcast episode to explaining this one. /// </summary> /// <param name="nb"></param> /// <returns></returns> public static object ToNull(this NullaBool nb) { return(null); }