Hi!
I would like to create general routine that works on a concrete type based on the BusinessListBase<T, C>. where I won’t know the type, ‘T’, 'C' until runtime.
How can I achieve this?
e.g. I want to create a BaseMaintForm that will be used for Maintaining all Lookup/Reference Tables.
1] This Form will have a bindingSource, and a dataGridView
2] From the Menu I would like to pass the concerete class e.g. ProjectList (BusinessListBase<T, C>) to the BaseMaintForm which will then set that to a private variable (field/property) in the constructor
public partial class BaseMaintForm : Form
{
private object _mainbo; // What type should this be?
public BaseMaintForm(object mainBO) // What type should this be?
{
this._mainbo = mainBO;
this.mainBindingSource.DataSource = this._mainbo.GetList();
this.mainDataGridView.DataSource = this.mainBindingSource;
this._mainbo.BeginEdit()
}
}
What I can't figure out is what type should I define _mainbo and mainBO as ?
Thanks
Sarosh
this._mainbo = mainBO;
this.mainBindingSource.DataSource = this._mainbo.GetList();
this.mainDataGridView.DataSource = this.mainBindingSource;
this._mainbo.BeginEdit()
Hi!
IEditableBusinessObject does not have .GetList() and .BeginEdit() Methods.
What interface can I use so that I have access to the following PEM's.
GetList()
BeginEdit()
ApplyEdit()
Save()
AddNew()
CanEditObject()
CanAddObject()
CanDeleteObject()
IsDirty
IsValid
Can I use the bindingSource or the dataGridView's PEMS instead of some of the above mentioned PEM's
Thanks
Sarosh
Hi!
>>You shouldn't call BeginEdit, CancelEdit or ApplyEdit directly
How else can I set the BO for n-level Undo before seeting it to the bindingSource's DataSource.
>>What is GetList()? You mean the method off the IBindingSource interface from a DataSet?
GetList() is the static constructor for the BO e.g.
/// <summary>
/// Returns a list of roles.
/// </summary>
public static RoleList GetList()
{
if (_list == null)
_list = DataPortal.Fetch<RoleList>
(new Criteria(typeof(RoleList)));
return _list;
}
Am I correct in saying that it will be very difficult to do what I am trying here?
Sarosh
Don't worry about n-level undo - the BindingSource will handle that for you.
GetList() - as you've defined - is a static method and can't be part of the interface (see Rocky's remarks about CanXXXObject).
Based on what I've seen in your posts, you should probably retrieve the list externally and then simply pass the object reference to the form via the constructor - probably typed as IEditableBusinessObject. You can also role your own interface as Rocky explained previously.
What you want to do *can* be done - you just have to understand the limitations of generics with regards to polymorphism. Coding to an interface will solve the majority of your issues. You'll have to find some other solution if you need to access static members of the object (possibly pass the values in as additional parameters on the constructor). For example...
public BaseMaintForm(IEditableBusinessObject obj, bool canAddObject, bool canEditObject, bool canDeleteObject)
{
//Do whatever
}
Hi!
Thank you all for your ideas.
I will try them out and will post my findings.
Sarosh
Copyright (c) Marimer LLC