Skip to content

Types of nested properties are not registered with the custom type provider #13

Description

@ncguilbeault

Description

When using expression scripting, I noticed that only the type of the source itself is registered with the custom type provider. So, any type reached through a property of the source type cannot be named in an expression. This is most visible with enum-typed properties, where naming the enum type is the natural way to write the comparison. For example:

using Bonsai;
using System.Linq;
using System;
using System.Reactive.Linq;
using System.ComponentModel;

[Combinator]
[Description("")]
[WorkflowElementCategory(ElementCategory.Source)]
public class NestedEnum
{
    public InnerEnum Value { get { return _value; } set { _value = value; } }

    InnerEnum _value = InnerEnum.A;

    public IObservable<NestedEnum> Process()
    {
        return Observable.Return(this);
    }
}

public enum InnerEnum
{
    A,
    B,
    C
}

Feeding the output directly to an ExpressionTransform and comparing against the enum by name fails:

it.Value == InnerEnum.B

Type 'InnerEnum' not found

as does casting to the enum:

InnerEnum(it.Value + 1)

No applicable method 'InnerEnum' exists in type 'NestedEnum'

However, the same expressions work fine when InnerEnum becomes the source type.

In practice, any source type that exposes its "useful" objects behind a property does not get those types registered. I'm not sure if there are specific gotchas with the following approach, but could this be fixed by expanding the EnumerateTypeHierarchy method in src/Bonsai.Scripting.Expressions/ParsingConfigHelper.cs to walk the properties of the object as well as the interfaces and the base chain of the type it is handed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions