attributes

Possible to validate a .NET Attibute parameter?

I am wondering if it is possible to validate parameters to (custom) .net attributes. eg: If I had an attribute that takes a positive integer, could I force a compile time error when a negative value was supplied? [DonkeyAttribute(1)] //OK [DonkeyAttribute(-828)] //error In this example I could use an unsigned integer (but that is non...

What is the meaning of this attribute in .NET

What is the meaning of this attribute? <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select, True)> _ ...

How to do mutually exclusive attributes in XML schema?

I'm trying to make two XML attributes to be mutually exclusive. How can one create an XSD schema to capture this kind of scenario? I would like to have one of these <elem value="1" /> <elem ref="something else" /> but not <elem value="1" ref="something else" /> ...

How to stop event propagation with inline onclick attribute?

Consider the following: <div onclick="alert('you clicked the header')" class="header"> <span onclick="alert('you clicked inside the header');">something inside the header</span> </div> How can I make it so that when the user clicks the span, it does not fire the div's onclick event? ...

use a global setting as an attribute argument

I want to specify an argument in an attribute, like this: [OutputCache(Duration = GlobalSettings.GlobalVar)] Where GlobalVar is a variable I defined only once (don't care where). Using a configuration setting doesn't work anyhow, and I can't get it working with some static class either. I get the error: An attribute argument must be...

How can I add my attributes to Code-Generated Linq2Sql classes properties?

Hi I would like to add attributes to Linq 2 Sql classes properties. Such as this Column is browsable in the UI or ReadOnly in the UI and so far. I've thought about using templates, anybody knows how to use it? or something different? Generally speaking, would do you do to address this issue with classes being code-generated? ...

Best practices: When should I use elements and when should I use attributes?

Which would be the correct format for this XML data, are they equivalent or are there trade offs between the two? 1. <sitemap> <category name="Animals"> <section title="Dogs"> <page url="/pics/greatdane.jpg" title="Great Dane"/> </section> </category> </sitemap> 2. <sitemap> <page> <category>Animals</category...

Is it true that NHibernate ISession.save(newTransientEntity) will only return generated Id, but NOT updating the Id property of the entity?

Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA { ... [Id][Generator(class="guid")] public Guid Id {...} [Property] public string Property1 {...} ... } Let say if I add a transient entity to the persistence context with code like this: ... Guid id; using(IS...

.NET Attributes: Why does GetCustomAttributes() make a new attribute instance every time?

So I was playing around a little more with attributes in .NET, and realized that every call to Type.GetCustomAttributes() creates a new instance of my attribute. Why is that? I would think that the attribute instance would basically be a singleton-per-MemberInfo, with 1 instance bound to the Type, PropertyInfo, etc... Here is my test co...

Is it possible to dynamically inject the attribute using IoC like Ninject or other IoC?

I am extending my Object Property Value Diff but I realized if an object has too many properties I may not want to diff them all. So I came up with the public class IgnorePropertyDiffAttribute : System.Attribute { } so that I can mark the properties I want the diff to ignore. However I don’t want to pollute my domain object with [Ign...

Can I just make up attributes on my HTML tags?

Am I allowed to add whatever attributes I want to HTML tags such that I can retrieve their value later on using javascript? For example: <a href="something.html" hastooltip="yes" tipcolour="yellow">...</a> If that's not going to work, how would you store arbitrary pieces of information like this? Edit: Since it appears that making up...

Why do managed attributes just work for class attributes and not for instance attributes in python?

To illustrate the question check the following code: class MyDescriptor(object): def __get__(self, obj, type=None): print "get", self, obj, type return self._v def __set__(self, obj, value): self._v = value print "set", self, obj, value return None class SomeClass1(object): m = MyDescriptor() class SomeClass2...

How to you inspect or look for .NET attributes?

I have an enumeration for Status for a Task. Some of the statuses are considered obsolete, and I have marked them as obsolete, as seen below: public enum TaskStatus { [Description("")] NotSet = 0, Pending = 1, Ready = 2, Open = 3, Completed = 4, Closed = 5, [Description("On Hold")][Obsolete] OnHold =...

How can I assign a new class attribute via __dict__ in python?

I want to assign a class attribute via a string object - but how? Example: class test(object): pass a = test() test.value = 5 a.value # -> 5 test.__dict__['value'] # -> 5 # BUT: attr_name = 'next_value' test.__dict__[attr_name] = 10 # -> 'dictproxy' object does not support item assignment ...

Is it possible to mark a property shown in a property grid as a password field

I'm using C# and have a windows form containing a property grid control. I have assigned the SelectedObject of the propertygrid to a settings file, which displays and lets me edit the settings. However one of the settings is a password - and I'd like it to display asterisks in the field rather than the plain text value of the password ...

jQuery 1.3 - Issue with Setting an Attribute Value

This is my first stackoverflow question, so try to be nice. ;-D My issue is this, I am refactoring some existing javascript code and using jQuery to do it. In several places I've come across javascript code similar to the following: // some js code working with the customAttribute value javascriptElementObject.customAttribue = void(0);...

C# - Attribute to Skip over a Method while Stepping in Debug Mode

Is there an attribute I can use on a method so that when stepping through some code in Debug mode the Debugger stays on the outside of the method? ...

What was the Historical Precursor for .NET Attributes?

What languages or platforms influenced the .NET 1.0 Team to build-in the concept of Attributes from the very start? Was this an Aspect-Oriented thing? Serialization? or something else? I was still in VB6-land at this time, and never used any of the pre-1.0 .NET versions. ...

What is the best way to get a property and value with a particular attribute?

Given this definition: [UniqueId("Ident")] public class MyClass : MyBase { public int Ident{ get; } } What is the best way from the "MyBase" class to get the "UniqueId" attribute, find the matching property name and get the underlying value? ...

ASP.NET MVC Authorization based on role membership or data relation (ownership)

I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at http://stackoverflow.com/questions/390930/asp-net-mvc-authorization-using-roles....