Questions tagged [custom-attributes]

In .NET Framework, custom attributes are user defined attributes which enable providing metadata for application elements such as assemblies, classes and methods.

In .NET Framework, custom attributes are user defined attributes which enable providing metadata for application elements such as assemblies, classes and methods.

1173 questions
39
votes
5 answers

Custom attribute on property - Getting type and value of attributed property

I have the following custom attribute, which can be applied on properties: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class IdentifierAttribute : Attribute { } For example: public class MyClass { [Identifier()] …
Alex
  • 37,502
  • 51
  • 204
  • 332
39
votes
1 answer

What's the difference between implementing FilterAttribute, IActionFilter and inheriting from ActionFilterAttribute in asp.net mvc 3?

I see that in one situation we can override OnActionExecuting or OnActionExecuted methods inheriting from ActionFilterAttribute class like this: public class MyFilterAttribute : ActionFilterAttribute { public override void…
37
votes
2 answers

Custom attributes in Android fragments

I'd like to define custom attributes in Android fragment using XML (without using bundle additional parameters) like declare-styleable in custom controls. But there are no constructors with AttrSet parameters, so is it possible? Can i just override…
Anton
  • 1,903
  • 3
  • 16
  • 18
37
votes
4 answers

Adding attributes to customer entity

my current goal is to add a new customer attribute (with int type) which should appear as select with predefined options (loaded from a model with entries editable in backend, which is done). I'm struggling with proper use of…
Zifius
  • 1,650
  • 1
  • 16
  • 27
35
votes
3 answers

Using an array reference as an XML attribute for custom android view

This problem has been solved, see comments for details. I am extending an existing Android View and loading some custom attributes, as described in Declaring a custom android UI element using XML and Defining custom attrs. Attributes with boolean…
35
votes
7 answers

Get enum from enum attribute

I've got public enum Als { [StringValue("Beantwoord")] Beantwoord = 0, [StringValue("Niet beantwoord")] NietBeantwoord = 1, [StringValue("Geselecteerd")] Geselecteerd = 2, [StringValue("Niet geselecteerd")] NietGeselecteerd =…
RubenHerman
  • 1,674
  • 6
  • 23
  • 42
30
votes
2 answers

Custom Attributes in Android

I'm trying to create a custom attribute called Tag for all editable elements. I added the following to attrs.xml
Arun
  • 3,036
  • 3
  • 35
  • 57
29
votes
1 answer

Custom HTML tag attributes are not rendered by JSF

I want to add some iOS specific tag attributes to my login-form. If I have a look on my web page source, the attributes autocorrect, autocapitalize and spellcheck aren't there. What is the reason for this? I am using JSF 2.x.
Jochen
  • 1,746
  • 4
  • 22
  • 48
29
votes
2 answers

Getting the type of a MemberInfo with reflection

I'm using reflection to load a treeview with the class structure of a project. Each of the members in a class have a custom attribute assigned to them. I don't have a problem getting the attributes for a class using MemberInfo.GetCustomAttributes()…
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
28
votes
1 answer

Re-using Android Custom enum xml attributes

I'm defining a custom attribute in XML that is an enum.It looks something like this:
ptoinson
  • 2,013
  • 3
  • 21
  • 30
27
votes
4 answers

React Typescript - Adding custom attribute

React Typescript allow to add custom data-* attributes. But is it possible to add custom attributes like 'name' || 'test' act. ? Bold added by me. type error: Type '{ children:…
Yaniv Peretz
  • 1,118
  • 2
  • 13
  • 22
27
votes
2 answers

How to put conditional Required Attribute into class property to work with WEB API?

I just want to put conditional Required Attribute which is work with WEB API Example public sealed class EmployeeModel { [Required] public int CategoryId{ get; set; } public string Email{ get; set; } // If CategoryId == 1 then it…
Shubhajyoti Ghosh
  • 1,292
  • 5
  • 27
  • 45
26
votes
1 answer

get all types in assembly with custom attribute

Is there an elegant way to get all the types in an assembly that have a custom attribute? So if I have a class [Findable] public class MyFindableClass {} I would like to be able to find it in a collection of types returned by…
Aidan
  • 4,783
  • 5
  • 34
  • 58
26
votes
6 answers

Adding custom property attributes in Entity Framework code

Is there any way to add custom attributes to properties in EF generated code? The only thing I can see as a plausible solution would be to come up with a custom T4 template. However, because of the nature of the attribute it would be impossible to…
AKoran
  • 1,846
  • 6
  • 22
  • 36
25
votes
8 answers

Adding name attribute to `User` in Devise

I'm trying to add a name attribute to the User model provided by Devise. I added a "name" column to my database, and changed the sign up view so that it asks for the user's name:

Sign up

<%= form_for(resource, :as => resource_name, :url…
steffi2392
  • 1,345
  • 3
  • 19
  • 19
1
2
3
78 79