English 中文(简体)
动态的特性
原标题:Adding and removing Data Annotation attributes dynamically

我对你来说,我只剩下一个 cur子。 也许只是一个设计问题......甚至可能像我不理解数据说明提供者那样简单。

Anyway here we go: I have a class which represents some model data. Let s say it represents a package/box/carton.

It actually represents all of these things so I use the class in several different views. Sometimes I want the attribute of the field Package_Description to be So that it shows up as Box Number : input box here.

现在,如果想把它说成是“卡顿语”,我唯一的选择是将其分类。 或者使用一个单独的类别来说明这一类别。 我的基调是,一些外地名称是用户可图谱的,因此我不可能有固定的定义!

(使用第三方图书馆的方式[Telerik MVC Grid]确实显示这些外地名称,因此不能改变它研究数据说明的事实......)

So I just need to know is there a way to add attributes dynamically? Create an anonymous type on the fly, sub class the original and then add attributes using reflection? Or what other options are open to me, do I need to somehow implement a different annotation provider?

问题回答

贡献是此类定义的一部分。 因此,你可以改变目前班级的属性。

You could create a new type during runtime (not an anonymous type), but I think that s not such a good idea. I m sure whatever component you re using, it allows you to specify the appearance explicitly.





相关问题
c# reflection with dynamic class

I need to execute a method "FindAll" in my page. This method returns a list of the object. This is my method that I execute "FindAll". FindAll requires an int and returns an List of these class. ...

Performance overhead of using attributes in .NET

1.. Is there any performance overhead caused by the usage of attributes? Think for a class like: public class MyClass { int Count {get;set;} } where it has 10 attibutes (...

WPF GridView, Display GetType().Name in DisplayMemberBinding

I want include the Type name of each object in my collection from my GridView. I have a collection which has four different types in it that all derive from a base class. Call them, Foo, Bar, Fizz, ...

Testing private method of an abstract class using Reflection

How can I test a private method of an abstract class using reflection (using C#)? I am specifically interested in adapting the code found in this thread. I am aware of the discussion around the ...

Adding Items to ListBox, RadioList, Combobox using reflection

I m trying to add items to a listbox,combobox, radiolist using reflection. The code I have at the moment is as follows: public static Control ConfigureControl(Control control, ControlConfig ctrlconf)...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

热门标签