首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

在.Net中,为什么在调用Type.GetCustomAttributes(true)时返回的接口上没有声明属性?

在.Net中,调用Type.GetCustomAttributes(true)方法时返回的接口上没有声明属性的原因是因为接口本身不支持属性的声明。

接口是一种抽象的类型,用于定义一组方法、属性、事件和索引器的集合,但接口本身并不包含实现。在接口中,只能声明方法、事件、索引器和自动属性,而不能声明具有实际实现的属性。

当调用Type.GetCustomAttributes(true)方法时,该方法会返回指定类型的所有自定义属性。自定义属性是一种用于为类型、成员或程序集添加元数据的特性。然而,由于接口本身不支持属性的声明,因此在接口上调用该方法时返回的结果中不会包含任何属性。

需要注意的是,虽然接口本身不支持属性的声明,但可以在实现接口的类中声明属性,并通过类的实例来访问这些属性。

总结起来,在.Net中调用Type.GetCustomAttributes(true)方法返回的接口上没有声明属性,是因为接口本身不支持属性的声明。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • Aop介绍及几种实现方式

    Aop介绍 我们先看一下wiki百科的介绍 Traditional software development focuses on decomposing systems into units of primary functionality, while recognizing that there are other issues of concern that do not fit well into the primary decomposition. The traditional development process leaves it to the programmers to code modules corresponding to the primary functionality and to make sure that all other issues of concern are addressed in the code wherever appropriate. Programmers need to keep in mind all the things that need to be done, how to deal with each issue, the problems associated with the possible interactions, and the execution of the right behavior at the right time. These concerns span multiple primary functional units within the application, and often result in serious problems faced during application development and maintenance. The distribution of the code for realizing a concern becomes especially critical as the requirements for that concern evolve – a system maintainer must find and correctly update a variety of situations.

    02
    领券