I'm relatively new at C# programming, I've been coding in it for almost a year now. Previously I have been using PowerShell, and am pretty good at that and it seems that C# is a next step. So, if this is a stupid question I apologize in advance. I've not been able to find anything on the internet about this, and it could be just bad search terms on my part.
first off, i'm working on a webapp and the app contains a dropdown box that contains a list of types. These types were pulled from the VMware.vim sdk documentation. There aren't very many, just 14, but it makes for a long function which I think could be shortened up.
here is the function as it stands now
public List<EntityViewBase> FindEntityViewBase(VimClient vimClient, string viType, ManagedObjectReference viMoRef = null, NameValueCollection viFilter = null, string[] viProperties = null) { List<EntityViewBase> lstResultCollection = new List<EntityViewBase>(); switch (viType) { case "ClusterComputeResource": { lstResultCollection = vimClient.FindEntityViews(typeof(ClusterComputeResource), viMoRef, viFilter, viProperties); break; } case "ComputeResource": { lstResultCollection = vimClient.FindEntityViews(typeof(ComputeResource),viMoRef,viFilter,viProperties); break; } case "Datacenter": { lstResultCollection = vimClient.FindEntityViews(typeof(Datacenter), viMoRef, viFilter, viProperties); break; } case "Datastore": { lstResultCollection = vimClient.FindEntityViews(typeof(Datastore), viMoRef, viFilter, viProperties); break; } } return lstResultCollection; }
I've shortened it up for just testing things out. This works just fine and does what i expected it should, but it's gross. What i would like to see is similar to the following:
public List<EntityViewBase> FindEntityViewBase(VimClient vimClient, string viType, ManagedObjectReference viMoRef = null, NameValueCollection viFilter = null, string[] viProperties = null) { List<EntityViewBase> lstResultCollection = vimClient.FindEntityViews(typeof(viType), viMoRef, viFilter, viProperties); return lstResultCollection; }
If what I want to do isn't possible, that's fine. The function returns a collection of EntityViewBase, and i would still need to figure out the underlying type that is returned. Any thoughts would be appreciated, thanks!
Jeffrey S. Patton Jeffrey S. Patton Systems Specialist, Enterprise Systems University of Kansas 1001 Sunnyside Ave. Lawrence, KS. 66045 (785) 864-0242 | http://patton-tech.com