编辑代码

using System;

public class HelpAttribute : Attribute
{
 string _url;
 string _topic;
 public HelpAttribute(string url) => _url = url;
 public string Url => _url;
 public string Topic
 {
 get => _topic;
 set => _topic = value;
 }
}

[Help("https://docs.microsoft.com/dotnet/csharp/tour-of-csharp/features")]
public class Widget
{
 [Help("https://docs.microsoft.com/dotnet/csharp/tour-ofcsharp/features", Topic = "Display")]
 public void Display(string text) { }
}

public class Demo{
	public static void Main(){
		Type widgetType = typeof(Widget);
		object[] widgetClassAttributes =
		widgetType.GetCustomAttributes(typeof(HelpAttribute), false);
		if (widgetClassAttributes.Length > 0)
		{
		 HelpAttribute attr = (HelpAttribute)widgetClassAttributes[0];
		 Console.WriteLine($"Widget class help URL : {attr.Url} \n Related topic :{attr.Topic}\n ");
		}
		System.Reflection.MethodInfo displayMethod =
		widgetType.GetMethod(nameof(Widget.Display));
		object[] displayMethodAttributes =
		displayMethod.GetCustomAttributes(typeof(HelpAttribute), false);
		if (displayMethodAttributes.Length > 0)
		{
		 HelpAttribute attr = (HelpAttribute)displayMethodAttributes[0];
		 Console.WriteLine($"Display method help URL : {attr.Url} \n  Related topic: {attr.Topic}\n ");
		}  
	}
}