private static void TestMyStruct() { Console.WriteLine(MethodBase.GetCurrentMethod().Name); MyStruct foo = new MyStruct(); var resA1 = foo.GetAnnotation <MyStruct>(); var resA2 = foo.GetAnnotation <MyStruct>(nameof(MyStruct.MyString)); var resA3 = foo.GetAnnotation <MyStruct>("MyField"); Console.WriteLine($"{nameof(resA1)}: {resA1}"); Console.WriteLine($"{nameof(resA2)}: {resA2}"); Console.WriteLine($"{nameof(resA3)}: {resA3}"); foo = new MyStruct(); var resB1 = foo.GetAnnotation <MyStruct>(); var resB2 = foo.GetAnnotation <MyStruct>(nameof(MyStruct.MyString)); var resB3 = foo.GetAnnotation <MyStruct>("MyField"); Console.WriteLine($"{nameof(resB1)}: {resB1}"); Console.WriteLine($"{nameof(resB2)}: {resB2}"); Console.WriteLine($"{nameof(resB3)}: {resB3}"); var resC1 = typeof(MyStruct).GetAnnotation(); var resC2 = foo.GetType().GetAnnotation(); var resC3 = typeof(MyStruct).GetAnnotation("MyString"); var resC4 = foo.GetType().GetAnnotation("MyString"); Console.WriteLine($"{nameof(resC1)}: {resC1}"); Console.WriteLine($"{nameof(resC2)}: {resC2}"); Console.WriteLine($"{nameof(resC3)}: {resC3}"); Console.WriteLine($"{nameof(resC4)}: {resC4}"); }