Hi All, I had a quick question. Something seems really wrong with this code. I want to take advantage of generics and delegates and quite possibly generic delegates if applicable. I am working with some code generated api's and the objects generated are very similiar. I see that they all implement an interface so I was to try to create one class with a few methods to handle the different scenarios. Here is some sample code. It just feels wrong on so many levels. Please tell me how I can make this code better. A little refactoring advice if you will. And by all means rip it to shreds. I want to code better and learn to do things correctly.
Thanks, ~ck in San Diego
private delegate IsomeEntity DisplayDelegate(IsomeEntity display);
public IsomeEntity Display<T>()
{
DisplayDelegate _del = null;
IsomeEntity display = factory.CreateObject(typeof(T).Name);
if (display.GetType() == typeof(ADisplayEntity))
_del = ADisplayEntity;
if (display.GetType() == typeof(BDisplayEntity))
_del = BDisplayEntity;
if (display.GetType() == typeof(CDisplayEntity))
_del = CDisplayEntity;
return _del(display);
}
public ADisplayEntity ADisplayEntity(IsomeEntity display)
{
ADisplayEntity ade = display as ADisplayEntity;
try
{
ADisplay o = new ADisplay();
ADisplayEntity response = o.ADisplay(ade);
return response;
}
catch (Exception ex)
{
Exception newEx;
if (someExceptionHandler.HandleException(ex, this, out newEx))
throw newEx;
}
return null;
}
public BDisplayEntity BDisplayEntity(IsomeEntity display)
{
BDisplayEntity dde = display as BDisplayEntity;
try
{
BDisplay o = new BDisplay();
BDisplayEntity response = o.BDisplay(bde);
return response;
}
catch (Exception ex)
{
Exception newEx;
if (someExceptionHandler.HandleException(ex, this, out newEx))
throw newEx;
}
return null;
}