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

NullReferenceException with HashSet #84

Open
GZTimeWalker opened this issue May 1, 2024 · 0 comments
Open

NullReferenceException with HashSet #84

GZTimeWalker opened this issue May 1, 2024 · 0 comments

Comments

@GZTimeWalker
Copy link

The code here:

_addMethod!.Invoke(list, new[] { value });

will throw a NullReferenceException because of:

foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
{
if (method.Name == "Add" && method.GetParameters().Length == 1 && method.ReturnType == typeof(void) && method.GetParameters()[0].ParameterType == elementType)
{
_addMethod = method;
break;
}
}

will never change _addMethod as the declaration of Add method in HashSet is:

bool HashSet<int>.Add(int item);

where the return type is not matched.


Maybe add support for ISet or ICollection instead of using a hard-coded method declaration?

@GZTimeWalker GZTimeWalker changed the title NullReferenceException with using HashSet NullReferenceException with HashSet May 1, 2024
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

No branches or pull requests

1 participant