The object Row
is a class, that has a property Values
which is a Dictionary.
Below are extension methods on the Values property.
public static T TryGetValue<T>(this Row row, string key)
{
return TryGetValue(row, key, default(T));
}
public static T TryGetValue<T>(this Row row, string key, T defaultValue)
{
object objValue;
if (row.Values.TryGetValue(key, out objValue))
{
return (T)objValue;
}
return defaultValue;
}
If I do:
user.Username = user.Values.TryGetValue<string>("Username");
This happends if the key "username" is not in the Dictionary.
I get an exception, invalid cast:
The following error ocurred:
System.InvalidCastException: Specified cast is not valid.
TryGetValue[T](Row row, String key, T defaultValue)
TryGetValue[T](Row row, String key)
So I guess TryGetValue
doesn't work on strings?