What are attributes in .NET?
What are attributes in .NET, what are they good for, and how do I create my own attributes? 11 Answers 11
What are attributes in .NET, what are they good for, and how do I create my own attributes? 11 Answers 11
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute] private string _bar; public string BigBar { get { return this._bar; } } } I want to find the private item _bar that I will mark with a attribute. Is that possible? I have done this with properties where I have … Read more
I am learning C# 3.5 and I want to know what [STAThread] does in our programs? 3 Answers 3
I would like to know if it is possible to get attributes of the enum values and not of the enum itself? For example, suppose I have the following enum: using System.ComponentModel; // for DescriptionAttribute enum FunkyAttributesEnum { [Description(“Name With Spaces1”)] NameWithoutSpaces1, [Description(“Name With Spaces2”)] NameWithoutSpaces2 } What I want is given the enum type, … Read more
This causes a compile-time exception: public sealed class ValidatesAttribute<T> : Attribute { } [Validates<string>] public static class StringValidation { } I realize C# does not support generic attributes. However, after much Googling, I can’t seem to find the reason. Does anyone know why generic types cannot derive from Attribute? Any theories? 8 s 8 Well, … Read more
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 8 years ago. Improve this question I know that attributes are extremely useful. There are some predefined ones such as [Browsable(false)] which … Read more