예제 #1
0
        public void TestAnonymousTypeProperties()
        {
            var    sourceTemplate = @"
class C
{{
    object M()
    {{
        return new {{ {0} = 1, {0}1 = 'a' }};
    }}
}}
";
            int    padding        = GeneratedNames.MakeAnonymousTypeBackingFieldName("A").Length - 1;
            string longName       = s_longSymbolName.Substring(padding);
            var    source         = string.Format(sourceTemplate, longName);
            var    comp           = CreateCompilationWithMscorlib(source);

            comp.VerifyDiagnostics();

            // CONSIDER: Double reporting (once for field def, once for member ref) is not ideal.
            // CONSIDER: No location since the synthesized field symbol doesn't have one (would light up automatically).
            comp.VerifyEmitDiagnostics(
                // error CS7013: Name '<longName1>i__Field' exceeds the maximum length allowed in metadata.
                Diagnostic(ErrorCode.ERR_MetadataNameTooLong).WithArguments("<" + longName + 1 + ">i__Field").WithLocation(1, 1),
                // error CS7013: Name '<longName1>i__Field' exceeds the maximum length allowed in metadata.
                Diagnostic(ErrorCode.ERR_MetadataNameTooLong).WithArguments("<" + longName + 1 + ">i__Field").WithLocation(1, 1));
        }