Skip to content

Commit 4363956

Browse files
committed
Updated additional DefaultValue processing and removed debug logging
1 parent 1d24039 commit 4363956

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

crates/bindings-csharp/Codegen/Module.cs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,24 @@ attrData.AttributeClass is not { } attrClass
2828
return default;
2929
}
3030

31-
if (attrClass.ToString() == typeof(DefaultAttribute).FullName)
32-
{
33-
// Create a dummy instance to get the mask
34-
var attrWithDefault = attrData.ParseAs<DefaultAttribute>(attrType);
35-
return new(attrWithDefault.Mask, attrWithDefault.Table, attrWithDefault.Value);
36-
}
37-
3831
var attr = attrData.ParseAs<ColumnAttribute>(attrType);
3932
return new(attr.Mask, attr.Table);
4033
}
34+
35+
public static ColumnAttr ParseDefaultAttribute(AttributeData attrData)
36+
{
37+
if (
38+
attrData.AttributeClass is not { } attrClass
39+
|| !AttrTypes.TryGetValue(attrClass.ToString(), out var attrType)
40+
|| attrClass.ToString() != typeof(DefaultAttribute).FullName
41+
)
42+
{
43+
return default;
44+
}
45+
46+
var attr = attrData.ParseAs<DefaultAttribute>(attrType);
47+
return new(attr.Mask, attr.Table, attr.Value);
48+
}
4149
}
4250

4351
record ColumnRef(int Index, string Name);
@@ -49,6 +57,7 @@ record ColumnDeclaration : MemberDeclaration
4957
public readonly bool IsEquatable;
5058
public readonly string FullTableName;
5159
public readonly int ColumnIndex;
60+
public readonly string? ColumnDefaultValue;
5261

5362
// A helper to combine multiple column attributes into a single mask.
5463
// Note: it doesn't check the table names, this is left up to the caller.
@@ -80,6 +89,15 @@ public ColumnDeclaration(string tableName, int index, IFieldSymbol field, DiagRe
8089
.Select(a => new ViewIndex(new ColumnRef(index, field.Name), a, diag))
8190
.ToImmutableArray()
8291
);
92+
93+
ColumnDefaultValue =
94+
field
95+
.GetAttributes()
96+
.Select(ColumnAttr.ParseDefaultAttribute)
97+
.Where(a => a.Mask == ColumnAttrs.Default)
98+
.Select(a => a.ColumnDefaultValue)
99+
.ToList().FirstOrDefault()
100+
;
83101

84102
var type = field.Type;
85103

@@ -582,17 +600,8 @@ public IEnumerable<FieldDefaultValue> GenerateDefaultValues()
582600

583601
yield return new FieldDefaultValue(
584602
view.Name,
585-
$"\"{fieldsWithDefaultValue.ColumnIndex} (Debug log: column name = {fieldsWithDefaultValue.Name}\"",
586-
defaultValue.ColumnDefaultValue ?? "Debug log: Default value was null when it should not have been."
587-
);
588-
}
589-
590-
if (withDefaultValues.Length != 0)
591-
{
592-
yield return new FieldDefaultValue(
593-
"Debug log: This is a debug entry of FieldDefaultValue to see the data available to the codegen.",
594-
$"\"Members of this table ({Members.Length}) = {members}, Views ({Views.Length}) = {view.Name}\"", // This
595-
$$"""defaultColumnNames ({{withDefaultValues.Length}}) = {{defaultValueAttributes}}"""
603+
fieldsWithDefaultValue.ColumnIndex.ToString(),
604+
fieldsWithDefaultValue.ColumnDefaultValue
596605
);
597606
}
598607
}

0 commit comments

Comments
 (0)