Skip to content

Conversation

@eNeRGy164
Copy link
Contributor

Detect specific exceptions with .ToArray() with ImmutableArray<T>.

Should fix #1655

IMPORTANT

Copy link
Member

@jnyrup jnyrup left a comment

Choose a reason for hiding this comment

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

How do we handle empty vs default instances?
Should they be considered equivalent?

{
return ((IEnumerable)value).Cast<object>().ToArray();
}
catch (InvalidOperationException) when (value.GetType().Name.Equals("ImmutableArray`1", StringComparison.Ordinal))
Copy link
Member

Choose a reason for hiding this comment

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

Is it out of habit that you're not using == instead of Equals or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's probably caused by copy & pasting the suggestion by @Tragedian and changing the StartWith with an exact match.

@dennisdoomen
Copy link
Member

dennisdoomen commented Aug 30, 2021

Hmm, on second thought, maybe we should just bite the bullet and accept taking a dependency on the System.Collections.Immutable package.

#1655 (comment)

@eNeRGy164
Copy link
Contributor Author

How do we handle empty vs default instances?
Should they be considered equivalent?

I think we can only do this correctly if we take a dependency on the package like @dennisdoomen is suggesting

@jnyrup jnyrup merged commit 178861b into fluentassertions:master Sep 10, 2021
@eNeRGy164 eNeRGy164 deleted the support-immutablearray branch September 10, 2021 11:06
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.

InvalidOperationException when asserting equivalent with default instance of ImmutableArray<T>

3 participants