-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derived attribute causes exception #658
Comments
Unfortunately, derived attributes must include all of the parameter from the base attribute. So in your case, it's this immensely verbose declaration! public class CustomValueObjectAttribute<T> : ValueObjectAttribute<T>
{
public CustomValueObjectAttribute(
Conversions conversions = Conversions.Default | Conversions.EfCoreValueConverter,
Type? throws = null,
Customizations customizations = Customizations.None,
DeserializationStrictness deserializationStrictness = DeserializationStrictness.AllowValidAndKnownInstances,
DebuggerAttributeGeneration debuggerAttributes = DebuggerAttributeGeneration.Default,
ComparisonGeneration comparison = ComparisonGeneration.Omit,
StringComparersGeneration stringComparers = StringComparersGeneration.Unspecified,
CastOperator toPrimitiveCasting = CastOperator.Implicit,
CastOperator fromPrimitiveCasting = CastOperator.Implicit,
ParsableForStrings parsableForStrings = ParsableForStrings.Unspecified,
ParsableForPrimitives parsableForPrimitives = ParsableForPrimitives.Unspecified,
TryFromGeneration tryFromGeneration = TryFromGeneration.Unspecified,
IsInitializedMethodGeneration isInitializedMethodGeneration = IsInitializedMethodGeneration.Unspecified,
PrimitiveEqualityGeneration primitiveEqualityGeneration = PrimitiveEqualityGeneration.Unspecified)
: base(
conversions, throws, customizations, deserializationStrictness, debuggerAttributes, comparison, stringComparers,
toPrimitiveCasting, fromPrimitiveCasting, parsableForStrings, parsableForPrimitives, tryFromGeneration,
isInitializedMethodGeneration, primitiveEqualityGeneration)
{
}
} It should be something like this, which is more natural, but Vogen doesn't currently support: public CustomValueObjectAttribute(
Conversions conversions = Conversions.Default | Conversions.EfCoreValueConverter,
ComparisonGeneration comparison = ComparisonGeneration.Omit,
CastOperator toPrimitiveCasting = CastOperator.Implicit,
CastOperator fromPrimitiveCasting = CastOperator.Implicit)
: base(conversions: conversions, comparison: comparison, toPrimitiveCasting: toPrimitiveCasting, fromPrimitiveCasting: fromPrimitiveCasting)
{
} This is because Vogen reads constructor parameters in order, rather than by name. So it expects the 14th parameter to be pf a certain type, the 13th to be of a certain type, etc. etc. In the case of this bug, the parameter at position 1 was expected to be a type (of the exception that is thrown during validation), but instead was an integer (representing the constant value of an enum). I need to have a think about a better way to handle this, maybe: [VogenConfig<Guid>]
public partial class CustomValueObject
{
public readonly Conversions conversions = Conversions.Default | Conversions.EfCoreValueConverter;
public readonly ComparisonGeneration comparison = ComparisonGeneration.Omit;
public readonly CastOperator toPrimitiveCasting = CastOperator.Implicit;
public readonly CastOperator fromPrimitiveCasting = CastOperator.Implicit;
}
That would then generate a `CustomValueObject<Guid>` attribute
I don't think this change is going to happen within the next couple of weeks though, so it looks like the ugly verbose way is the best way.
Mind you, if it's **assembly wide** config, then you can use the `[assembly: VogenDefaults(...)]`, but as I say, that's per-assembly. |
Describe the bug
This should work:
... but it fails
This is currently failing with
InvalidCastException.
Vogen v4.0.17
Steps to reproduce
Use the code above
Expected behaviour
No exceptions
The text was updated successfully, but these errors were encountered: