Questions tagged [attributes]

The attributes tag should be used for any issues relating to a property of an object, element, or file, etc.

In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such.

For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property.

However, in actual usage, the term attribute can and is often treated as equivalent to a property, depending on the technology being discussed.

An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.

  • Each named attribute has an associated set of rules called operations: one doesn't sum characters or manipulate and process an integer array as an image object — one doesn't process text as type floating point (decimal numbers).
  • It follows that an object definition can be extended by imposing data typing: a representation format, a default value, and legal operations (rules) and restrictions ("Division by zero is not to be tolerated!") are all potentially involved in defining an attribute, or conversely, may be spoken of as attributes of that object's type. A JPEG file is not decoded by the same operations (however similar they may be—these are all graphics data formats) as a PNG or BMP file, nor is a floating point typed number operated upon by the rules applied to typed long integers.

See also:

13044 questions
169
votes
11 answers

Get list of data-* attributes using javascript / jQuery

Given an arbitrary HTML element with zero or more data-* attributes, how can one retrieve a list of key-value pairs for the data. E.g. given this:
blah
I would like to be able to…
Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
169
votes
3 answers

Why "decimal" is not a valid attribute parameter type?

It is really unbelievable but real. This code will not work: [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)] public class Range : Attribute { public decimal Max { get; set; } public decimal Min { get; set; } } public…
Cheng Chen
  • 42,509
  • 16
  • 113
  • 174
167
votes
8 answers

What are the best practices for using Assembly Attributes?

I have a solution with multiple project. I am trying to optimize AssemblyInfo.cs files by linking one solution wide assembly info file. What are the best practices for doing this? Which attributes should be in solution wide file and which are…
Jakub Šturc
  • 35,201
  • 25
  • 90
  • 110
162
votes
11 answers

How to Compare Flags in C#?

I have a flag enum below. [Flags] public enum FlagTest { None = 0x0, Flag1 = 0x1, Flag2 = 0x2, Flag3 = 0x4 } I cannot make the if statement evaluate to true. FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2; if (testItem ==…
David Basarab
  • 72,212
  • 42
  • 129
  • 156
155
votes
5 answers

What is the difference between class and instance attributes?

Is there any meaningful distinction between: class A(object): foo = 5 # some default value vs. class B(object): def __init__(self, foo=5): self.foo = foo If you're creating a lot of instances, is there any difference in…
Dan Homerick
  • 4,118
  • 7
  • 28
  • 30
151
votes
10 answers

Can attributes be added dynamically in C#?

Is it possible to add attributes at runtime or to change the value of an attribute at runtime?
Jon Turner
  • 2,932
  • 3
  • 22
  • 20
150
votes
6 answers

javascript remove "disabled" attribute from html input

How can I remove the "disabled" attribute from an HTML input using javascript? at onClick I want my input tag to not consist of "disabled" attribute.
Sam San
  • 6,567
  • 8
  • 33
  • 51
149
votes
7 answers

Define an 's src attribute in CSS

I need to define an 's src attribute in CSS. Is there a way to specify this attribute?
Massimo Ugues
  • 4,373
  • 8
  • 43
  • 56
144
votes
8 answers

Get all attributes of an element using jQuery

I am trying to go through an element and get all the attributes of that element to output them, for example an tag may have 3 or more attributes, unknown to me and I need to get the names and values of these attributes. I was thinking something…
Styphon
  • 10,304
  • 9
  • 52
  • 86
140
votes
8 answers

Set attributes from dictionary in python

Is it possible to create an object from a dictionary in python in such a way that each key is an attribute of that object? Something like this: d = { 'name': 'Oscar', 'lastName': 'Reyes', 'age':32 } e = Employee(d) print e.name # Oscar print…
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
140
votes
4 answers

Test if a class has an attribute?

I'm trying to do a little Test-First development, and I'm trying to verify that my classes are marked with an attribute: [SubControllerActionToViewDataAttribute] public class ScheduleController : Controller How do I unit test that the class has…
JoshRivers
  • 9,920
  • 8
  • 39
  • 39
135
votes
3 answers

XML Serialization - Disable rendering root element of array

Can I somehow disable rendering of root element of collection? This class with serialization attributes: [XmlRoot(ElementName="SHOPITEM", Namespace="")] public class ShopItem { [XmlElement("PRODUCTNAME")] public string ProductName { get;…
Jan Remunda
  • 7,840
  • 8
  • 51
  • 60
135
votes
10 answers

Custom Compiler Warnings

When using the ObsoleteAtribute in .Net it gives you compiler warnings telling you that the object/method/property is obsolete and somthing else should be used. I'm currently working on a project that requires a lot of refactoring an ex-employees…
Micah
  • 111,873
  • 86
  • 233
  • 325
134
votes
16 answers

NUnit Test Run Order

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?
Riain McAtamney
  • 6,342
  • 17
  • 49
  • 62
133
votes
11 answers

Localization of DisplayNameAttribute

I am looking for a way to localize properties names displayed in a PropertyGrid. The property's name may be "overriden" using the DisplayNameAttribute attribute. Unfortunately attributes can not have non constant expressions. So I can not use…
PowerKiKi
  • 4,539
  • 4
  • 39
  • 47