Avatar of Jon Jaques
Jon Jaques
Flag for United States of America

asked on 

Need help simplifying C# code

Hello Experts,

I need help simplifying this bit of code:

Object doc = ActiveMdiChild;
string s = doc.GetType().ToString();
switch (s)
{
	case "KTStoreHouseCS.WebDocument":
		((WebDocument)doc).Activate();
		break;
	case "KTStoreHouseCS.WebIEDocument":
		((WebIEDocument)doc).Activate();
		break;
	case "KTStoreHouseCS.ToursForm":
		((ToursForm)doc).Activate();
		break;
	default:
		break;
}

Open in new window


I feel like I should be able to dispose of the switch statement, and just use something like this, but I don't know how to make it work:

Object doc = ActiveMdiChild;
string s = doc.GetType().ToString();
((s)doc).Activate();

Open in new window


Any ideas?

Thanks in advance!

--Jon
C#

Avatar of undefined
Last Comment
AndyAinscow

8/22/2022 - Mon