コード例 #1
0
    public bool PosTest1()
    {
        bool retVal = true;

        const string         c_TEST_DESC = "PosTest1:check the MethodImplAttributes.IL value is 0x0000...";
        const string         c_TEST_ID   = "P001";
        MethodImplAttributes FLAG_VALUE  = (MethodImplAttributes)0x0000;

        TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);

        try
        {
            if (MethodImplAttributes.IL != FLAG_VALUE)
            {
                string errorDesc = "value " + FLAG_VALUE.ToString() + " is not as expected: Actual is " + MethodImplAttributes.IL.ToString();
                TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
コード例 #2
0
    public static void Main()
    {
        // Use reflection to get a reference to the GetCalendarName method.
        Assembly   assem      = Assembly.LoadFrom(@".\Example.dll");
        Type       type       = assem.GetType("Utility");
        MethodInfo methodInfo = type.GetMethod("GetCalendarName");

        // Determine whether the method has any custom attributes.
        Console.Write("Utility.GetCalendarName custom attributes:");
        object[] attribs = methodInfo.GetCustomAttributes(false);
        if (attribs.Length > 0)
        {
            Console.WriteLine();
            foreach (var attrib in attribs)
            {
                Console.WriteLine("   " + attrib.ToString());
            }
        }
        else
        {
            Console.WriteLine("   <None>");
        }

        // Get the method's metadata flags.
        MethodImplAttributes flags = methodInfo.GetMethodImplementationFlags();

        Console.WriteLine("Utility.GetCalendarName flags: {0}",
                          flags.ToString());
    }