Attributes in C#

前端 未结 8 723
时光说笑
时光说笑 2020-11-30 04:08

I know that C# (and .NET in general) is big on attributes. However, despite the fact I have programmed in C# for many years, I haven\'t found myself ever using them. Would s

相关标签:
8条回答
  • 2020-11-30 04:26

    I use attributes for the following:

    • Communicating with a plug-in architecture
    • Telling another framework what to do with the code (NUnit, for instance)
    • Adding metadata for use with other code (See PropertyGrid)
    • Mapping objects to databases (See Castle ActiveRecord)
    • When writing my own APIs to allow users to communicate metadata
    • In framework code to tell the debugger to skip over it

    Those are off the top of my head. I use them in many other places

    0 讨论(0)
  • 2020-11-30 04:35

    Class Attribute definition is available here

    ClassInterfaceAttribute : Indicates the type of class interface to be generated for a class exposed to COM, if an interface is generated at all.

    ComDefaultInterfaceAttribute : Specifies a default interface to expose to COM. This class cannot be inherited.

    ComVisibleAttribute: Controls accessibility of an individual managed type or member, or of all types within an assembly, to COM.

    0 讨论(0)
提交回复
热议问题