New default named values: $parent and $serializationRoot/$root

Issue #762 new
Ryan George created an issue

One of the more common use-cases for named values I’ve seen is referring to data that exists in a class that owns an instance of a property. For example, having a ValueDropdown in a list item whose values are populated from some list in the parent. Currently this is accomplished by navigating the InspectorProperty graph. e.g.:

public class ListItem
{
   [ValueDropdown("@((ContainingClass) $property.SerializationRoot.ValueEntry.WeakSmartValue).GetNames()")]
   public string Name;
}

public class ContainingClass
{
  public List<ListItem> Items = new List<ListItem>();
  public string[] GetNames() => 
  {
    "Aerith",
    "Bob",
    "Cloud"
  };
}

I’d like to propose two new default name values that function similarly to $property and $value:

  • $parent - refers to the immediate parent of the property, i.e.: $property.Parent.Parent.ValueEntry.WeakSmartValue
  • $serializationRoot/$root - refers to $property.SerializationRoot.ValueEntry.WeakSmartValue
public class DeeplyNestedListItem
{
    [ValueDropdown("$serializationRoot.GetNames()")] 
    public string Name;
}

public class ListItem
{
    [ValueDropdown("$parent.GetNames()")] 
    public string Name;
    public DeeplyNestedListItem Child;
}

public class ContainingClass
{
  public List<ListItem> Items = new List<ListItem>();
  public string[] GetNames() => 
  {
    "Aerith",
    "Bob",
    "Cloud"
  };
}

Having them able to utilize reflection to just find a matching method would be nice. But it would be awesome if they could be strongly typed using something like a generics syntax so it can be compiled:

public interface INameProvider
{
   string[] GetNames();
}

public class DeeplyNestedListItem
{
    [ValueDropdown("$serializationRoot<INameProvider>.GetNames()")] 
    public string Name;
}

public class ListItem
{
    [ValueDropdown("$parent<INameProvider>.GetNames()")] 
    public string Name;
    public DeeplyNestedListItem Child;
}

public class ContainingClass : INameProvider
{
  public List<ListItem> Items = new List<ListItem>();
  public string[] GetNames() => 
  {
    "Aerith",
    "Bob",
    "Cloud"
  };
}

If this works, I’d happily take this too:

[ValueDropdown("((INameProvider) $serializationRoot).GetNames()")] 

Comments (2)

  1. Log in to comment