天道酬勤,学无止境

attributes

What's the use of attributes on an interface?

Using Resharper, I extracted an interface of an existing class. This class has some attributes set on a few members, and Resharper also put these on the interface members. Can I delete these attributes from the interface? Attributes on an interface aren't inherited when implementing an interface right?

2022-01-17 06:02:18    分类:问答    .net   attributes   interface

How to identify when an attribute's attribute is being set?

I have a mutable object (which we'll call mutable) that has multiple attributes. This object is itself an attribute in a class Foo. Foo is user-defined while mutable is not and thus cannot be changed. Whenever someone is trying to set the attributes in mutable, I'll need to make computations. The problem I'm facing is that using a property for mutable only works when mutable itself is set, and not its attributes. I've managed to solve the problem but with something that seems more of a hack than reasonable Python code. class Mutable(object): # Example class. def __init__(self): self.attr0 = 0

2022-01-17 04:00:12    分类:问答    python   properties   attributes

Adding Editor / EditorAttribute at Run-time (Dynamically) to an Object's Property

How to add the EditorAttribute (Editor) to an object's property at run-time? I have My.Settings.ExcludeFiles, which is created by the settings designer as Public Property ExcludedFiles() As Global.System.Collections.Specialized.StringCollection. When editing ExcludedFiles via a property grid, the "String Collection Editor" generates a "Constructor on type 'System.String' not found" run-time exception. I cannot change the attributes of the ExcludeFiles property because they will be overwritten the next time any setting changes are made. Therefore, I must attach/add the Editor/EditorAttribute at

2022-01-16 21:21:15    分类:问答    winforms   attributes   propertygrid   my.settings

为什么这是合法的? 引用类型中的常量,从属性 *on* 类型,不带类型名称前缀?(Why is this legal? Referring to a constant in a type, from an attribute *on* the type, without prefixing with type name?)

问题 看下面的 LINQPad 程序: void Main() { } [TestAttribute(Name)] public class Test { public const string Name = "Test"; } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] [Serializable] public class TestAttribute : Attribute { public TestAttribute(string dummy) { } } 这编译顺利。 为什么? 具体来说: [TestAttribute(Name)] public class Test { public const string Name = "Test"; 为什么我不必写这个: vvvvv [TestAttribute(Test.Name)] public class Test { public const string Name = "Test"; 属性声明是否被视为在类型“内部”,因此在范围内? 回答1 属性实例声明的范围确实是它所附加的类型,或者(在方法、参数等的情况下)包含它所附加的元素的类型。 尽管标准确实说: 可以在全局范围内指定属性(以指定包含程序集的属性

2022-01-16 18:58:59    分类:技术分享    c#   attributes   constants

Rails:虚拟属性和表单值(Rails: Virtual attributes and form values)

问题 我有一个带有虚拟属性的模型书,用于从 Book 表单创建一个编辑器。 代码如下所示: class Book < ActiveRecord::Base has_many :book_under_tags has_many :tags, :through => :book_under_tags has_one :editorial has_many :written_by has_many :authors, :through => :written_by def editorial_string self.editorial.name unless editorial.nil? "" end def editorial_string=(input) self.editorial = Editorial.find_or_create_by_name(input) end end 和新的形式: <% form_for(@book, :html => { :multipart => true }) do |f| %> <%= f.error_messages %> ... <p> <%= f.label :editorial_string , "Editorial: " %><br /> <%= f.text_field :editorial_string, :size => 30

2022-01-16 16:45:42    分类:技术分享    ruby-on-rails   activerecord   attributes   virtual

Why is this legal? Referring to a constant in a type, from an attribute *on* the type, without prefixing with type name?

Look at the following LINQPad program: void Main() { } [TestAttribute(Name)] public class Test { public const string Name = "Test"; } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] [Serializable] public class TestAttribute : Attribute { public TestAttribute(string dummy) { } } This compiles without a hitch. Why? Specifically: [TestAttribute(Name)] public class Test { public const string Name = "Test"; Why don't I have to write this: vvvvv [TestAttribute(Test.Name)] public class Test { public const string Name = "Test"; Is the attribute declaration deemed to

2022-01-16 16:07:30    分类:问答    c#   attributes   constants

Rails: Virtual attributes and form values

I have a Model Book with a virtual attribute for create a Editor from the Book form. The code looks like: class Book < ActiveRecord::Base has_many :book_under_tags has_many :tags, :through => :book_under_tags has_one :editorial has_many :written_by has_many :authors, :through => :written_by def editorial_string self.editorial.name unless editorial.nil? "" end def editorial_string=(input) self.editorial = Editorial.find_or_create_by_name(input) end end And the new form: <% form_for(@book, :html => { :multipart => true }) do |f| %> <%= f.error_messages %> ... <p> <%= f.label :editorial_string ,

2022-01-16 14:26:26    分类:问答    ruby-on-rails   activerecord   attributes   virtual

通过自定义属性生成附加代码(Generating additional code through a custom attribute)

问题 我对 C# 还是很陌生,我有一个关于属性的问题。 是否可以编写在编译时生成附加代码的自定义属性。 例如: [Forever] public void MyMethod() { // Code } 变成: public void MyMethod() { while (true) { // Code } } 回答1 开箱即用,不,这不是可以做到的。 不过,使用 PostSharp 可以实现: http://www.sharpcrafters.com/aop.net/compiletime-weaving 回答2 Afterthought 通过对程序集执行编译时修改与 PostSharp 类似。 在 Afterthought 的情况下,您可以选择如何识别要进行的更改,方法是查找已定义的属性、查找常见模式或简单地建立约定。 例如,我正在研究一个示例,该示例使用 Afterthought 在编译时为已编译程序集中 DbContext 公开的类型自动实现实体框架接口。 在这种情况下,我只是查找作为 DbContext 子类的任何类型,然后查看此类型的属性以确定要修改哪些 POCO 类型以与实体框架一起使用。 然而,像这样的程序集的编译时操作虽然功能强大,但对我来说仍然是最后的选择。 .NET 框架和 Microsoft 工具本身并不支持它。 虽然我编写 Afterthought

2022-01-16 10:12:44    分类:技术分享    c#   .net   attributes   custom-attributes

jQuery - 选择标签 - 获取所选元素的属性(jQuery - select tag - get attribute of the selected element)

问题 有没有办法从'select'标签的选定选项中获取属性 - 例如'rel' - 即? <select name="menu" id="menu"> <option value="1" rel="123">Option 1</option> <option value="2" rel="124">Option 2</option> </select> 任何的想法? 回答1 您可以只使用:selected过滤器。 这是一个小提琴:http://jsfiddle.net/jomanlk/ECAea/ $('#menu').change(function(){ alert($(this).find('option:selected').attr('rel')); }); 回答2 with jQuery $('#menu option:selected').attr('rel'); with javascript var sel = document.getElementById('menu'); var option = sel.options[sel.selectedIndex]; var rel = option.getAttribute('rel'); demo with both versions at http://jsfiddle.net/gaby/WLFmv/ 回答3

2022-01-16 08:54:40    分类:技术分享    jquery   select   attributes

在 woocommerce 产品页面中显示产品属性和分类(display product attribute and taxonomy in woocommerce product page)

问题 我想在产品页面的附加信息中显示品牌属性。 有没有办法创建一个短代码,因为我有一个特定的位置来显示它,甚至在 php.ini 中。 这适用于 woocommerce 3.6.5 先感谢您 回答1 您可以在活动主题的 functions.php 中添加以下代码片段来执行上述操作 - // to display product additional info in product page add_action( 'woocommerce_single_product_summary', 'show_additional_info_product_summary', 45 ); // To diplay additonal info via shortcode within product page add_shortcode( 'show_additional_info', 'show_additional_info_product_summary' ); function show_additional_info_product_summary() { global $product; // Assume that your attribute is pa_brand $brand_attributes = $product->get_attribute('brand');

2022-01-16 06:22:01    分类:技术分享    php   wordpress   woocommerce   attributes   taxonomy