如何将参数传递给继承UITypeEditor的类 [英] how do I pass an argument to a class that inherits UITypeEditor

查看:40
本文介绍了如何将参数传递给继承UITypeEditor的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为属性创建了一个编辑器.但是,我想将一些参数传递给编辑器的构造函数,但是我不确定如何执行此操作.

I have created an editor for a property. I would however like to pass some arguments to the constructor of the editor, but I am unsure as to how to do this.

FOO _foo = new foo();
[Editor(typeof(MyEditor), typeof(UITypeEditor))]
public object foo 
 {
 get { return _foo; }
 set {_foo = value;}
 }

class MyEditor: UITypeEditor
{
  public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
  {
    //some other code
    return obj;
  }
}

推荐答案

当然,您可以在myEditor类中添加另一个(已参数化的)构造函数,如下所示:

of course you can add another (parametrized) constructor to your myEditor class, something like this:

public class MyEditor: UITypeEditor
{
  // new parametrized constructor
  public MyEditor(string parameterOne, int parameterTwo...)
  {
    // here your code
  }

  ...
  ...
}

问题在于,您还应该控制谁调用该构造函数,因为只有这样,您才能决定要使用哪个构造函数,并且可以为参数指定/分配值.

the problem is that you should also be in control of who calls that constructor because only then you can decide which constructor to use and you can specify/assign a value to the parameters.

这篇关于如何将参数传递给继承UITypeEditor的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆