Make project non-dependent on Vogen
Describe the feature
Is there a way to have this package create the generated code but not be dependent on the Vogen package. So other projects using our package doesn't also require referencing Vogen?
Hi @johnwc - other projects using your package wouldn't necessarily need Vogen, but if they didn't reference it, then they wouldn't get code analysis goodness.
@SteveDunn what code analysis goodness?
There's various analysers that offer compiler warnings for things like newing up a value object, or defaulting a value object.
I have not seen these show up during my development, can you give short examples of some that I can paste into my code to see? Currently we only have the following one to test how well it works with EF. How would I use this incorrectly in code to have it show the analysis warnings?
[ValueObject<int>(conversions: Conversions.Default | Conversions.EfCoreValueConverter)]
public partial struct AccountId;
Here's some examples
// catches object creation expressions
var c = new CustomerId(); // error VOG010: Type 'CustomerId' cannot be constructed with 'new' as it is prohibited
CustomerId c = default; // error VOG009: Type 'CustomerId' cannot be constructed with default as it is prohibited.
var c = default(CustomerId); // error VOG009: Type 'CustomerId' cannot be constructed with default as it is prohibited.
var c = GetCustomerId(); // error VOG010: Type 'CustomerId' cannot be constructed with 'new' as it is prohibited
var c = Activator.CreateInstance<CustomerId>(); // error VOG025: Type 'CustomerId' cannot be constructed via Reflection as it is prohibited.
var c = Activator.CreateInstance(<CustomerId>); // error VOG025: Type 'MyVo' cannot be constructed via Reflection as
it is prohibited
// catches lambda expressions
Func<CustomerId> f = () => default; // error VOG009: Type 'CustomerId' cannot be constructed with default as it is prohibited.
// catches method / local function return expressions
CustomerId GetCustomerId() => default; // error VOG009: Type 'CustomerId' cannot be constructed with default as it is prohibited.
CustomerId GetCustomerId() => new CustomerId(); // error VOG010: Type 'CustomerId' cannot be constructed with 'new' as it is prohibited
CustomerId GetCustomerId() => new(); // error VOG010: Type 'CustomerId' cannot be constructed with 'new' as it is prohibited
// catches argument / parameter expressions
Task<CustomerId> t = Task.FromResult<CustomerId>(new()); // error VOG010: Type 'CustomerId' cannot be constructed with 'new' as it is prohibited
void Process(CustomerId customerId = default) { } // error VOG009: Type 'CustomerId' cannot be constructed with default as it is prohibited.```