编辑代码

using System;

namespace ET
{
    // 定义 EnableClassAttribute
    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class EnableClassAttribute : BaseAttribute
    {
        // 可以在这里添加任何你需要的属性或方法
    }

    // 定义 BaseAttribute
    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
    public class BaseAttribute : Attribute
    {
        // 基类特性可以在这里定义通用的属性或方法
    }
}

// 使用示例
namespace Example
{
    [ET.EnableClass]
    public class MyClass
    {
        public void MyMethod()
        {
            // 方法实现
        }

        public void CheckAttributes()
        {
            var classType = this.GetType();

            // 检查类上是否有 EnableClassAttribute
            if (classType.IsDefined(typeof(ET.EnableClassAttribute), false))
            {
                Console.WriteLine("Class has EnableClassAttribute");
            }

            // 检查类上是否有 BaseAttribute(包括继承的)
            if (classType.IsDefined(typeof(ET.BaseAttribute), false))
            {
                Console.WriteLine("Class has BaseAttribute");
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        var myObject = new Example.MyClass();
        myObject.CheckAttributes();
    }
}