added method to create ListFields and generation of Lists
This commit is contained in:
@@ -161,6 +161,11 @@ namespace CodeGenerator {
|
|||||||
Log($"Fields: {type.Fields.Count}");
|
Log($"Fields: {type.Fields.Count}");
|
||||||
for (var index = 0; index < type.Fields.Count; index++) {
|
for (var index = 0; index < type.Fields.Count; index++) {
|
||||||
var field = type.Fields[index];
|
var field = type.Fields[index];
|
||||||
|
if (!normalFields.Contains(field)) {
|
||||||
|
Log($"Field {field.Name} is part of a list, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
CodeMemberField cmf;
|
CodeMemberField cmf;
|
||||||
string name = field.Name;
|
string name = field.Name;
|
||||||
if (name.Contains("()")) continue;
|
if (name.Contains("()")) continue;
|
||||||
@@ -179,7 +184,19 @@ namespace CodeGenerator {
|
|||||||
ctd.Members.Add(cmf);
|
ctd.Members.Add(cmf);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctd.CustomAttributes[0].Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(totalSize)));
|
//Add the list fields to the class
|
||||||
|
foreach (var field in listFields) {
|
||||||
|
var listPointer = field.Item1;
|
||||||
|
var listLength = field.Item2;
|
||||||
|
Log($"Generating list field {listPointer.Name}");
|
||||||
|
|
||||||
|
CodeMemberField cmf = CreateListMemberField(listPointer, listLength);
|
||||||
|
//TODO: add DNAListAttribute
|
||||||
|
|
||||||
|
ctd.Members.Add(cmf);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctd.CustomAttributes[0].Arguments.Add(new (new CodePrimitiveExpression(totalSize)));
|
||||||
|
|
||||||
Log("Generating Parameterless constructor");
|
Log("Generating Parameterless constructor");
|
||||||
if(ctd.Members.Count > 0)
|
if(ctd.Members.Count > 0)
|
||||||
@@ -226,6 +243,7 @@ namespace CodeGenerator {
|
|||||||
out List<(BlendFile.DnaField, BlendFile.DnaField)> listFields) {
|
out List<(BlendFile.DnaField, BlendFile.DnaField)> listFields) {
|
||||||
normalFields = new(); //Fields that are not lists nor lengths of lists
|
normalFields = new(); //Fields that are not lists nor lengths of lists
|
||||||
listFields = new(); //Fields that are lists, and their corresponding length fields
|
listFields = new(); //Fields that are lists, and their corresponding length fields
|
||||||
|
|
||||||
//Cast to array the fields to avoid multiple enumerations
|
//Cast to array the fields to avoid multiple enumerations
|
||||||
var dnaFields = fields as BlendFile.DnaField[] ?? fields.ToArray();
|
var dnaFields = fields as BlendFile.DnaField[] ?? fields.ToArray();
|
||||||
foreach (var field in dnaFields) {
|
foreach (var field in dnaFields) {
|
||||||
@@ -402,6 +420,23 @@ namespace CodeGenerator {
|
|||||||
return cmf;
|
return cmf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CodeMemberField CreateListMemberField(BlendFile.DnaField field, BlendFile.DnaField lenght) {
|
||||||
|
Type t = Type.GetType(field.Type.ParseFType());
|
||||||
|
CodeMemberField cmf;
|
||||||
|
CodeTypeReference ctr = new(typeof(List<>));
|
||||||
|
|
||||||
|
//Check if the type is a built-in type or a custom type
|
||||||
|
if (t != null) { //Built-in type
|
||||||
|
ctr.TypeArguments.Add(t);
|
||||||
|
cmf = new(ctr, field.Name.ParseFName());
|
||||||
|
} else { //Custom type
|
||||||
|
ctr.TypeArguments.Add(new CodeTypeReference(field.Type));
|
||||||
|
cmf = new(ctr, field.Name.ParseFName());
|
||||||
|
}
|
||||||
|
cmf.Attributes = MemberAttributes.Public;
|
||||||
|
return cmf;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<int> GetArrayDimensions(string name)
|
private static List<int> GetArrayDimensions(string name)
|
||||||
{
|
{
|
||||||
var dimensions = new List<int>();
|
var dimensions = new List<int>();
|
||||||
|
|||||||
Reference in New Issue
Block a user