Serialization Attributes

RonExclude / RonInclude

Include or exclude members from ron serialization.

C#

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",
};

Ron

MyClass(
// Included in generated Ron
includeMember: "I will be serialized"
)

RonInto

Can be applied to a method to allow type conversion from this type into the return type of that method.

C#

public class StringVector{
public string value;
[RonInto]
public Vector3 IntoVector(){
return Vector3.Parse(value);
}
}
public class Point {
Vector3 position;
}

Ron

Point(
// When deserialized StringVector will
// be converted to a Vector3
position: StringVector(
value: "(1, 2, 3)"
)
)

Can also be applied to a static method. Will convert the parameter type into the return type.

C#

public class StringVector{
public string value;
// This also works.
[RonInto]
public static Vector3 IntoVector(
StringVector source
) {
return Vector3.Parse(value);
}
}

Ron

Point(
position: StringVector(
value: "(1, 2, 3)"
)
)

RonFrom

Can be applied to a static method to convert the parameter type into the return type.

C#

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;
}

Ron

Point(
// Vector3.From will be called
// to deserialize this field.
position: "(1, 2, 3)"
)

RonList

Can be applied to a class to make that class serialize as a field.

C#

[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);

Ron

[
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.

C#

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);

Ron

PointCloud(
points: [
Vector3(
x: 0f32,
y: 0f32,
z: 0f32
),
Vector3(
x: 1f32,
y: 1f32,
z: 1f32
)
]
)

RonMap

Can be applied to a class to make that class serialized as a map.

C#

[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);

Ron

{
"Hello": "World"
}

RonProxy

Apply to a class to auto-convert it to another class for serialization and deserialization.

C#

// 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);

Ron

Vector3(
value: "(1, 1, 1)";
)

RonTuple

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.

C#

public class Vector3{
public float x;
public float y;
public float z;
// This constructor will be used to
// Deserialize the Vector3
public Vector3(
float x,
float y,
float z
){
...
}
[RonTuple]
public object[] ToTuple(){
return [x, y, z];
}
}
var value = Vector3.One;
var ron = Ron.Serialize();

Ron

Vector3(
1f32,
1f32,
1f32
)
// Without RonTuple
Vector3(
x: 1f32,
y: 1f32,
z: 1f32
)