custom-attributes

How to add Custom Attributes to a DynamicMethod-generated method?

I was playing around with DynamicMethod and Expression Trees' Compilation (which uses DynamicMethod internally). I then wondered if there is a way to add a custom attribute to the generated method. I googled about it, but I couldn't find a way. I know that it's possible to do using CodeDom, but I want to use DynamicMethod. Someone ment...

Magento custom attribute default value not showing in front end

Hi there, I have added some custom attributes to the products in the admin section of our Magento 1.3.2.1 installation and I've given some of those attributes default values. The problem is that the default values aren't being returned when I try to get the attribute from the product object as follows: $_product->getCode() Logically...

Specify required base class for .NET attribute targets

I tried to create a custom .NET attribute with the code below but accidentally left off the subclass. This generated an easily-fixed compiler error shown in the comment. // results in compiler error CS0641: Attribute 'AttributeUsage' is // only valid on classes derived from System.Attribute [AttributeUsage(AttributeTargets.Class)] int...

How do I pass in the repository to an authorize attribute in ASP.NET MVC

I am castle Windsor and it works great for controller constructors in passing in the repository that is being used. private IStoryRepository Repository; public StoryController(IStoryRepository Repository) { this.Repository = Repository; } Now I have an Action that is in the admin area to display the main admin ...

A .NET custom attribute to perform impersonation?

I have some methods that need to run as a certain service account, so I do the normal thing: public DoSomeWorkAsServiceAccount() { ... // assume I am given tokenHandle WindowsIdentity newId = new WindowsIdentity(tokenHandle); WindowsImpersonationContext impersonatedUser = newId.Impersonate(); ... // do the work...

Is HTML 5 supported by all the main browsers?

I am looking at the custom attributes feature of html 5 here at this link http://ejohn.org/blog/html-5-data-attributes/ This look like the perfect thing for when I am using jquery/javascript. My question, Is HTML 5 supported by all the main browsers? example <li class="user" data-name="John Resig" data-city="Boston" data-la...

Generating a custom compile time warning C#

Hi all, I'm using VS2008 and would like to create a compile time warning / error based on custom attributes on a property (if it is possible). There are two cases which interest me currently: [MyAttribute (typeof(MyClass)] Where MyClass has to implement an interface. Currently I assert this in the constructor of the attribute, how...

Custom attributes in C#

Hello I have a custom attribute for my page like this: [PageDefinition("My page", "~/Parts/MyPage.aspx")] My PageDefinition looks like this, where AttributeItemDefinitions is get set for Title, Url, IsPage and IsUserControl public class PageDefinition : AttributeItemDefinitions { public PageDefinition(string title, string url) ...

Is there a generic attribute for all HTML elements aside from ID and class?

Like a tag that I can use to store some necessary info? But really isn’t required or used by the HTML? Works like the tag attribute for objects on Visual Basic? ...

How to check if C# class has security attribute used

Hi, How can I check and make sure that a class uses my own custom security attribute? I know that I can use reflection to get normal attributes, but if the custom attribute is based on a security attribute as shown below reflection doesn't show it. Is there any way to check that? Why I would need this is to make sure that a plugin that...

Has anyone come accross a browser where a custom attribute didn't work?

Hi, The web application im working on has a few custom attributes on HTML elements to store data that is output. Only happens here and there and so far I haven't noticed anything wrong in how the page is rendered on IE7, IE8, FF 3.5 and Chrome 3. I'd like to assume everything will be ok but just wanted to check if anyone else has had ...

Method Profiling Using Attributes

Is it possible to profile individual methods via attributes in .NET? I am currently trying to locate some of the bottle necks in a large legacy application that makes heavy use of static methods. Integrating a framework is simply not an option at the moment. Since most of the calls use static methods, interfaces and dependency injec...

Are There Reasons To Not Use CustomAttributes?

This is mostly a request for comments if there is a reason I should not go down this road. I have a multi-tierd, CodeSmith generated application. At the UI level there need to be some fields that are required, and the required fields will vary depending on field values in the bound entity. What I am thinking of doing is adding a "Proper...

Custom Attributes on ActionResult

This is probably a rookie question but; Let's say I have an ActionResult that I only want to grant access to after hours. Let's also say that I want to decorate my ActionResult with a custom attribute. So the code might look something like; [AllowAccess(after="17:00:00", before="08:00:00")] public ActionResult AfterHoursPage() { ...

Consuming Custom Attributes

Taking a look at the following question, http://stackoverflow.com/questions/1023186/real-world-use-of-custom-net-attributes how would you implement the solution proposed by @Esteban? I'm a little confused as to when and where the code would get executed I think. Could you please supply a good sample of code. I've asked this question b...

How to make a Attribute aware of the Name of the Proprty it is on?

I want to implement a simple attribute that is used to map Database Columns to Properties. So what i have so far is something that attached like so: [DataField("ID")] public int ID { get; set; } [DataField("Name")] public String Name { get; set; } [DataField("BirD8")] public DateTime BirthDay { get; set; } Is there a way that...

is there any property default value initializer attribute?

I need like this public class AA{ public AA(){} [Default("hi")] public string value1{get;set} [Default(12)] public int value2{get;set;} } Usage: AA a=new AA(); print(a.value1); //result: hi print(a.value2); //result: 12 Is it possible to create like this? I know another way Public class AA{ public AA(){value1=...

Execution Priority in custom Attributes in asp.net mvc

I have two custom attributes in my asp.net mvc(C#) application. [CustAttribute1()] [CustAttribute2()] When i use those attributes to my actions, which will get execute first? [CustAttribute1()] [CustAttribute2()] public ActionResult Index() { Can i use more than one custom attributes for my actions? If so, in the above Action, whic...

How do I call GetCustomAttributes from a Base Class?

Hi, I need to be able to retrieve the Custom Attributes of a class from a method in its base class. Right now I am doing it via a protected static method in the base class with the following implementation (the class can have multiple instances of the same attribute applied): //Defined in a 'Base' class protected static CustomAttribute...

Attribute.IsDefined doesn't see attributes applied with MetadataType class

If I apply attributes to a partial class via the MetadataType attribute, those attributes are not found via Attribute.IsDefined(). Anyone know why, or what I'm doing wrong? Below is a test project I created for this, but I'm really trying to apply custom attributes to a LINQ to SQL entity class - like this answer in this question. Tha...