Attributes in C#

前端 未结 8 750
时光说笑
时光说笑 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

提交回复
热议问题