OpenRA.FieldSaver.Save C# (CSharp) Method

Save() public static method

public static Save ( object o, bool includePrivateByDefault = false ) : MiniYaml
o object
includePrivateByDefault bool
return MiniYaml
        public static MiniYaml Save(object o, bool includePrivateByDefault = false)
        {
            var nodes = new List<MiniYamlNode>();
            string root = null;

            foreach (var info in FieldLoader.GetTypeLoadInfo(o.GetType(), includePrivateByDefault))
            {
                if (info.Attribute.DictionaryFromYamlKey)
                {
                    var dict = (System.Collections.IDictionary)info.Field.GetValue(o);
                    foreach (var kvp in dict)
                    {
                        var key = ((System.Collections.DictionaryEntry)kvp).Key;
                        var value = ((System.Collections.DictionaryEntry)kvp).Value;

                        nodes.Add(new MiniYamlNode(FormatValue(key), FormatValue(value)));
                    }
                }
                else if (info.Attribute.FromYamlKey)
                    root = FormatValue(o, info.Field);
                else
                    nodes.Add(new MiniYamlNode(info.YamlName, FormatValue(o, info.Field)));
            }

            return new MiniYaml(root, nodes);
        }

Usage Example

Example #1
0
 public override MiniYaml Save()
 {
     return(FieldSaver.Save(this));
 }
All Usage Examples Of OpenRA.FieldSaver::Save