Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need multi inheritance or workaround 1

Status
Not open for further replies.

yeller2

Programmer
Feb 8, 2007
69
US
Hi,

I need to derive from UserControl and CriticalFinalizerObject classes. Is there any way I can work around this?

Thanks
 
Try creating a usercontrol first that extends CriticalFinalizerObject.

IF you need a class on top of the usercontrol (I don't see why you don't just create a usercontrol) but if you have to then create a class that extends YourUserControl which extends CriticalFinalizerObject.

Messy...

 
The work around would be Creating a class that contains an instance of both of these objects. Then if you really want a "hybrid" of the two, just expose properties to the underlying classes.

You could also create a user control that contains the CriticalFinalizerObject and only have one member instead of two.
 
could you not have a UserControl which contains a CriticalFinalizerObject member variable, then overload the cast to return the reference:

Code:
public class MyUserControl : UserControl
{
 private CriticalFinalizerObject myCriticalFinalizerObject = new CriticalFinalizerObject();

 public static explicit operator CriticalFinalizerObject(MyUserControl control)
 {
  return control.myCriticalFinalizerObject;
 }
}

public static class MyApp
{
 [STAThread]
 public static void Main()
 {
  MyUserControl c = new MyUserControl();
  ((CriticalFinalizerObject)c).CFOMethod();
 }
}

i feel sure there are really good reasons why you shouldn't use code like this. i'd rather like some feedback.

any ideas?



mr s. <;)

 
CriticalFinalizerObject is an abstract class. So you can't instantiate it.

 
but you can derive your own implementation of it.

that's much easier than not deriving from UserControl: you'd lose too much.



mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top