public static bool IsDictionaryOrListInterface(RuntimeTypeModel model, Type type, out Type defaultType)
{
defaultType = null;
if (!Helpers.IsInterface(type))
{
return(false);
}
Type[] genArgs;
var itemType = TypeModel.GetListItemType(model, type);
#if WINRT
TypeInfo typeInfo = type.GetTypeInfo();
if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IDictionary <,>) &&
itemType == typeof(System.Collections.Generic.KeyValuePair <,>).MakeGenericType(genArgs = typeInfo.GenericTypeArguments))
#else
if (type.IsGenericType && type.GetGenericTypeDefinition() == model.MapType(typeof(System.Collections.Generic.IDictionary <,>)) &&
itemType == model.MapType(typeof(System.Collections.Generic.KeyValuePair <,>)).MakeGenericType(genArgs = type.GetGenericArguments()))
#endif
{
defaultType = model.MapType(typeof(System.Collections.Generic.Dictionary <,>)).MakeGenericType(genArgs);
return(true);
}
#if WINRT
if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(System.Collections.Generic.IList <>).MakeGenericType(genArgs = typeInfo.GenericTypeArguments))
#else
if (type.IsGenericType && type.GetGenericTypeDefinition() == model.MapType(typeof(System.Collections.Generic.IList <>)).MakeGenericType(genArgs = type.GetGenericArguments()))
#endif
{
defaultType = model.MapType(typeof(System.Collections.Generic.List <>)).MakeGenericType(genArgs);
return(true);
}
return(false);
}