Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
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);
         }
     }
 }
Exemplo n.º 4
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;
         }
     }
 }