-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: release/9.0
Are you sure you want to change the base?
Conversation
ArgumentNullException.ThrowIfNull(destinationType); | ||
if (destinationType == typeof(string) && value is ColumnDefinition columnDefinition) | ||
{ | ||
return GridLengthConverter.ToString(columnDefinition.Width, cultureInfo); |
There was a problem hiding this comment.
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) }; |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
No description provided.