Include or exclude members from ron serialization.
public class MyClass{[RonExclude]public string excludeMember;[RonInclude]private string includeMember;}var value = new MyClass{excludeMember="I will not be serialized",includeMember="I will be serialized",};
MyClass(// Included in generated RonincludeMember: "I will be serialized")
Can be applied to a method to allow type conversion from this type into the return type of that method.
public class StringVector{public string value;[RonInto]public Vector3 IntoVector(){return Vector3.Parse(value);}}public class Point {Vector3 position;}
Point(// When deserialized StringVector will// be converted to a Vector3position: StringVector(value: "(1, 2, 3)"))
Can also be applied to a static method. Will convert the parameter type into the return type.
public class StringVector{public string value;// This also works.[RonInto]public static Vector3 IntoVector(StringVector source) {return Vector3.Parse(value);}}
Point(position: StringVector(value: "(1, 2, 3)"))
Can be applied to a static method to convert the parameter type into the return type.
public class Vector3{public float x;public float y;public float z;[RonFrom]public static Vector3 From(string source){return Vector3.Parse(source);}}public class Point{public Vector3 position;}
Point(// Vector3.From will be called// to deserialize this field.position: "(1, 2, 3)")
Can be applied to a class to make that class serialize as a field.
[RonList]public class VectorLinkedList: IEnumerable<Vector3>{public VectorLinkedList next;// This constructor will be used to// deserialize the list.public VectorLinkedList(IEnumerable<Vector3> list){...}// This will be used to serialize// the list.public IEnumerator GetEnumerator(){...}public IEnumerator<Vector3> GetEnumerator(){...}}var list = new VectorLinkedList(new Vector3[]{Vector3.Zero, Vector3.One});var serialized = Ron.Serialize(list);
[Vector3(x: 0f32,y: 0f32,z: 0f32),Vector3(x: 1f32,y: 1f32,z: 1f32)]
Can be applied to a field to make the field serialize as a list.
public class PointCloud {// Will be serialized as a list.[RonList]public VectorLinkedList points;}var pointCloud = new PointCloud{points = new VectorLinkedList(new Vector3[]{Vector3.Zero,Vector3.One})};var ron = Ron.Serialize(pointCloud);
PointCloud(points: [Vector3(x: 0f32,y: 0f32,z: 0f32),Vector3(x: 1f32,y: 1f32,z: 1f32)])
Can be applied to a class to make that class serialized as a map.
[RonMap]public class MySet: IDictionary<string, string>{public Dictionary<string, string> values;// This constructor will be used to// deserialize MySet.public MySet(IDictionary<string, string> source){values = source.ToDictionary();}// This method will be used to// serialize MySet.[RonInto]public IDictionary<string, string> IntoDictionary(){return values;}}var set = new MySet{values = new Dictionary<string, string>(){{"Hello": "World"}}};var ron = Ron.Serialize(set);
{"Hello": "World"}
Apply to a class to auto-convert it to another class for serialization and deserialization.
// Will be converted to a StringVector// when serialized// Will be converted from a StringVector// when deserialized// See RonInto and RonFrom for// info about serialization.[RonProxy(typeof(StringVector))]public class Vector3{public float x;public float y;public float z;}public class StringVector{public string value;[RonFrom]public static StringVector From(Vector3 source){return new StringVector{value = source.ToString();};}[RonInto]public Vector3 IntoVector(){return Vector3.Parse(value);};}var vector = Vector3.One;var ron = Ron.Serialize(vector);
Vector3(value: "(1, 1, 1)";)
Apply this to a method to convert this type into a tuple before serializing.
When deserializing Ron will look for a matching constructor to deserialize the type.
public class Vector3{public float x;public float y;public float z;// This constructor will be used to// Deserialize the Vector3public Vector3(float x,float y,float z){...}[RonTuple]public object[] ToTuple(){return [x, y, z];}}var value = Vector3.One;var ron = Ron.Serialize();
Vector3(1f32,1f32,1f32)// Without RonTupleVector3(x: 1f32,y: 1f32,z: 1f32)