Force the usage of an attribute on properties, if they already have another attribute

Offler

I want to force the usage of an attribute, if another attribute is used. If a special 3rd party attribute is attached to a property, this attribute also needs to be given to a property. Is there any possibility of doing this?

For example:

[Some3rdPartyAttribute("...")]
[RequiredAttribute("...)]
public bool Example{get; set;}

should bring no compile error,

[Some3rdPartyAttribute("...")]
public bool Example{get; set;}

should bring a compile error or warning.

The attribute itself is definded like the example from http://msdn.microsoft.com/en-US/library/z919e8tw(v=vs.80).aspx itself . But how to force the usage of the attribute if another attribute is used?

Tigran

Another option is using some AOP techniques. Like for example:

PostSharp.

Using it you can at compilation analyze yur code and emit a error if some condition does not sutisfies your requirements.

For concrete example on attributes, can have a look on :

PostSharp 2.1: Reflecting Custom Attributes

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

is it possible for an interface to have an already instanced object as an attribute?

From Dev

Pass Attribute to another attribute

From Dev

Select attribute of another attribute of entity

From Dev

jQuery - Adding an Attribute into Another Attribute?

From Dev

ExpectedException Attribute Usage

From Dev

Ant Macrodef attribute usage

From Dev

ExpectedException Attribute Usage

From Dev

Boost Spirit: force an attribute on a no-attribute parser

From Dev

Boost Spirit: force an attribute on a no-attribute parser

From Dev

Xpath Getting All Nodes that Have an Attribute that Matches Another Node

From Dev

XPath: How to select all elements which have one attribute or another

From Dev

Xpath Getting All Nodes that Have an Attribute that Matches Another Node

From Dev

Have Required Attribute apply to property in one view and not another?

From Dev

MinValue & MaxValue attribute for properties

From Dev

DebuggerStepThrough attribute equivalent for properties?

From Dev

Filtering ngOptions by properties of an attribute

From Dev

FactoryGirl Inheritance attribute already defined

From Dev

attribute insetForeground has already be defined

From Dev

Force a custom attribute using an interface

From Dev

Force parameter as Service contract attribute

From Dev

Attribute "title" has already been define when have android plot dependencies 1.0.0

From Dev

XSL pass attributes to child elements if child elements do not already have the same attribute

From Dev

XML attribute usage "android:focusableInTouchMode"

From Dev

Wrong usage of conf attribute of ivy

From Dev

Automatically update attribute when another attribute is updated

From Dev

XSLT: Creating new attribute with value of another attribute

From Dev

Constraining attribute values based on another attribute

From Dev

XSLT: Creating new attribute with value of another attribute

From Dev

C# XDocument: Find Attribute by another Attribute

Related Related

  1. 1

    is it possible for an interface to have an already instanced object as an attribute?

  2. 2

    Pass Attribute to another attribute

  3. 3

    Select attribute of another attribute of entity

  4. 4

    jQuery - Adding an Attribute into Another Attribute?

  5. 5

    ExpectedException Attribute Usage

  6. 6

    Ant Macrodef attribute usage

  7. 7

    ExpectedException Attribute Usage

  8. 8

    Boost Spirit: force an attribute on a no-attribute parser

  9. 9

    Boost Spirit: force an attribute on a no-attribute parser

  10. 10

    Xpath Getting All Nodes that Have an Attribute that Matches Another Node

  11. 11

    XPath: How to select all elements which have one attribute or another

  12. 12

    Xpath Getting All Nodes that Have an Attribute that Matches Another Node

  13. 13

    Have Required Attribute apply to property in one view and not another?

  14. 14

    MinValue & MaxValue attribute for properties

  15. 15

    DebuggerStepThrough attribute equivalent for properties?

  16. 16

    Filtering ngOptions by properties of an attribute

  17. 17

    FactoryGirl Inheritance attribute already defined

  18. 18

    attribute insetForeground has already be defined

  19. 19

    Force a custom attribute using an interface

  20. 20

    Force parameter as Service contract attribute

  21. 21

    Attribute "title" has already been define when have android plot dependencies 1.0.0

  22. 22

    XSL pass attributes to child elements if child elements do not already have the same attribute

  23. 23

    XML attribute usage "android:focusableInTouchMode"

  24. 24

    Wrong usage of conf attribute of ivy

  25. 25

    Automatically update attribute when another attribute is updated

  26. 26

    XSLT: Creating new attribute with value of another attribute

  27. 27

    Constraining attribute values based on another attribute

  28. 28

    XSLT: Creating new attribute with value of another attribute

  29. 29

    C# XDocument: Find Attribute by another Attribute

HotTag

Archive