public static Object FromNamedItem(CodeGenerationConfigBuilder builder, INamedItem namedItem)
        {
            Object returnItem = null;

            if (namedItem is RoslynClassMetadata classMetadata && ClassImpl.FromMetadata(classMetadata, null) is Class @class)
            {
                returnItem = @class;
            }
            if (namedItem is RoslynEnumMetadata enumMetadata && EnumImpl.FromMetadata(enumMetadata, null) is Enum @enum)
            {
                returnItem = @enum;
            }
            if (namedItem is RoslynInterfaceMetadata interfaceMetadata && InterfaceImpl.FromMetadata(interfaceMetadata, null) is Interface @interface)
            {
                returnItem = @interface;
            }
            if (returnItem != null)
            {
                returnItem.Template = builder.Input.Template;
            }
            return(returnItem);
        }
 private void Txtsearch_TextChanged(object sender, TextChangedEventArgs e)
 {
     try
     {
         if (txtsearch.Text == "")
         {
             clImpl = new ClassImpl();
             dgvDatos.ItemsSource = null;
             dgvDatos.ItemsSource = clImpl.Select(Course).DefaultView;
             Ocultar();
         }
         else
         {
             clImpl = new ClassImpl();
             dgvDatos.ItemsSource = null;
             dgvDatos.ItemsSource = clImpl.Selectlike(Course, txtsearch.Text).DefaultView;
             Ocultar();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
    private static int Main()
    {
        const int numCalcIters = 1000000;
        const int countUpIters = 1000000;

        int x        = numCalcIters;
        S32 s        = default;
        int expected = 0;

        while (x != 0)
        {
            if (x % 2 == 0)
            {
                s = default;
            }

            Calc(ref x, ref s, ref expected);
        }

        bool result = true;

        void Test <T>(Func <T> f, T expected, string name)
        {
            Console.Write("{0}: ", name);
            Stopwatch timer = Stopwatch.StartNew();
            T         val   = f();

            timer.Stop();
            if (val.Equals(expected))
            {
                Console.WriteLine("OK in {1} ms", name, timer.ElapsedMilliseconds);
                return;
            }

            Console.WriteLine("FAIL (expected {1}, got {2})", name, expected, val);
            result = false;
        }

        void TestCalc <T>(Func <int, int, T> f, T expected, string name)
        => Test(() => f(numCalcIters, 0), expected, name);

        ClassImpl c = new ClassImpl();

        c.Other = c;

        InterfaceImpl i = new InterfaceImpl();

        i.Other = i;

        GenInstance <string, int>      g   = new GenInstance <string, int>();
        IGenInterface <string, int>    ig  = new GenInterfaceImpl <string, int>();
        IGenInterface <string, object> ig2 = new GenInterfaceImpl <string, object>();
        GenAbstractImpl <string>       ga1 = new GenAbstractImpl <string>();
        GenAbstractImpl <int>          ga2 = new GenAbstractImpl <int>();

        long expectedI8  = (long)(((ulong)(uint)expected << 32) | (uint)expected);
        S16  expectedS16 = new S16 {
            A = expected, B = expected,
        };
        S32 expectedS32 = new S32 {
            A = expected, B = expected, C = expected, D = expected,
        };
        int ten = 10;

        TestCalc(CalcStatic, expected, "Static non-generic");
        TestCalc(CalcStaticSmall, (byte)expected, "Static non-generic small");
        TestCalc(CalcStaticRetbuf, expectedS32, "Static non-generic retbuf");
        TestCalc(CalcStaticLong, expectedI8, "Static non-generic long");
        TestCalc(CalcStaticS16, expectedS16, "Static non-generic S16");
        TestCalc((x, s) => { CalcStaticVoid(x, s); return(s_result); }, expected, "Static void");
        TestCalc(new Instance().CalcInstance, expected, "Instance non-generic");
        TestCalc(new Instance().CalcInstanceRetbuf, expectedS32, "Instance non-generic retbuf");
        TestCalc(c.CalcAbstract, expected, "Abstract class non-generic");
        TestCalc(c.CalcAbstractRetbuf, expectedS32, "Abstract class non-generic retbuf");
        TestCalc(i.CalcInterface, expected, "Interface non-generic");
        TestCalc(i.CalcInterfaceRetbuf, expectedS32, "Interface non-generic retbuf");
        TestCalc(CalcStaticCalli, expected, "Static calli");
        TestCalc(CalcStaticCalliRetbuf, expectedS32, "Static calli retbuf");
        TestCalc(new Instance().CalcInstanceCalli, expected, "Instance calli");
        TestCalc(new Instance().CalcInstanceCalliRetbuf, expectedS32, "Instance calli retbuf");
        Test(() => EmptyCalli(), "Empty calli", "Static calli without args");
        Test(() => ValueTypeInstanceMethodCalli(), "Instance method", "calli to an instance method on a value type");
        Test(() => ValueTypeExplicitThisInstanceMethodCalli(), "Instance method", "calli to an instance method on a value type with explicit this");
        Test(() => { var v = new InstanceValueType(); v.CountUp(countUpIters); return(v.Count); }, countUpIters, "Value type instance call");
        Test(() => new Instance().GC("2", 3, "4", 5, "6", "7", "8", 9, ref ten), "2 3 4 5 6 7 8 9 10", "Instance with GC");
        Test(() => CountUpHeap(countUpIters, new HeapInt(0)), countUpIters, "Count up with heap int");
        Test(() => { int[] val = new int[1]; CountUpRef(countUpIters, ref val[0]); return(val[0]); }, countUpIters, "Count up with byref to heap");
        Test(() => GenName1Forward("hello"), "System.String hello", "Static generic string");
        Test(() => GenName1Forward <object>("hello"), "System.Object hello", "Static generic object");
        Test(() => GenName1Forward(5), "System.Int32 5", "Static generic int");
        Test(() => GenName2ForwardBoth("hello", (object)"hello2"), "System.String System.Object hello hello2", "Static generic 2 string object");
        Test(() => GenName2ForwardBoth("hello", 5), "System.String System.Int32 hello 5", "Static generic 2 string int");
        Test(() => GenName2ForwardOne("hello", "hello2"), "System.String System.String hello hello2", "Static generic 1 string");
        Test(() => GenName2ForwardOne((object)"hello", "hello2"), "System.Object System.String hello hello2", "Static generic 1 object");
        Test(() => GenName2ForwardOne(5, "hello2"), "System.Int32 System.String 5 hello2", "Static generic 1 int");
        Test(() => GenName2ForwardNone("hello", "hello2"), "System.Object System.String hello hello2", "Static generic 0");
        Test(() => g.NonVirtForward <object, string>("a", 5, "b", "c"),
             "System.String System.Int32 System.Object System.String a 5 b c", "Instance generic 4");
        Test(() => g.VirtForward <object, string>("a", 5, "b", "c"),
             "System.String System.Int32 System.Object System.String a 5 b c", "Virtual instance generic 4");
        Test(() => GenInterfaceForwardF <string, int, string, object>("a", 5, "c", "d", ig),
             "System.String System.Int32 System.String System.Object a 5 c d", "Interface generic 4");
        Test(() => GenInterfaceForwardG <string, int>("a", 5, ig),
             "System.String System.Int32 a 5", "Interface generic forward G");
        Test(() => GenInterfaceForwardNone("a", "b", 5, "d", ig2),
             "System.String System.Object System.Int32 System.Object a b 5 d", "Interface generic 0");
        Test(() => GenInterfaceForward2("a", "b", ig2),
             "System.String System.Object a b", "Interface generic without generics on method");
        Test(() => GenAbstractFString(ga1), "System.String System.Object", "Abstract generic with generic on method 1");
        Test(() => GenAbstractFInt(ga2), "System.Int32 System.Object", "Abstract generic with generic on method 2");
        Test(() => GenAbstractGString(ga1), "System.String", "Abstract generic without generic on method 1");
        Test(() => GenAbstractGInt(ga2), "System.Int32", "Abstract generic without generic on method 2");

        if (result)
        {
            Console.WriteLine("All tailcall-via-help succeeded");
        }
        else
        {
            Console.WriteLine("One or more failures in tailcall-via-help test");
        }

        return(result ? 100 : 1);
    }