Make custom types optional

This commit is contained in:
Daniel Cronqvist 2024-11-16 21:14:23 +01:00
parent 67876c6532
commit 8c9068cc97
21 changed files with 189 additions and 59 deletions

View file

@ -73,12 +73,12 @@ public class Program
return templateReader.ReadTemplate();
}
private static ICustomTypeDefinition ResolveCustomType(string name)
private static Optional<ICustomTypeDefinition> ResolveCustomType(string name)
{
ICustomTypeDefinition[] allDefinedTypes =
[
new CustomClassDefinition() { Name = "a" },
];
return allDefinedTypes.FirstOrDefault(type => type.Name == name) ?? throw new InvalidOperationException();
return allDefinedTypes.FirstOrDefault(ctd => ctd.Name == name) is ICustomTypeDefinition ctd ? new Optional<ICustomTypeDefinition>(ctd) : Optional<ICustomTypeDefinition>.Empty;
}
}