1

Closed

Overloaded CLR indexers not supported ("Item" property)

description

When having multiple indexers in a class, Jint just selects the one that happens to come first when enumerating available properties. The proposed patch fixes this by first attempting to let the runtime resolve the property directly using the Type.GetProperty() method (CachedReflectionPropertyGetter.cs). Also included is a change to ExecutionVisitor.cs that adds support for renamed default members (i.e. when the indexer property name is not "Item").

Example broken code:

using System;
using System.Text;
using Jint;

namespace jinttest
{
public enum TestEnum
{
    One = 1,
    Two = 2,
    Three = 3
}

public class Test
{
    public string this[string str]
    {
        get { return "StringIndexer - " + str; }
    }

    public string this[TestEnum num]
    {
        get { return "EnumIndexer - " + num.ToString(); }
    }
}

class Program
{
    static void Main(string[] args)
    {
        object result;

        JintEngine engine = new JintEngine();
        engine.AllowClr = true;
        engine.DisableSecurity();

        StringBuilder program = new StringBuilder();

        program.AppendLine("var o = new jinttest.Test();");
        program.AppendLine("return o[jinttest.TestEnum.Two];");

        result = engine.Run(program.ToString());

        Console.WriteLine(result.ToString());
        Console.ReadKey();
    }
}
}

file attachments

Closed Oct 3, 2014 at 6:43 PM by sebastienros
Jint has been rewritten and this issue should be fixed in the new version. Please check it on https://github.com/sebastienros/jint or on using the nuget package here: https://www.nuget.org/packages/Jint/

comments

neonp wrote Apr 7, 2010 at 1:06 PM

Hi,

Which source did you use to build this patch on. This issue should already be addressed in the last source version on the svn repository.

mka wrote Apr 7, 2010 at 3:45 PM

Hello,

It's based on the latest (?) trunk, revision 209. Should I be using some other branch in order to get the latest changes?

Thanks,
Martin