attributes

C# wrap method via attributes

Hello! I'm new to C# and wondering if it's possible to wrap a method only by adding an attribute. Example: I want to log the execution time a method takes. [LogTimings] public void work() { .. } This is kind of wrapping a method into another one(see this python implementation) ...

jQuery: how to include attributes on click during .ready() ?

I'm trying to convert all my old javascripts to jquery but I'm a bit confused how can I convert my click event with attr. The old javascript looks something like: function MyFunction(string1, string2){ doSomething(string1); doSomethingElse(string2); } And then I call it with <a href="javascript:MyFunction('string 1','string 2...

Can you get merged attributes for a class in C#?

Say I have the following set of classes, is it possible for the attributes of DerivedClass to be merged? Currently if I use the GetType().GetCustomAttributes()method passing in true for inheritance it takes the highest attributes in the inheritance structure. i.e. [Another("Bob")] and [My(16)] Is it possible for the attributes to be me...

Html Attribute for Html.Dropdown

I am using a dropdown list as follows. <%=Html.DropDownList("ddl", ViewData["Available"] as SelectList, new { CssClass = "input-config", onchange = "this.form.submit();" })%> On its selection change I am invoking post action. After the post the same page is shown on which this drop down is present. I want to know about the HTML a...

Magento: Loading attributes per store

I have a custom module that exports data to our fulfillment system when the user checks out. Before export I need to run the address through a verification service. Since we are charged for this service, I need to configure the user name and password for the service per store. I have added the attributes I need, however I cannot figur...

Iterating over element attributes with jQuery

I know individual attributes can be retrieved with the attr() method, but I'm trying to iterate over all of the attributes for an element. For context, I'm using jQuery on some XML... <items> <item id="id123" name="Fizz" value="Buzz" type="xyz"> <subitem name="foo"> <subitem name="bar"> </item> <item id="id456" name="Bizz...

how to find specific xml data by attribute name/value in flex / actionscript

From some xml I want to find items that have a specific attribute and value. Here is example xml: <node> <node> <node> <special NAME="thisone"></special> </node> <node> <special>dont want this one</special> </node> </node> </node> (nodes can contain nodes...) I need to find the first based on it has an attribute nam...

stripping all attributes from an html tag using regex

Hi, I've been trying to formulate a regular expression to remove any attributes that may be present in html tags but I'm having trouble doing this and Google doesn't seem to provide any answers either. Basically my input string looks something like <p style="font-family:Arial;" class="x" onclick="doWhatever();">this text</p> <img st...

How do I sort a generic list based on a custom attribute?

I am working in c#.NEt 2.0. I have a class, let's say X with many properties. Each properties has a custom attribute, an interger, which I planned to use to specify its order int he final array. Using reflection I read through all of the properties and group the values and place them into a generic list of properties. This works and I c...

Custom attribute only on specific classes

Hi, I would like to define a constrait on my custom (PostSharp) attribute. My goal is to get error or warning while compile time, if class X dont implements Y interface but it has my attribute. So this should work: [MyAttributeOnlyForY] public class X : Y { ... } but this should break the compile process: [MyAttributeOnlyForY] publ...

ASP.Net MVC 2.0: EditorFor setting name via attributes

Hey guys Just wondering how do I mimic the following using attributes... <%= Html.EditorFor(x => x.SportProgramIdList, "FormMultiSelectDropDownList", "SportProgramIds")%> I know I can specify the template by using [UIHint("FormMultiSelectDropDownList")] but I am left with the problem with how to set the name... Cheers Anthony ...

How to get attributes on a referenced field

Hi, I have a question: Is there an elegant way of getting Attributes on a referenced field. Ie.: public class C1: Base { [MyAttribute] public string Field1; } public class Base { private void Do(ref string field) { if (field has attributes) DoSomething(); } } How can I get attributes of a f...

How to determine if a class is decorated with a specific attribute

I'm trying to determine if a interface is decorated with a specific attribute. For example, I have the following interface: <MyCustomAttribute()> _ Public Interface IMyInterface Function Function1 Sub DeleteWorkflowInstanceMap(ByVal instanceId As Guid) Sub InsertWorkflowInstanceMap(ByVal instanceId As Guid, ByVal aliasName ...

What are [] in C#?

For example: [TestFixtureSetUp] public void Init() { GetTestRepo(false); } [TestFixtureSetUp] in this example, what does it do? From my experience, [] usually refers to lists. ...

jQuery check if element contains any attribute

Hi, I can check if an element have a specific attribute with: if ($('#A').attr('myattr') !== undefined) { // attribute exists } else { // attribute does not exist } How can I check if an element have any attribute? Thank you ...

Is there an Attribute that hides a property from being bound to a gridview in asp.net?

I have an object that I set as the datasource for a gridview - this works fine, I get a nice table on the page with a column for each public property. But - I always want to hide one of the columns (but still need it available as a public property. I'm using a clunky hide-column-on-row-created fix for now, but am looking for a better s...

Type casting for Core Data attribute setting

I am trying to set a Core Data attribute but am getting incompatible type errors. I have a float attribute in a Core Data entity on iPhone 3.0. Core Data auto-generates an interface for a managed data object that provides property access to it: @property (nonatomic, retain) NSNumber * volume; and an implementation for it: @dynamic vo...

Does the order of attributes have any guarantees?

If multiple attributes are applied to a member, e.g. [Foo] [Bar] void Baz() { ... } Then are any guarantees made by the CLR/.NET specifications as to what order they will be retrieved in when retrieved by reflection (e.g. Attribute.GetCustomAttributes)? The documentation for these methods does not make it explicit, and while it does s...

Ruby: How to DRY up similar model attribute calls

I have a User model with a number of very similar properties that I want to list without typing each on in individually. So, rather than: "eye color: #{@user.his_eye_color}" "hair color: #{@user.his_hair_color}" "height: #{@user.his_height}" "weight: #{@user.his_weight}" ... "eye color: #{@user.her_eye_color}" "hair color: #{@user.her...

FlagsAttribute what for?

What is the difference between the code bellow ' no Flags' Public Enum MyEnum Monday = 1 Tuesday = 2 Wednesday = 4 Thursday = 8 End Enum and <Flags()> _ Public Enum MyEnum Monday = 1 Tuesday = 2 Wednesday = 4 Thursday = 8 End Enum I do the Dim days As MyEnum = MyEnum.Monday Or MyEnum.Tuesday Or MyEnum.Wednesday ...