There's a bug in PropertyGrid that makes it so that primitive collections can never update.
-- first, in "PropertyGridUtilities.cs", the following code determines the item type of the collection, which is fine, and works. Implementing this code later might be the best resolution to the bug.
Type listType = ListUtilities.GetListItemType( propertyType );
However, later, when the actual control is created, the following code is executed in order to determine the collection type:
if( type.BaseType == typeof( System.Array ) )
{
Editor.ItemType = type.GetElementType();
}
else if( type.ContainsGenericParameters )
{
Editor.ItemType = type.GetGenericArguments()[ 0 ];
}
this code will fail for anything that is not arrays. To be clear:
typeof(List<string>).ContainsGenericParameters
is false, while
typeof(List<>).ContainsGenericParameters
is true. (https://msdn.microsoft.com/en-us/library/system.type.containsgenericparameters(v=vs.110).aspx)
This could be resolved by simply doing:
Editor.ItemType = type.GetGenricArguments().FirstOrDefault();
However - this would not allow for collection types _inheriting from_ i.e. list<string>.
I Would therefore suggest changing
else if( type.ContainsGenericParameters )
{
Editor.ItemType = type.GetGenericArguments()[ 0 ];
}
to
else
{
Editor.ItemType = ListUtilities.GetListItemType( type );
}
Comments: ** Comment from web user: BoucherS **
-- first, in "PropertyGridUtilities.cs", the following code determines the item type of the collection, which is fine, and works. Implementing this code later might be the best resolution to the bug.
Type listType = ListUtilities.GetListItemType( propertyType );
However, later, when the actual control is created, the following code is executed in order to determine the collection type:
if( type.BaseType == typeof( System.Array ) )
{
Editor.ItemType = type.GetElementType();
}
else if( type.ContainsGenericParameters )
{
Editor.ItemType = type.GetGenericArguments()[ 0 ];
}
this code will fail for anything that is not arrays. To be clear:
typeof(List<string>).ContainsGenericParameters
is false, while
typeof(List<>).ContainsGenericParameters
is true. (https://msdn.microsoft.com/en-us/library/system.type.containsgenericparameters(v=vs.110).aspx)
This could be resolved by simply doing:
Editor.ItemType = type.GetGenricArguments().FirstOrDefault();
However - this would not allow for collection types _inheriting from_ i.e. list<string>.
I Would therefore suggest changing
else if( type.ContainsGenericParameters )
{
Editor.ItemType = type.GetGenericArguments()[ 0 ];
}
to
else
{
Editor.ItemType = ListUtilities.GetListItemType( type );
}
Comments: ** Comment from web user: BoucherS **
Hi,
v2.5 already contains a fix for this, but wasn't taking care of collection types inheriting from List<>.
Your fix will be included in v2.7.
Thanks !