I got a Type whose FullName is :
"System.Collections.ObjectModel.ObservableCollection`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
The thing is that I’d like to test if my Type is an ObservableCollection of string (in the current case, it is). So here is my code :
if (propertyType.GetType() == typeof(ObservableCollection<string>))
but it seems to fail and I don’t understand why :/
I had this code thats works :
if (propertyType.Namespace == "System.Collections.ObjectModel" && propertyType.Name == "ObservableCollection`1")
{
//We are dealing with an ObservableCollection
var args = propertyType.GetGenericArguments();
if (args.Count() != 0 && args[0] == typeof(string))
{
//MyCode for ObservableCollection<string>
}
}
but I don’t feel like it’s optimal and considering that I’ll have to handle other collections (IEnumerable, List, etcetc…) of other Types (int, bool, etcetc…) this doesnt fit well 🙁
At a guess, remove the extra
.GetType():since
propertyType.GetType()is probably some derivative ofSystem.Type(such asSystem.RuntimeType).