Beispiel #1
0
        static void Main(string[] args)
        {
            var DrEvil = new EvilGenius("Dr. Evil");
            WriteLine(DrEvil);
            WriteLine(DrEvil.EvilPoints());

            DrEvil.ReplaceHenchman(new Henchman { Name = "Scott Evil" });
            WriteLine(DrEvil);

            DrEvil.ReplaceHenchman(new Henchman { Name = "Mini Me" });
            WriteLine(DrEvil.EvilHistory());

            var TheMaster = new EvilGenius("The Master");
            var tokens = EvilGenius.ToJson(new[] { DrEvil, TheMaster });

            var evil = EvilGenius.FromJson(tokens);

            foreach (var e in evil)
            {
                WriteLine(e);
            }

            // Yes, this is evil, but it's in a console app so 
            // I can't await:
            AsyncEvilCreation();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var DrEvil = new EvilGenius("Dr. Evil");

            WriteLine(DrEvil);
            WriteLine(DrEvil.EvilPoints());

            DrEvil.ReplaceHenchman(new Henchman {
                Name = "Scott Evil"
            });
            WriteLine(DrEvil);

            DrEvil.ReplaceHenchman(new Henchman {
                Name = "Mini Me"
            });
            WriteLine(DrEvil.EvilHistory());

            var TheMaster = new EvilGenius("The Master");
            var tokens    = EvilGenius.ToJson(new[] { DrEvil, TheMaster });

            var evil = EvilGenius.FromJson(tokens);

            foreach (var e in evil)
            {
                WriteLine(e);
            }

            // Yes, this is evil, but it's in a console app so
            // I can't await:
            AsyncEvilCreation();
        }
Beispiel #3
0
        private static async Task AsyncEvilCreation()
        {
            try
            {
                //var nameless = new EvilGenius(default(string));

                var empty = new EvilGenius("     ");
            }
            catch (Exception e) when(logException(e))
            {
            }
            catch (ArgumentNullException n)
            {
                await LogErrorToFileAsync("Dude, can't have nameless evil genius", n);
            }
            catch (ArgumentException e3) when(!Debugger.IsAttached)
            {
                await LogErrorToFileAsync("Evil names cannot be blank", e3);
            }
        }
Beispiel #4
0
        private static async Task AsyncEvilCreation()
        {
            try
            {
                //var nameless = new EvilGenius(default(string));

                var empty = new EvilGenius("     ");
            }
            catch (Exception e) when (logException(e))
            {

            }
            catch (ArgumentNullException n)
            {
                await LogErrorToFileAsync("Dude, can't have nameless evil genius", n);
            }
            catch (ArgumentException e3) when (!Debugger.IsAttached)
            {
                await LogErrorToFileAsync("Evil names cannot be blank", e3);
            }
        }
Beispiel #5
0
 public static IEnumerable <EvilGenius> FromJson(JArray array)
 {
     foreach (var json in array)
     {
         if (json != null)
         {
             var rVal = new EvilGenius((string)json[nameof(EvilGenius.Name)])
             {
                 CatchPhrase = (string)json[nameof(EvilGenius.CatchPhrase)]
             };
             var minion = (JToken)json[nameof(EvilGenius.Assistant)];
             if (minion != null)
             {
                 rVal.ReplaceHenchman(new Henchman
                 {
                     Name = (string)minion[nameof(Henchman.Name)]
                 });
             }
             yield return(rVal);
         }
     }
 }
Beispiel #6
0
 public static IEnumerable<EvilGenius> FromJson(JArray array)
 {
     foreach (var json in array)
     {
         if (json != null)
         {
             var rVal = new EvilGenius((string)json[nameof(EvilGenius.Name)])
             {
                 CatchPhrase = (string)json[nameof(EvilGenius.CatchPhrase)]
             };
             var minion = (JToken)json[nameof(EvilGenius.Assistant)];
             if (minion != null)
             {
                 rVal.ReplaceHenchman(new Henchman
                 {
                     Name = (string)minion[nameof(Henchman.Name)]
                 });
             }
             yield return rVal;
         }
     }
 }