Skip to content

Conversation

@himgoyalmicro
Copy link
Owner

No description provided.

ArgumentNullException.ThrowIfNull(destinationType);
if (destinationType == typeof(string) && value is ColumnDefinition columnDefinition)
{
return GridLengthConverter.ToString(columnDefinition.Width, cultureInfo);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do more checks, you cannot express columns/rows that have min/max/offset set

{
if (value is string input)
{
RowDefinition rowDefinition = new RowDefinition{ Height = GridLengthConverter.FromString(input, cultureInfo) };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use type descriptor to decide whether you should return column or row and have only one converter (possibly even the grid length one), but if this ends up being public, it possibly is a better API separately

}

if (propInfo != null && !XamlTypeMapper.IsAllowedPropertySet(propInfo))
if (propInfo != null && !CanInitializeCollectionFromString(propInfo.PropertyType) && !XamlTypeMapper.IsAllowedPropertySet(propInfo))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably add the new condition at the end for consistency and performance

shouldSetValue = true;
_context.ParentKeyIsUnconverted = true;
}
else if (valueXamlType == XamlLanguage.String && property.Type.IsCollection && property.TypeConverter == null && property.Type.ItemType.TypeConverter != null)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would exclude collections of type string/object because they don't need a converter

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not necessarily bad thing and can be enabled later)

{
return IsACollection(type) && XamlTypeMapper.GetTypeConverterType(type) == null
&& XamlTypeMapper.GetTypeConverterType(GetCollectionItemType(type)) != null;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you could test for though is whether the item type converter can convert from string

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But again you need to decide whether it is desirable to throw "no setter" error or converter error. Maybe the latter is better in this case too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants