custom-attributes

An attribute argument must be a constant expression, …- Create an attribute of type array

半世苍凉 提交于 2019-11-26 04:51:15
问题 Here is my custom attribute and a class I\'m using it on: [MethodAttribute(new []{new MethodAttributeMembers(), new MethodAttributeMembers()})] public class JN_Country { } public class MethodAttribute : Attribute { public MethodAttributeMembers[] MethodAttributeMembers { get; set; } public MethodAttribute(MethodAttributeMembers[] methodAttributeMemberses) { MethodAttributeMembers = methodAttributeMemberses; } } public class MethodAttributeMembers { public string MethodName { get; set; }

Can I add custom methods/attributes to built-in Python types?

丶灬走出姿态 提交于 2019-11-26 04:28:00
For example—say I want to add a helloWorld() method to Python's dict type. Can I do this? JavaScript has a prototype object that behaves this way. Maybe it's bad design and I should subclass the dict object, but then it only works on the subclasses and I want it to work on any and all future dictionaries. Here's how it would go down in JavaScript: String.prototype.hello = function() { alert("Hello, " + this + "!"); } "Jed".hello() //alerts "Hello, Jed!" Here's a useful link with more examples— http://www.javascriptkit.com/javatutors/proto3.shtml You can't directly add the method to the

Exclude property from serialization via custom attribute (json.net)

大憨熊 提交于 2019-11-26 04:21:19
问题 I need to be able to control how/whether certain properties on a class are serialized. The simplest case is [ScriptIgnore] . However, I only want these attributes to be honored for this one specific serialization situation I am working on - if other modules downstream in the application also want to serialize these objects, none of these attributes should get in the way. So my thought is to use a custom attribute MyAttribute on the properties, and initialize the specific instance of

Get enum from enum attribute

南楼画角 提交于 2019-11-26 03:41:43
问题 I\'ve got public enum Als { [StringValue(\"Beantwoord\")] Beantwoord = 0, [StringValue(\"Niet beantwoord\")] NietBeantwoord = 1, [StringValue(\"Geselecteerd\")] Geselecteerd = 2, [StringValue(\"Niet geselecteerd\")] NietGeselecteerd = 3, } with public class StringValueAttribute : Attribute { private string _value; public StringValueAttribute(string value) { _value = value; } public string Value { get { return _value; } } } And I would like to put the value from the item I selected of a

How do I read an attribute on a class at runtime?

浪子不回头ぞ 提交于 2019-11-26 03:26:52
问题 I am trying to create a generic method that will read an attribute on a class and return that value at runtime. How do would I do this? Note: DomainName attribute is of class DomainNameAttribute. [DomainName(\"MyTable\")] Public class MyClass : DomainBase {} What I am trying to generate: //This should return \"MyTable\" String DomainNameValue = GetDomainName<MyClass>(); 回答1: public string GetDomainName<T>() { var dnAttribute = typeof(T).GetCustomAttributes( typeof(DomainNameAttribute), true )

Custom HTML tag attributes are not rendered by JSF

∥☆過路亽.° 提交于 2019-11-26 00:55:37
问题 I want to add some iOS specific tag attributes to my login-form. If I have a look on my web page source, the attributes autocorrect, autocapitalize and spellcheck aren\'t there. What is the reason for this? I am using JSF 2.x. <h:inputText id=\"user-name\" forceId=\"true\" value=\"#{login.username}\" style=\"width:120px;\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" /> 回答1: This is by design. You can only specify attributes which are supported by the JSF component itself

Can I add custom methods/attributes to built-in Python types?

折月煮酒 提交于 2019-11-26 00:55:13
问题 For example—say I want to add a helloWorld() method to Python\'s dict type. Can I do this? JavaScript has a prototype object that behaves this way. Maybe it\'s bad design and I should subclass the dict object, but then it only works on the subclasses and I want it to work on any and all future dictionaries. Here\'s how it would go down in JavaScript: String.prototype.hello = function() { alert(\"Hello, \" + this + \"!\"); } \"Jed\".hello() //alerts \"Hello, Jed!\" Here\'s a useful link with

ASP.NET MVC 4 Custom Authorize Attribute with Permission Codes (without roles)

杀马特。学长 韩版系。学妹 提交于 2019-11-26 00:50:02
问题 I need to control the access to views based on users privilege levels (there are no roles, only privilege levels for CRUD operation levels assigned to users) in my MVC 4 application. As an example; below the AuthorizeUser will be my custom attribute and I need to use it like this: [AuthorizeUser(AccessLevels=\"Read Invoice, Update Invoice\")] public ActionResult UpdateInvoice(int invoiceId) { // some code... return View(); } [AuthorizeUser(AccessLevels=\"Create Invoice\")] public ActionResult

Custom HTML tag attributes are not rendered by JSF

六眼飞鱼酱① 提交于 2019-11-25 19:43:52
I want to add some iOS specific tag attributes to my login-form. If I have a look on my web page source, the attributes autocorrect, autocapitalize and spellcheck aren't there. What is the reason for this? I am using JSF 2.x. <h:inputText id="user-name" forceId="true" value="#{login.username}" style="width:120px;" autocorrect="off" autocapitalize="off" spellcheck="false" /> BalusC This is by design. You can only specify attributes which are supported by the JSF component itself (i.e. it's listed in the attribute list in the tag documentation ). You can't specify arbitrary additional attributes