Finished the first complete VDF tree creator.
This commit is contained in:
parent
bb520424ac
commit
1ee60cdf65
@ -34,6 +34,7 @@ public static class VdfConvert
|
|||||||
VdfTreeNode tree = new();
|
VdfTreeNode tree = new();
|
||||||
|
|
||||||
if (obj is IVdfSerializable vdf) return vdf.ToNodeTree();
|
if (obj is IVdfSerializable vdf) return vdf.ToNodeTree();
|
||||||
|
else if (obj is string str) return new VdfSingleNode(str);
|
||||||
else if (obj is IDictionary dictionary)
|
else if (obj is IDictionary dictionary)
|
||||||
{
|
{
|
||||||
object[] keys = new object[dictionary.Count],
|
object[] keys = new object[dictionary.Count],
|
||||||
@ -42,7 +43,7 @@ public static class VdfConvert
|
|||||||
dictionary.Values.CopyTo(values, 0);
|
dictionary.Values.CopyTo(values, 0);
|
||||||
for (int i = 0; i < dictionary.Count; i++)
|
for (int i = 0; i < dictionary.Count; i++)
|
||||||
{
|
{
|
||||||
tree[SerializeObject(keys.GetValue(i), options)!] = ToNodeTree(values.GetValue(i));
|
tree[SerializeObject(keys.GetValue(i), options)!] = ToNodeTree(values.GetValue(i), options);
|
||||||
}
|
}
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ public static class VdfConvert
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
foreach (object item in enumerable)
|
foreach (object item in enumerable)
|
||||||
{
|
{
|
||||||
tree[SerializeObject(index, options)!] = ToNodeTree(item);
|
tree[SerializeObject(index, options)!] = ToNodeTree(item, options);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return tree;
|
return tree;
|
||||||
@ -67,7 +68,10 @@ public static class VdfConvert
|
|||||||
where isPublic && !isStatic && !isIgnored && !isConst
|
where isPublic && !isStatic && !isIgnored && !isConst
|
||||||
select field;
|
select field;
|
||||||
|
|
||||||
IEnumerable<PropertyInfo> validProperties = from prop in type.GetProperties()
|
IEnumerable<PropertyInfo> validProperties;
|
||||||
|
if (options.serializeProperties)
|
||||||
|
{
|
||||||
|
validProperties = from prop in type.GetProperties()
|
||||||
let canGet = prop.GetMethod is not null
|
let canGet = prop.GetMethod is not null
|
||||||
let isPublic = canGet && prop.GetMethod!.IsPublic
|
let isPublic = canGet && prop.GetMethod!.IsPublic
|
||||||
let isStatic = canGet && prop.GetMethod!.IsStatic
|
let isStatic = canGet && prop.GetMethod!.IsStatic
|
||||||
@ -75,9 +79,17 @@ public static class VdfConvert
|
|||||||
x.AttributeType == typeof(VdfIgnoreAttribute))
|
x.AttributeType == typeof(VdfIgnoreAttribute))
|
||||||
where canGet && isPublic && !isStatic && !isIgnored
|
where canGet && isPublic && !isStatic && !isIgnored
|
||||||
select prop;
|
select prop;
|
||||||
|
}
|
||||||
|
else validProperties = Array.Empty<PropertyInfo>();
|
||||||
|
|
||||||
foreach (FieldInfo field in validFields) Write($"field: {field.Name}");
|
foreach (FieldInfo field in validFields)
|
||||||
foreach (PropertyInfo prop in validProperties) Write($"prop: {prop.Name}");
|
{
|
||||||
|
tree[field.Name] = ToNodeTree(field.GetValue(obj), options);
|
||||||
|
}
|
||||||
|
foreach (PropertyInfo prop in validProperties)
|
||||||
|
{
|
||||||
|
tree[prop.Name] = ToNodeTree(prop.GetValue(obj), options);
|
||||||
|
}
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ public record class VdfOptions
|
|||||||
public bool closeWhenFinished;
|
public bool closeWhenFinished;
|
||||||
public int indentSize;
|
public int indentSize;
|
||||||
public bool resetStreamPosition;
|
public bool resetStreamPosition;
|
||||||
|
public bool serializeProperties;
|
||||||
public bool useEscapeCodes;
|
public bool useEscapeCodes;
|
||||||
public bool useQuotes;
|
public bool useQuotes;
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ public record class VdfOptions
|
|||||||
closeWhenFinished = true;
|
closeWhenFinished = true;
|
||||||
indentSize = 4;
|
indentSize = 4;
|
||||||
resetStreamPosition = false;
|
resetStreamPosition = false;
|
||||||
|
serializeProperties = true;
|
||||||
useEscapeCodes = false;
|
useEscapeCodes = false;
|
||||||
useQuotes = false;
|
useQuotes = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,8 @@ public class VdfTreeNode : VdfNode, IEnumerable<KeyValuePair<string, VdfNode?>>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Add(string key, VdfNode? value) => this[key] = value;
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
public IEnumerator<KeyValuePair<string, VdfNode?>> GetEnumerator() => p_subNodes.GetEnumerator();
|
public IEnumerator<KeyValuePair<string, VdfNode?>> GetEnumerator() => p_subNodes.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user