pondělí 4. dubna 2011

cannot derive from sealed type 'System.ComponentModel.EditorAttribute'

Yep, lovely. Yet another sealed class. Why?!?

OK, so I wrote a Visual Studio plugin that extends the Entity Framework designer. Everything's working fine. Well ... mostly ... the fact that if and only if there is a plugin, any validation problems in the updated .edmx are fatal and attributed to the plugin without the user having any chance to fix the problems ... in 99.784% of cases caused by the original code ... yeah, that's pretty annoying ... the only solution is to write a copy of the .edmx into a different file just before the EF Designer starts the validation and then replace the .edmx by this copy and fix the huge "Hey, I don't know what's the primary key for this view" problem.

Anyway ... most of the attributes I need to add to the properties that I want to display in the EF Designer are kinda OK. [DisplayName("...")], ["Description("...")], [Category("..")], [DefaultValue(...)]. All that's OK.

If I want a dropdown I just define an enum and it works automatically. (And if I want a dropdown with a dynamic list of options it ... well ... I haven't found a way to do that).

Then if I want a multiline input for the property, I know how to do it, it's just an attribute. An attribute that looks like this:

[EditorAttribute(typeof(System.ComponentModel.Design.MultilineStringEditor), 
 typeof(System.Drawing.Design.UITypeEditor))]

Lovely, isn't it?

OK, so I thought I could define subclass (named for example MultiLineAttribute) that'd use the inherited constructor with those values:


public class MultiLineAttribute : System.ComponentModel.EditorAttribute {
  public MultiLineAttribute()
   : base(typeof(System.ComponentModel.Design.MultilineStringEditor),
    typeof(System.Drawing.Design.UITypeEditor)) { }
 }
Nope. Cannot derive from sealed type.

Why?!? Why the heck does the silly class have to be seaeaeaeaealed?

Žádné komentáře:

Okomentovat