Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object writer changes to implement shorthand syntax for ColumnDefinitions and RowDefinitions #4

Draft
wants to merge 5 commits into
base: release/9.0
Choose a base branch
from

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

{
ThrowExceptionWithLine(SR.Format(SR.ParserReadOnlyProp, attribLocalName));
}
}

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

@@ -782,6 +782,10 @@ public override void WriteEndMember()
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.

2 participants