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

Adding mixed text and elements to collections using IList.Add. #103

Merged
merged 12 commits into from Sep 28, 2018
Merged

Adding mixed text and elements to collections using IList.Add. #103

merged 12 commits into from Sep 28, 2018

Conversation

grokys
Copy link
Contributor

@grokys grokys commented May 27, 2018

The previous PR #102 fixed adding mixed text and elements to collections if a TypeConverter was available for the type, however System.Xaml doesn't require this - it will try to add inline text in an element to a collection using IList.Add.

This PR implements that behavior, but it also changes the behavior of Portable.Xaml in that it no longer tries to add the item using a typed IList<T>.Add method and just goes straight for IList.Add. I'm not sure if that change in behavior is desired? Should we be trying the typed Add method first and falling back to IList.Add?

I also suspect some of the logic around adding to collections could be tidied up here, but I didn't want to make that change in this PR.

Types that don't have a `TypeConverter` should call `IList.Add`.
Ensure that `GetObject` is emitted when there is a collection that contains text, and use `IList.Add` to add items to collections, so that text can be added as a collection item.
@grokys grokys changed the title Adding mixed text and elements to collections using IList.Add. WIP: Adding mixed text and elements to collections using IList.Add. May 28, 2018
@grokys
Copy link
Contributor Author

grokys commented May 28, 2018

Changed this to be WIP as there's a few issues with it still.

@cwensley
Copy link
Owner

Hey @grokys, looking good, though I'd like to keep IList<T>.Add support as implementing IList<T> doesn't intrinsically implement IList. Perhaps it was the wrong way around before, so use IList.Add first if implemented, then fallback to IList<T>.Add if not.

grokys and others added 6 commits May 31, 2018 00:19
Failing reading a property after collection items.
And simplify `ReadCollectionItems` in the process.
We're testing `InlineCollection` and friends, lets not be shy about that. Move these tests to a new test class so they're a bit more manageable.
@grokys grokys changed the title WIP: Adding mixed text and elements to collections using IList.Add. Adding mixed text and elements to collections using IList.Add. Jun 18, 2018
@grokys
Copy link
Contributor Author

grokys commented Jun 18, 2018

Ok, @cwensley this is now ready for review I think. I hope I've got the IList.Add stuff right, but I can't say I understand that code too well. Please feel free to tweak if it's incorrect.

}
catch (TargetInvocationException e)
{
throw e.InnerException;
Copy link
Owner

Choose a reason for hiding this comment

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

Hm, this would actually trash the original stack trace (where the crash actually happened). I think we should probably leave this try/catch out, unless you have a specific reason for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the purpose of this is throw the original exception raised inside delegate. I don't see any reason why we can't unwrap delegate invocation from try block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohh... I see why it wrapped and re-throwed InnerException after remove this I have failed test: AddToCollectionTypeMismatch(). Assert.Throws<ArgumentException> (() => i.AddToCollection (l, "5")); We must leave this or we can rewrite test and scan ArgumentException in ``InnerException``` or something else? @cwensley what do you think about this?

Copy link
Owner

Choose a reason for hiding this comment

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

@cm4ker take a look at ExceptionDispatchInfo, it can be used to rethrow the inner exception without losing the stack trace. I've used it before here and it works well.

@@ -171,7 +171,7 @@ static XmlReaderSettings CreateReaderSettings(XamlXmlReaderSettings settings, Co
CloseInput = closeInput ?? settings?.CloseInput ?? false,
IgnoreComments = true,
IgnoreProcessingInstructions = true,
IgnoreWhitespace = true,
//IgnoreWhitespace = true,
Copy link
Owner

Choose a reason for hiding this comment

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

Is this test code? or is IgnoreWhitespace's default false?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is not a test code. When IgnoreWhitespace = false then inline tests go fault. Can I just remove commented line in this case?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes that would be perfect.

@cm4ker
Copy link
Collaborator

cm4ker commented Sep 28, 2018

@cwensley It's ready for next review round.

@cwensley
Copy link
Owner

@cm4ker looks beautiful! Thanks!

@cwensley cwensley merged commit 44926c5 into cwensley:develop Sep 28, 2018
@grokys grokys deleted the fixes/collection-text branch September 29, 2018 17:46
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.

None yet

4 participants