Missing properties when accessing the object obtained from the host function returning an interface which inherits from several interfaces
uleelx opened this issue · comments
Version used
3.0.0-beta-2053/3.0.0-beta-2052/3.0.0-beta-2051
Describe the bug
Missing properties when accessing the object obtained from the host function returning an interface which inherits from several interfaces.
Version 3.0.0-beta-2050 is ok.
To Reproduce
using Jint;
using System.Collections.ObjectModel;
namespace ConsoleApp1
{
public interface IIndexer<out T>
{
T this[int index] { get; }
}
public interface ICountable<out T>
{
int Count { get; }
}
public interface IStringCollection : IIndexer<string>, ICountable<string>
{
string? this[string name] { get; }
}
public class Strings : IStringCollection
{
private readonly ReadOnlyCollection<string> _strings;
public Strings(List<string> strings)
{
_strings = new ReadOnlyCollection<string>(strings);
}
public string? this[string name]
{
get
{
if (int.TryParse(name, out var index))
{
return _strings[index];
}
return _strings.FirstOrDefault(x => x.Contains(name));
}
}
public string this[int index] => _strings[index];
public int Count => _strings.Count;
}
public class Utils
{
public IStringCollection GetStrings()
{
IStringCollection strings = new Strings(new List<string>() { "a", "b", "c" });
return strings;
}
}
internal class Program
{
static void Main(string[] args)
{
Engine engine = new Engine();
engine.SetValue("Utils", new Utils());
engine.Execute(@"const strings = Utils.GetStrings(); var result = strings.Count;");
var result = engine.GetValue("result").ToString();
Console.WriteLine($"strings.Count: {result}");
}
}
}
Expected behavior
Print "strings.Count: 3" expected, but "strings.Count: null"
Thanks for the report, should be now fixed in main
.