我有一个.dll文件,我已经实现了自定义控件和类型编辑器。
UITypeEditor在.dll文件中工作。但是当我将.dll导入主项目时,它会给我一个对象引用错误。
我的自定义表单和类型编辑器如下:
形式:
public partial class MyBrowseForm<TParentEntity> : Base4Form, IBaseBrowseDialog where TParentEntity : class
{
[Category("Base4Data")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(BdFormTypeEditor), typeof(UITypeEditor))]
[TypeConverter(typeof(CollectionConverter))]
public BindingList<MySearchFields> MySearchFieldsCollection
{
get => _mySearchFieldsCollection;
set => _mySearchFieldsCollection = value;
}
[Browsable(false)]
public Type MyGenericType => typeof(TParentEntity);
}
UITypeEdior
internal class BdFormTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
var svc = provider?.GetService(typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
if (context != null)
{
var genericType = ((dynamic) context.Instance).MyGenericType;
var editorFormType = typeof(MyEditorForm<>);
var editorFormInstance = editorFormType?.MakeGenericType(genericType);
if (svc != null)
{
using (var f = (Form) Activator.CreateInstance(editorFormInstance, null))
{
f.GetType().GetProperty("List")?.SetValue(f, value);
if (svc.ShowDialog(f) == DialogResult.OK)
return ((dynamic) f).List;
}
}
else
{
using (var f = (Form) Activator.CreateInstance(editorFormInstance, null))
{
f.GetType().GetProperty("List")?.SetValue(f, value);
if (svc.ShowDialog(f) == DialogResult.OK)
return ((dynamic) f).List;
}
}
}
return base.EditValue(context, provider, value);
}
}
我创建了另一个UITypeEditor和一个从Typeeditor打开的Form。 (使用上述声明) 这次我只添加了以下代码,并且我没有将值传递给表单中的任何属性。我得到了同样的错误。
var genericType = (Type)context?.Instance.GetPropValue("MyGenericType");
//var genericArgument = (Type)myGenericTypeProperty.GetValue(context.Instance);
var editorFormType = typeof(MyEditorForm<>);
//var genericArguments = new[] { genericArgument };
var editorFormInstance = editorFormType.MakeGenericType(genericType);
if (svc != null)
{
using (var f = Form)Activator.CreateInstance(editorFormInstance))
所以这在原始解决方案中有效但是当我构建并将dll导入另一个解决方案时,我得到一个对象引用..
您认为我在这里失踪了什么?任何帮助表示赞赏。