Рассмотрите следующее:
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
public class NotNullAttribute : Attribute
{
}
public class Class1
{
[return: NotNull]
public static string TestMethod([NotNull] string arg)
{
return arg + " + " + arg;
}
}
Как, с помощью Системы. Отражение, Вы видели бы, что атрибут NotNullAttribute был применен к возвращаемому значению метода? Если Вы не можете, что является целью позади [возврат:] синтаксис?
MethodInfo имеет свойство ReturnTypeCustomAttributes, если вы вызываете GetCustomAttributes () для этого, вы получите возвращаемое значение atrtibutes.
MethodInfo mi = typeof(Class1).GetMethod("TestMethod");
object[] attrs = mi.ReturnTypeCustomAttributes.GetCustomAttributes(true);