Why reinvent the wheel? Take a look at your own code:
You are using the Dictionary method TryGetValue . How does he deal with the same problem?
I suggest you follow in the footsteps of the .Net Framework developers and do the same:
public bool TryParseDictionaryItem<T>(string s, Dictionary<string, T> dictionary, out T result) { if (dictionary.TryGetValue(s, out result)) { return true; } return false;
}
Update
Since you don't like this approach, how about including it?
public T TryParseDictionaryItem<T>(string s, Dictionary<string, T> dictionary, out bool Success) { T result = default(T); Success = (dictionary.TryGetValue(s, out result)) return result; }
source share