Skip to content

Commit 2d5753d

Browse files
committed
Fixes to single-file enums and intersections
1 parent 6576d38 commit 2d5753d

9 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/DataverseProxyGenerator.Core/Generation/CSharpProxyGenerator.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using DataverseProxyGenerator.Core.Domain;
22
using DataverseProxyGenerator.Core.Generation.Generators;
3+
using DataverseProxyGenerator.Core.Generation.Mappers;
34
using DataverseProxyGenerator.Core.Templates;
45

56
namespace DataverseProxyGenerator.Core.Generation;
@@ -72,7 +73,7 @@ private static (Dictionary<string, HashSet<ColumnSignature>> InterfaceColumns, D
7273
return BuildIntersectionData(config.IntersectMapping, tableDict, tableColumns);
7374
}
7475

75-
private IEnumerable<GeneratedFile> GenerateSingleFile(
76+
private static IEnumerable<GeneratedFile> GenerateSingleFile(
7677
List<TableModel> tablesList,
7778
Dictionary<string, HashSet<ColumnSignature>> interfaceColumns,
7879
Dictionary<string, List<string>> tableToInterfaces,
@@ -93,7 +94,9 @@ private static object CreateSingleFileTemplateModel(
9394
Dictionary<string, List<string>> tableToInterfaces,
9495
GenerationContext context)
9596
{
96-
var globalOptionsets = GetGlobalOptionsets(tablesList).ToList();
97+
var globalOptionsets = GetGlobalOptionsets(tablesList)
98+
.Select(enumCol => EnumMapper.MapToTemplateModel(enumCol, context))
99+
.ToList();
97100
var interfaces = CreateInterfaceModels(interfaceColumns, tablesList);
98101

99102
// Add interface lists to tables (without modifying TableModel structure)
@@ -140,6 +143,14 @@ private static List<object> CreateInterfaceModels(
140143
Name = kvp.Key,
141144
Columns = kvp.Value.Select(sig => FindMatchingColumn(sig, tablesList))
142145
.Where(c => c != null)
146+
.Select(col => new
147+
{
148+
SchemaName = Utilities.GenerationUtilities.SanitizeName(col!.SchemaName),
149+
col!.LogicalName,
150+
col.DisplayName,
151+
col.Description,
152+
TypeSignature = Utilities.GenerationUtilities.GetTypeSignature(col),
153+
})
143154
.ToList(),
144155
}).ToList<object>();
145156
}

src/DataverseProxyGenerator.Core/Generation/Mappers/EnumMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static object MapToTemplateModel(EnumColumnModel input, GenerationContext
1010
ArgumentNullException.ThrowIfNull(context);
1111
ArgumentNullException.ThrowIfNull(input);
1212

13-
var sanitizedOptionSetName = DataverseProxyGenerator.Core.Generation.Utilities.GenerationUtilities.SanitizeName(input.OptionsetName, "UnknownOptionSet");
13+
var sanitizedOptionSetName = GenerationUtilities.SanitizeName(input.OptionsetName, "UnknownOptionSet");
1414

1515
// Generate unique enum member names to handle duplicate labels using groupBy approach
1616
var sanitizedOptions = input.OptionsetValues
@@ -42,4 +42,4 @@ public static object MapToTemplateModel(EnumColumnModel input, GenerationContext
4242
version = context.Version,
4343
};
4444
}
45-
}
45+
}

src/DataverseProxyGenerator.Core/Generation/Mappers/HelperFileMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public static object MapToTemplateModel(string templateName, GenerationContext c
1212
version = context.Version,
1313
};
1414
}
15-
}
15+
}

src/DataverseProxyGenerator.Core/Generation/Mappers/IntersectionInterfaceMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ public static object MapToTemplateModel((string InterfaceName, IEnumerable<Colum
2828
version = context.Version,
2929
};
3030
}
31-
}
31+
}

src/DataverseProxyGenerator.Core/Generation/Mappers/ProxyClassMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ public static object MapToTemplateModel((TableModel Table, IReadOnlyList<string>
4545
version = context.Version,
4646
};
4747
}
48-
}
48+
}

src/DataverseProxyGenerator.Core/Generation/Mappers/XrmContextMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ public static object MapToTemplateModel(IEnumerable<TableModel> input, Generatio
1717
version = context.Version,
1818
};
1919
}
20-
}
20+
}

src/DataverseProxyGenerator.Core/Generation/Utilities/FilePathHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static string GetIntersectionInterfaceFilePath(string sanitizedName)
3535
/// <summary>
3636
/// Gets the output path for the Xrm context class file.
3737
/// </summary>
38+
/// <param name="sanitizedName">The sanitized name for the context file.</param>
3839
/// <returns>The relative file path.</returns>
3940
public static string GetXrmContextFilePath(string sanitizedName)
4041
{

src/DataverseProxyGenerator.Core/Generation/Utilities/GenerationUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public static string GetTypeSignature(ColumnModel column)
2424
{
2525
return TypeSignatureHelper.GetPropertyTypeSignature(column);
2626
}
27-
}
27+
}

src/DataverseProxyGenerator.Core/Templates/SingleFile.scriban-cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,22 @@ public interface {{interface.Name}}
216216
[System.CodeDom.Compiler.GeneratedCode("DataverseProxyGenerator", "{{version}}")]
217217
[DataContract]
218218
#pragma warning disable CS8981
219-
public enum {{optionsetName}}
219+
public enum {{optionset.optionsetName}}
220220
#pragma warning restore CS8981
221221
{
222-
{{~ for pair in optionset.Values | array.sort "Value" ~}}
222+
{{~ for pair in optionset.optionsetValues | array.sort "Value" ~}}
223223
[EnumMember]
224224
{{~ for loc in pair.Localizations ~}}
225225
[OptionSetMetadata("{{ loc.Value }}", {{ loc.Key }})]
226226
{{~ end ~}}
227227
{{ pair.Name }} = {{ pair.Value }},
228+
{{~ if !for.last ~}}
229+
230+
{{~ end ~}}
228231
{{~ end ~}}
229232
}
230-
{{~ end ~}}
231233

234+
{{~ end ~}}
232235
// ============================================================================
233236
// ATTRIBUTE CLASSES
234237
// ============================================================================

0 commit comments

Comments
 (0)