Пример #1
0
        static void Main(string[] args)
        {
            ProgramConverter[] array =
            {
                new ProgramConverter(),
                new ProgramHelper(),
                new ProgramConverter()
            };

            foreach (ProgramConverter pc in array)
            {
                ICodeChecker icc = pc as ICodeChecker;

                if (icc != null)
                {
                    if (icc.CheckCodeSyntax("Строка", "CSharp"))
                    {
                        Console.WriteLine(pc.ConvertToVB("code"));
                        Console.WriteLine();
                    }

                    else
                    {
                        Console.WriteLine(pc.ConvertToCSharp("code"));
                        Console.WriteLine();
                    }
                }
                else
                {
                    Console.WriteLine(pc.ConvertToCSharp("code"));
                    Console.WriteLine(pc.ConvertToVB("code"));
                    Console.WriteLine();
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string input    = "Random str.";
            string language = "VB";

            ProgramConverter[] array = { new ProgramConverter(), new ProgramConverter(), new ProgramHelper(), new ProgramHelper() };
            foreach (var item in array)
            {
                if (item is ICodeChecker)
                {
                    ICodeChecker check = item as ICodeChecker;
                    if (check.CheckCodeSyntax(input, language))
                    {
                        Console.WriteLine(item.ConvertToVB(input));
                    }
                    else
                    {
                        Console.WriteLine(item.ConvertToCSharp(input));
                    }
                }
                else
                {
                    Console.WriteLine(item.ConvertToCSharp(input));
                    Console.WriteLine(item.ConvertToVB(input));
                }
            }
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            ProgramConverter[] pc = new ProgramConverter[3];
            pc[0] = new ProgramHelper();
            pc[1] = new ProgramConverter();
            pc[2] = new ProgramConverter();


            for (int i = 0; i < pc.Length - 1; i++)
            {
                if (pc[i] is ICodeChecker)
                {
                    ICodeChecker qq = pc[i] as ProgramHelper;
                    Console.WriteLine(qq.CheckCodeSyntax("+", "+"));
                }
                else
                {
                    Console.WriteLine(pc[i].ConvertToCSharp("+"));
                    Console.WriteLine(pc[i].ConvertToVB("+"));
                }
            }


            Console.ReadKey();
        }
Пример #4
0
 static void Main(string[] args)
 {
     ProgramConverter[] check = new ProgramConverter[2];
     check[0] = new ProgramConverter();
     check[1] = new ProgramHelper();
     for (int i = 0; i < check.Length; i++)
     {
         if (check[i] is ICodeChecker)
         {
             ICodeChecker codeCheck = check[i] as ProgramHelper;
             if (codeCheck.CheckCodeSyntax("lol", "haha"))
             {
                 Console.WriteLine(check[i].ConvertToCSharp("lol"));
             }
             else
             {
                 Console.WriteLine(check[i].ConvertToVB("lol"));
             }
         }
         else
         {
             IConvertible convert = check[i] as ProgramConverter;
             Console.WriteLine(convert.ConvertToCSharp("lol"));
             Console.WriteLine(convert.ConvertToVB("lol"));
         }
     }
 }
Пример #5
0
 static void Main(string[] args)
 {
     ProgramConverter[] check = new ProgramConverter[2]; // создали массив элементов ProgramConverter
     check[0] = new ProgramConverter();                  // тип ProgramConverter
     check[1] = new ProgramHelper();                     // тип ProgramHelper
     for (int i = 0; i < check.Length; i++)              // проверка реализации метода ICodeChecker
     {
         if (check[i] is ICodeChecker)                   // если метод реализуется, вызываем метод проверки кода и соответствующий метод преобразования
         {
             ICodeChecker codeCheck = check[i] as ProgramHelper;
             if (codeCheck.CheckCodeSyntax("coding", "programmer"))
             {
                 Console.WriteLine(check[i].ConvertToCSharp("coding"));
             }
             else
             {
                 Console.WriteLine(check[i].ConvertToVB("coding"));
             }
         }
         else // если метод не реализуется, вызываем два метода преоброзвания кода
         {
             IConvertible convert = check[i] as ProgramConverter;
             Console.WriteLine(convert.ConvertToCSharp("coding"));
             Console.WriteLine(convert.ConvertToVB("coding"));
         }
     }
 }
Пример #6
0
 static void Main(string[] args)
 {
     ProgramConverter[] check = new ProgramConverter[2];
     check[0] = new ProgramConverter();
     check[1] = new ProgramHelper();
     for (int i = 0; i < check.Length; i++)
     {
         if (check[i] is ICodeChecker)
         {
             ICodeChecker Check = check[i] as ProgramHelper;
             if (Check.CheckCodeSyntax("str1", "str2"))
             {
                 Console.WriteLine(check[i].ConvertToCSharp("str1"));
             }
             else
             {
                 Console.WriteLine(check[i].ConvertToVB("str1"));
             }
         }
         else
         {
             ICodeChecker Check = check[i] as ProgramHelper;
             Console.WriteLine(check[i].ConvertToCSharp("str1"));
             Console.WriteLine(check[i].ConvertToVB("str1"));
         }
     }
     Console.ReadLine();
 }
Пример #7
0
        static void Main(string[] args)
        {
            string someCode = "code ;";

            Console.WriteLine($"Code to perform tests with : {someCode}");
            int size = 2;

            ProgramConverter[] array = new ProgramConverter[size];
            array[0] = new ProgramHelper();
            array[1] = new ProgramConverter();
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine($"\nCurrent index of array is [{i}] : ");
                if (array[i] is ICodeChecker)
                {
                    Console.WriteLine("This object realize ICodeChecker");

                    _IConvertible.IConvertible convertible = array[i];
                    Console.WriteLine(convertible.ConvertToCSharp(someCode) + "\n\t : Converted to CSharp");
                    Console.WriteLine(convertible.ConvertToVB(someCode) + "\n\t : Converted to VB");

                    ICodeChecker codeChecker = (ICodeChecker)array[i];
                    string       result      = codeChecker.CheckCodeSyntax(someCode, "CSharp") switch {
                        true => "Correct code",
                        _ => "Invalid code",
                    };
                    Console.WriteLine(result + " for CSharp");
                    result = codeChecker.CheckCodeSyntax(someCode, "VB") switch {
                        true => "Correct code",
                        _ => "Invalid code",
                    };
                    Console.WriteLine(result + " for VB");
                }
                else
                {
                    Console.WriteLine("This object realize IConvertible");

                    _IConvertible.IConvertible convertible = array[i];
                    Console.WriteLine(convertible.ConvertToCSharp(someCode) + "\n\t : Converted to CSharp");
                    Console.WriteLine(convertible.ConvertToVB(someCode) + "\n\t : Converted to VB");
                }
            }
        }