|
-
Apr 15th, 2010, 12:58 PM
#1
Thread Starter
Addicted Member
[2010] What is wrong with the code?
Hi, Here I gave the code. My aim : I am trying to make the frmView to generic for populating from Manager Class List.
Code:
namespace WindowsFormsApplication1
{
public abstract class AbsLookUpView
{
public abstract string LookupName{get;}
}
}
--------------------------------------------------------------------------
namespace WindowsFormsApplication1
{
public abstract class AbsManager<T> where T:AbsLookUpView
{
public abstract List<T> LoadAll();
}
}
==========================================================
public partial class Department: AbsLookUpView
{
public override string LookupName
{
get
{
return "Department";
}
}
}
==========================================================
namespace WindowsFormsApplication1
{
public class DeptManager : AbsManager<Department>
{
private DataClasses1DataContext dc = new DataClasses1DataContext();
public override List<Department> LoadAll()
{
return dc.Departments.ToList<Department>();
}
}
}
==========================================================
namespace WindowsFormsApplication1
{
public partial class frmView : Form
{
public AbsManager<AbsLookUpView> ManagerCls;
public void BindGrid()
{
this.lkpDataGridView.DataSource = ManagerCls.LoadAll();
}
}
}
==========================================================
namespace WindowsFormsApplication1
{
public partial class frmTest : frmView
{
public frmTest()
{
InitializeComponent();
}
private void frmTest_Load(object sender, EventArgs e)
{
AbsManager<AbsLookUpView> dmb ;
DeptManager dm = new DeptManager();
dmb = dm; [Error in this line is given below]
this.ManagerCls = dmb;
this.BindGrid();
Form5 f = new Form5(this);
this.ChildForm = f;
}
}
}
==========================================================
Error: Cannot implicitly convert type 'WindowsFormsApplication1.DeptManager' to 'WindowsFormsApplication1.AbsManager<WindowsFormsApplication1.AbsLookUpView>' E:\test\WindowsFormsApplication1\WindowsFormsApplication1\frmTest.cs
here, DeptManager is inherited from AbsManager<WindowsFormsApplication1.AbsLookUpView>. Then why it throws error. Pls explain.
What is wrong with the above code. Why is this error is occuring? Pls explain experts.
God has been pleased to place as a king or cobbler do the work sincerely
-
Apr 15th, 2010, 01:34 PM
#2
Re: [2010] What is wrong with the code?
"DeptManager is inherited from AbsManager<WindowsFormsApplication1.AbsLookUpView>"
It is?
You have: public class DeptManager : AbsManager<Department>
If it inherited from AbsLookUpView wouldn't it look like this:
public class DeptManager : AbsManager<AbsLookUpView>
Or did I miss something?
-tg
Edit - never mind... I did miss something... ok... back to square 1.
-
Apr 15th, 2010, 07:35 PM
#3
Re: [2010] What is wrong with the code?
The fact that String inherits Object does not mean that List<String> inherits List<Object>. Likewise, the fact that Department inherits AbsLookUpView does not mean that AbsManager<Department> inherits AbsManager<AbsLookUpView>. Your DeptManager class inherits AbsManager<Department> so it can be cast as type AbsManager<Department>. It doesn't inherit AbsManager<AbsLookUpView> so it can't be cast as that type.
-
Apr 16th, 2010, 02:29 AM
#4
Thread Starter
Addicted Member
Re: [2010] What is wrong with the code?
Then, how can we change this code to achieve the aim. Any suggestion to achieve this
God has been pleased to place as a king or cobbler do the work sincerely
-
Apr 16th, 2010, 02:40 AM
#5
Re: [2010] What is wrong with the code?
 Originally Posted by senthilkumartd
Then, how can we change this code to achieve the aim. Any suggestion to achieve this 
You have to change your aim.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|