using CommonLang.Property; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace CommonFroms.G2D { public class G2DCreateInstanceDialog : G2DListSelectEditor { private G2DCreateInstanceDialog(List list, ClassDefine selected) : base(list, selected) { } public static object ShowCreateInstanceDialog(Type type, IWin32Window owner=null) { if (type.IsAbstract || type.IsInterface) { List types = ReflectionUtil.GetNoneVirtualSubTypes(type); List defines = new List(); foreach (Type subType in types) { defines.Add(new ClassDefine(subType)); } G2DCreateInstanceDialog dialog = new G2DCreateInstanceDialog(defines, null); if (dialog.ShowDialog(owner) == DialogResult.OK) { ClassDefine define = dialog.SelectedObject; return ReflectionUtil.CreateInstance(define.ValueType); } return null; } else { return ReflectionUtil.CreateInstance(type); } } public class ClassDefine { public Type ValueType { get; private set; } public DescAttribute Desc { get; private set; } public ClassDefine(Type subType) { ValueType = subType; Desc = PropertyUtil.GetAttribute(subType); } public override string ToString() { if (Desc != null) { return Desc.Desc; } else { return ValueType.Name; } } } } }