Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Printer prt = new Printer();
            Dimen   dm  = new Dimen();

            Console.WriteLine("Pilih Printer");
            Console.WriteLine("1. Epson");
            Console.WriteLine("2. Canon");
            Console.WriteLine("3. Lasetjet");
            Console.WriteLine("");
            Console.WriteLine("Nomor Printer [1..3] : ");
            int nomor = Convert.ToInt16(Console.ReadLine());

            Console.WriteLine("");

            IConvertObject convert;

            if (nomor == 1)
            {
                prt.nama = "Epson Display Dimension : 10*11";
                dm.dimen = "Epson Printer Printing ....";
                convert  = new ConvertToJson();
            }
            else if (nomor == 2)
            {
                prt.nama = "Canon Display Dimension : 9.5*12";
                dm.dimen = "Canon Printer Printing ....";
                convert  = new ConvertToJson2();
            }
            else
            {
                prt.nama = "Lasetjat Display Dimension : 12*12";
                dm.dimen = "Lasetjat Printer Printing ....";
                convert  = new ConvertToJson3();
            }

            convert.Convert(prt);
            convert.Convert(dm);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void Convert(Dimen dm)
        {
            string json2 = JsonConvert.SerializeObject(dm);

            Console.WriteLine(json2);
        }