custom-attributes

Logging Error Code Design, Input needed

So, I'm stuck on a little problem. I was curious if anyone had some extra input they might be willing to give on this design. I have an ILog interface which has two methods exposed for the Error Code logging part of the design. FlagError and GetErrorCode; FlagError sets a bit on an integer, each bit representing that a certain error was...

How can I get tidy to allow my custom attributes?

function myTidy($content) { $tidyConfig = array( 'indent' => false, //don't indent 'doctype' => 'omit', //don't include doctype 'wrap' => 0, // don't line wrap 'show-body-only' => true, //don't include <html><head><tit...

When is the desctructor called for a custom attribute class?

Say I have this class: [AttributeUsage(AttributeTargets.Method)] public class MyAttribute : Attribute { public MyAttribute() { // Do stuff } ~MyAttribute() { // When is this called? When the function ends? Whenever the GC feels like? } } ...

Using custom C# attributes to select Fluent conventions

Suppose you have sets of Fluent conventions that apply to specific groups of mappings, but not to all of them. My thought here was, I'll create custom C# attributes that I can apply to the Fluent *Map classes - and write conventions that determine acceptance by inspecting the *Map class to see if the custom attribute was applied. That ...

How do I add a custom attribute to a templated ascx file?

I would like to decorate my ascx with an attribute so that when I search for types that have that attribute it will appear. The issue is that it seems like I can only add it to the base class which means that when I do a LoadControl on the type I don't get the ascx file, I get base class. I'm trying to avoid having controls require being...

C# Custom attribute on property - Getting type and value of attributed property.

I have the following attribute custom attribute, which can be applied on properties: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] public class IdentifierAttribute : Attribute { } For example: public class MyClass { [Identifier()] public string Name { get; set; } p...

Attribute Inheritence and Reflection

Hello All, I have created a custom Attribute to decorate a number of classes that I want to query for at runtime: [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] public class ExampleAttribute : Attribute { public ExampleAttribute(string name) { this.Name = name; } public string N...

How to retrieve the value of a Custom Attribute from a DLL Loaded at runtime?

I have a app that requires a dll to be loaded at runtime and I want to create some Custom Attributes in the dynamically loaded DLL so when it is loaded I can check to make sure that certain attributes have certain values before trying to use it. I create an attribute like this using System; [AttributeUsage(AttributeTargets.Class)] publ...

How to store an id in a model class

This should be an easy one. I'm not sure exactly how to title the question though. I have a collection of modules that can be added to my CMS (page, link, form...) they're all associated via a polymorphic association to one table that manages common things like ancestry and whether they're enabled etc... Because I'm making a 'page' for e...

What's the simplest most elegant way to utilize a custom attribute

So a little confession, I've never written an attribute class. I understand they serve the purpose of decorating classes with flags or extra functionality possibly. Can someone give me a quick example of not just creating and applying an attribute to a class, but rather utilizing the attribute from another block of code. The only code s...

Get Method Details using reflection and decorated attribute

Hey There I have a custom attribute : public class MenuItemAttribute : Attribute { } and i have a class with a few methods: public class HelloWorld { [MenuItemAttribute] public void Shout() { } [MenuItemAttribute] public void Cry() { } public void RunLikeHell() { } } Using reflection, ...

Using custom attributes in DOM elements, with boolean value

Is there a way to add attributes to a DOM element with boolean value like this: <body test='false'></body> I need to set this without using javascript. Thanks ...

Choosing the right exception type when custom attribute is missing

I have some trouble for choosing the right type of exception to throw when an expected custom attribute is not found (I would prefer one of the existing .NET exceptions). What do you recommend in this case? Thanks in advance. Edit: Here his the context: [<ExpectedAttribute()>] let foo args ... = ... The function foo (which is user-...

How to find all occurrences of a custom attribute in assemblies?

Hi, How can I find every occurrence of a custom attribute inside an assembly? If can find all types from an assembly where the attribute is used but thats not enough. How about methods, properties, enum, enum values, fields etc. Is there any shortcut for doing this or is the only way to do it to write code to search all parts of a typ...

Accessing properties attribute inside the get accessor

Am creating a custom attribute for my properties and was wondering if anyone know how i could access the the value of the Attribute inside of the get accessor. public class MyClass { [Guid("{2017ECDA-2B1B-45A9-A321-49EA70943F6D}")] public string MyProperty { get { return "value loaded from guid"; } } } ...

C# DataAnnotations and resource files - why no simple constructor?

I'm using DataAnnotions in a ASP.NET MVC application for validate my input models. If I want to use resource files for the error messages, then I have to specify these with named parameters, like so: [Required( ErrorMessageResourceType = typeof(Validation), ErrorMessageResourceName = "NameRequired")] Since I use this in a bunc...

Word 2007 - adding custom information invisible to the user in word elements

Hi, I would like to store some custom data on Word elements. In PowerPoint, every shape has a 'Tags' property, which is visible to programmers only, and anything can be stored in it. It's described here: http://blogs.msdn.com/b/andrew_may/archive/2004/12/07/277696.aspx Is there a convenient way to do it in Word? Regards. ...

ASP.NET: How can you add a custom/namespaced XHTML attribute to a web control declaratively?

Normally, unknown attributes of a webcontrol are passed through to to the rendered element in the browser. So the following works. <asp:label runat="server" Text="Label Text" helpId="101" /> However, if you use a namespaced attribute like the following <asp:label runat="server" Text="Label Text" myNs:helpId="101" /></div> The att...

C# Custom Attributes accessing database

Hi all, I have a custom attribute that accesses the database with nhiberate. The attribute actually inherits from Castle's AbstractValidationAttribute and is used to validate properties against regular expressions. Problem is, these regular expressions are cms managed and stored in the database, and when you change the values in the d...

Get list of custom attributes for current action/controller in ASP.NET MVC 1

Checking out the sample code from http://lukesampson.com/post/471548689/entering-and-exiting-https-with-asp-net-mvc written for ASP.NET MVC2, I noticed they can check if a custom attribute is applied to the current action or controller by accessing filterContext.ActionDescriptor and filterContext.ActionDescriptor.ControllerDescriptor res...