custom-attributes

Adding name attribute to `User` in Devise

泪湿孤枕 提交于 2019-11-30 11:02:18
I'm trying to add a name attribute to the User model provided by Devise. I added a "name" column to my database, and changed the sign up view so that it asks for the user's name: <h2>Sign up</h2> <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> <p><%= f.label :name %><br /> <%= f.text_field :name %></p> <p><%= f.label :email %><br /> <%= f.email_field :email %></p> <p><%= f.label :password %><br /> <%= f.password_field :password %></p> <p><%= f.label :password_confirmation %><br /> <%= f.password_field :password

What AttributeTarget should I use for enum members?

一笑奈何 提交于 2019-11-30 10:44:29
I want to use my IsGPUBasedAttribute for enum members like this: public enum EffectType { [IsGPUBased(true)] PixelShader, [IsGPUBased(false)] Blur } but the compiler doesn't let me to use: [AttributeUsage (AttributeTargets.Enum, AllowMultiple = false)] What is the right AttributeTarget value to limit the usage to enum members? Far as I know, there isn't one specifically for enum constants. The closest you could get would probably be "Field", which limits the use to field members of a class or struct (which Enum constants are treated as for purposes of attributes). EDIT: bringing the

Passing custom parameter in custom attribute - ASP.NET MVC

你说的曾经没有我的故事 提交于 2019-11-30 09:56:26
My goal is to create a custom attribute like System.ComponentModel.DataAnnotations.Display wich allows me to pass a parameter. Ex.: In System.ComponentModel.DataAnnotations.Display I can pass a value to the parameter Name [Display(Name = "PropertyName")] public int Property { get; set; } I want to do the same but in controllers and actions like below [CustomDisplay(Name = "Controller name")] public class HomeController : Controller and then fill a ViewBag or ViewData item with its value. Can someone help me with this? Thanks. Haitham Shaddad This is very simple public class

Override property setter and getter

笑着哭i 提交于 2019-11-30 09:08:38
问题 Is there a way to override the setter and getter of an auto property with an attribute? like this: [CustomAttribute] public int Value { get; set; } ... public class CustomAttibute : Attribute { public override NotExistingPropertySetter(object value) { if (((int)value) < 10 ) { value = 10; } } } 回答1: No. An attribute is never "executed". You would need to build a construct looking for the attribute and doing something if it's found. AoP (aspect oriented programming) in .NET is only possible by

is it possible to set custom attribute by jQuery attr() function using JS variables

耗尽温柔 提交于 2019-11-30 08:41:05
I'm using jquery 1.5 and html4 standard. I'm trying to set custom attribute which i get by javascript variable, but it is not setting up.code sample: var attname="list1"; // this is changed on every call of the function where it is defined. var attvalue="b,c,d"; // this also changed. jQuery('#div1').attr({attname:attvalue}); but it treat attname as string itself rather variable. there are other option like using data(),prop() but they are supported in HTML5 and jquery 1.6 that is not possible for me at the moment.other problem is data can't be set on server side to be sync and used at client

ASP.NET MVC: Ignore custom attribute in a base controller class

≡放荡痞女 提交于 2019-11-30 07:39:49
问题 I have a number of Controllers in my project that all inherit from a controller I've named BaseController. I wrote a custom attribute that I applied to the entire BaseController class, so that each time an action runs in any of my controllers, that attribute will run first. The problem is that I have a couple of controller actions that I'd like to ignore that attribute, but I don't know how to do it. Can anyone help? I'm using MVC 1. Thanks. 回答1: I had a similar need for something like this

How to solve Android Libraries custom attributes and package name remapping during build?

情到浓时终转凉″ 提交于 2019-11-30 07:36:58
Over time our Android project has expanded a great deal, and these days we are creating multiple branded APKs from the same source tree. This has become challenging due to the package naming requirements of Android. We have all of our shared code in an Android Library project, which is included in the main application project. Plus we have Android library 'overlays' for branded resources that get applied for each brand. When we want to build a brand, we include a few extra properties for that brand that end up including the 'overlay' Android libraries before the main shared code Android

Custom Attributes on Class Members

最后都变了- 提交于 2019-11-30 07:14:26
I am using a Custom Attribute to define how a class's members are mapped to properties for posting as a form post (Payment Gateway). I have the custom attribute working just fine, and am able to get the attribute by "name", but would like to get the attribute by the member itself. For example: getFieldName("name"); vs getFieldName(obj.Name); The plan is to write a method to serialize the class with members into a postable string. Here's the test code I have at this point, where ret is a string and PropertyMapping is the custom attribute: foreach (MemberInfo i in (typeof(CustomClass)).GetMember

C# Attributes On Fields

十年热恋 提交于 2019-11-30 06:58:31
How do I set an attribute on a field anywhere in my assembly, then reflect on those field attributes in my entire assembly and get/set the field values that the attribute is attached too? aku 1) Create custom attribute targeted for fields 2) Add it to desired fields 3) Iterate through types defined in your assembly 4) For each type : 4a) iterate through it's fields 4b) if field has your custom attribute go to step 4c 4c) get or set values of field 来源: https://stackoverflow.com/questions/156304/c-sharp-attributes-on-fields

Magento - Show Custom Attributes in Grouped Product table

删除回忆录丶 提交于 2019-11-30 05:47:54
I need to find a way to show the value of a custom attribute in place of the "Product Name" shown in the image below. (source: magentocommerce.com ) I'm working with /app/design/frontend/default/defaultx/template/catalog/product/view/type/grouped.php The code below doesn't work(the custom attribute is yearmade): <?php if (count($_associatedProducts)): ?> <?php foreach ($_associatedProducts as $_item): ?> <tr> <td><?php echo $this->htmlEscape($_item->getYearmade()) ?></td> Any help would be appreciated. EDIT: So the answer turned out to be quite simple. You see what I failed to mention above