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

Array.Contains not working #68

Closed
davideicardi opened this issue Oct 9, 2017 · 6 comments
Closed

Array.Contains not working #68

davideicardi opened this issue Oct 9, 2017 · 6 comments
Labels

Comments

@davideicardi
Copy link
Member

Array.Contains doesn't work.

	[Test]
	public void GitHub_Issue_()
	{
		var interpreter = new Interpreter();

		var array = new[] {5, 10, 6};

		interpreter.SetVariable("array", array);

		Assert.AreEqual(array.Contains(5), interpreter.Eval("array.Contains(5)"));
		Assert.AreEqual(array.Contains(3), interpreter.Eval("array.Contains(3)"));
	}

Se also https://stackoverflow.com/questions/46607171/parse-as-expression-an-array-containing-specific-identifier

@AbdoDabbas
Copy link

In file Parser.cs line 1380:
method.MethodBase = methodInfo.MakeGenericMethod(genericArgsType.ToArray());
This where the exception is thrown, I'm not an expert in C#, can you explain why are you trying to do this ?
Does this method MakeGenericMethod means like: "Try to get me back a method applicable to these parameters" ??

@AbdoDabbas
Copy link

AbdoDabbas commented Oct 10, 2017

Can't we change line 1380:
method.MethodBase = methodInfo.MakeGenericMethod(genericArgsType.ToArray());
To:

bool isExtension = methodInfo.IsDefined(typeof(ExtensionAttribute), true);
   if (isExtension)
       method.MethodBase = methodInfo.MakeGenericMethod(genericArgsType.Skip(1).ToArray());
   else
       method.MethodBase = methodInfo.MakeGenericMethod(genericArgsType.ToArray());

It looks like you're passing all arguments to the extension method, while should skip the first one I think.
Not sure of this solution and its effect on other methods but this what made the extension method work.

If it's correct let me know to make a pull request.

@davideicardi
Copy link
Member Author

Maybe this can be a fix, but I should investigate.
If you can I suggest to try it and then run all unit tests, it should probably be a good proof that it is correct. If correct just fork the project, fix it and then create a pull request.

@davideicardi davideicardi added this to the 1.3.5 milestone Oct 31, 2017
@xalikoutis
Copy link

Hi
Whats the status?

@davideicardi
Copy link
Member Author

Sorry, for now no news on my side. Is someone is available I appreciate any help.

@davideicardi
Copy link
Member Author

Fixed in v2.0.2

@davideicardi davideicardi modified the milestones: vNext, 2.1 Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants