/// <summary> /// Method to return an item sent in as a ModelViewModelType as a ModelType /// </summary> /// <typeparam name="ModelType">The type to be returned</typeparam> /// <typeparam name="ModelViewModelType">The type to get the value from</typeparam> /// <param name="Instance">The current instance needed to get the right item</param> /// <returns>The sent in item as the desired model type</returns> public ModelType GetSelectedItemAsModelType <ModelType, ModelViewModelType>(ModelViewModelType Instance) { // casting the database result to a queryable list var ModelTypeList = DatabaseList.Cast <ModelType>().ToList(); // casting the view model version to a queryable list var ModelViewModelList = CurrentList.Cast <ModelViewModelType>().ToList(); // getting the index of the chosen item int index = ModelViewModelList.IndexOf(Instance); // return the same item but as a Model Type return(ModelTypeList[index]); }