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

Issue finding indexer #57

Closed
richardsheppard-avalara opened this issue Dec 5, 2016 · 7 comments
Closed

Issue finding indexer #57

richardsheppard-avalara opened this issue Dec 5, 2016 · 7 comments
Assignees
Labels

Comments

@richardsheppard-avalara
Copy link

I'm running into an issue with the .Net Core port of dynamic linq.

I'm trying to sort a list of JObjects and I get this error:

No applicable indexer exists in type 'JObject'.

Here's an example

var rows = new List<JObject>();

var row1 = new JObject();
row1["Column1"] = "B";
row1["Column2"] = 2;
rows.Add(row1);

var row2 = new JObject();
row2["Column1"] = "B";
row2["Column2"] = 1;
rows.Add(row2);

var row3 = new JObject();
row3["Column1"] = "A";
row3["Column2"] = 2;
rows.Add(row3);

var row4 = new JObject();
row4["Column1"] = "A";
row4["Column2"] = 1;
rows.Add(row4);

var list = rows.AsQueryable().OrderBy(@"it[""Column1""]").ToList();

Note this code works with the System.Linq.Dynamic dll on a .Net 4.5.2 project.

I believe this issue resides in the FindIndexer method in the ExpressionParser class.

https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/src/System.Linq.Dynamic.Core/ExpressionParser.cs#L1681-L1707

        int FindIndexer(Type type, Expression[] args, out MethodBase method)
        {
            foreach (Type t in SelfAndBaseTypes(type))
            {
#if !(NETFX_CORE || WINDOWS_APP || DOTNET5_1 || UAP10_0 || NETSTANDARD)
                MemberInfo[] members = t.GetDefaultMembers();
#else
                MemberInfo[] members = new MemberInfo[0];
#endif

If you take away the NETSTANDARD check everything seems to work, although I'm not sure if that would effect anything else. I made that change locally and ran all the unit tests and they all passed. There might be better fix, but I'm not as familiar with the code.

@StefH
Copy link
Collaborator

StefH commented Dec 7, 2016

Thanks for your analysis, I'll look into this.

@StefH StefH self-assigned this Dec 7, 2016
@StefH StefH added the bug label Dec 7, 2016
@StefH
Copy link
Collaborator

StefH commented Dec 7, 2016

I think that the code

MemberInfo[] members = t.GetDefaultMembers();

will work for all frameworks.

I did fix it, can you retest (or do you need a new NuGet?)

StefH added a commit that referenced this issue Dec 7, 2016
@richardsheppard-avalara
Copy link
Author

I will retest it real quick and let you know.

@richardsheppard-avalara
Copy link
Author

That fixed my issue. My tests are passing now. I will need a new version on nuget at some point though.

Thanks for the quick turn around on this.

@StefH
Copy link
Collaborator

StefH commented Dec 8, 2016

New NuGet is uploaded.

@richardsheppard-avalara
Copy link
Author

Thanks. I did some more testing and everything looks good.

I think we can close this issue.

@StefH
Copy link
Collaborator

StefH commented Dec 8, 2016

OK

@StefH StefH closed this as completed Dec 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants