Created
August 16, 2013 00:54
-
-
Save rje/6246335 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<MyBaseClass> m_listOfObjects; // initialized somewhere else | |
public T FindFirstObjectOfType<T>() where T: MyBaseClass | |
{ | |
foreach(var toCheck in m_listOfObjects) | |
{ | |
if(toCheck.getType() == typeof(T)) | |
{ | |
return toCheck as T; | |
} | |
} | |
} | |
public List<T> FindAllObjectsOfType<T>() where T: MyBaseClass | |
{ | |
var toReturn = new List<T>(); | |
foreach(var toCheck in m_listOfObjects) | |
{ | |
if(toCheck.getType() == typeof(T)) | |
{ | |
toReturn.Add(toCheck as T); | |
} | |
} | |
return toReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment