This is due to a question about return type attributes and anonymous classes , but then for anonymous methods (or lambdas), but so far I could find this exact question, it seems, until it is in stackoverflow.
In the code for business objects that we generate using CodeSmith, we now have attributes [DebuggerNonUserCode], so they are not taken into account in the results of code coverage. Unfortunately, the generated code uses anonymous methods, which are now still displayed in code scope with type names Class.<>c__DisplayClass3cdue to how they are actually handled by the compiler.
A quick code example, with names and types changed to protect the innocent, so to speak:
public delegate T ReturnSomething<T>();
public static T SafeCall<T>(T whenNotSupported, ReturnSomething<T> method)
{
T result;
try
{
result = method();
}
catch (NotSupportedException)
{
result = whenNotSupported;
}
return result;
}
public static void CodeExample()
{
string foo = SafeCall<string>("OOPS!", delegate
{
return "Ok";
});
}
[DebuggerNonUserCode] , , , ? , ?
[DebuggerNonUserCode] method SafeCall ( ReturnSomething<T>) , , , , . :
public static void CodeExample()
{
string foo = SafeCall<string>("OOPS!", [DebuggerNonUserCode] delegate
{
return "Ok";
});
}
CSharp, , ( lambdas). , (?) ...?