Skip to content
Mailaender edited this page Aug 4, 2012 · 5 revisions

To load subobjects in your trait class, while using as much of the FieldLoader machinery as possible, do something like this:

// the subobject -- needs to be trivially constructible, and its fields should be understood by FL.
public class Obj
{ 
    public readonly string Name;
    public readonly int[] SomeArr;
}

// your traitinfo class
public class MyScriptInfo : ... whatever
{
    ...
    
    [FieldLoader.LoadUsing( "LoadObjs" )] public Obj[] Objs;
    
    static object LoadObjs( MiniYaml yaml )
    {
        return yaml.Nodes.Where( y => y.Key.Split('@')[0] == "Obj" )
            .Select( y => FieldLoader.Load<Obj>( y.Value ) )
            .ToArray();
    }
}
Clone this wiki locally