-
Notifications
You must be signed in to change notification settings - Fork 45
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
Static Abstract Members Support #1 #511
Comments
An interesting idea - thanks Aragas! I'll look into this shortly. |
It is tricky to implement this, especially for the casting operators, because they are not guaranteed to be the same for every value object. e.g., one VO can specify to have them generated, and another one can say to omit them. The equality operators look to be no problem though, as they are universal. |
@Aragas , this is now implemented in a branch. I'm working on a sample, and thought your value comparer would be ideal. On the subject of EF Core, Vogen generates this code: public class EfCoreValueComparer : global::Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer<SomeId>
{
public EfCoreValueComparer() : base(
(left, right) => DoCompare(left, right),
instance => instance._isInitialized ? instance._value.GetHashCode() : 0)
{
}
static bool DoCompare(SomeId left, SomeId right)
{
// if both null, then they're equal
if (left is null) return right is null;
// if only right is null, then they're not equal
if (right is null) return false;
// if they're both the same reference, then they're equal
if (ReferenceEquals(left, right)) return true;
// if neither are initialized, then they're equal
if(!left._isInitialized && !right._isInitialized) return true;
return left._isInitialized && right._isInitialized && left._value.Equals(right._value);
}
} Also generated is this extension method: public static class __EfCoreDateTimeOffsetVoEfCoreExtensions
{
public static global::Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<EfCoreDateTimeOffsetVo> HasVogenConversion(this global::Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder<EfCoreDateTimeOffsetVo> propertyBuilder) =>
propertyBuilder.HasConversion<EfCoreDateTimeOffsetVo.EfCoreValueConverter, EfCoreDateTimeOffsetVo.EfCoreValueComparer>();
} So, in your code, you have this: modelBuilder
.Entity<EfCoreTestEntity>(builder =>
{
builder
.Property(x => x.Id)
.HasVogenConversion()
// use the above instead to register the converter and comparer
// .HasConversion(new EfCoreDateTimeOffsetVo.EfCoreValueConverter())
.ValueGeneratedNever();
}); I was struggling to see how I could fit this example in, so instead I went with the scenario of a 'unique ID factory', where it just needs to know that it's a value object of type What do you think? Might you be able to help by adding another scenario, perhaps another EF core scenario where the generated stuff isn't needed and just uses the code you have above? |
@SteveDunn I would like to extended the ValueComparer a bit with #598 If speaking about EF Core scenarios, I'll try to take a look at it, especially with the snapshot functionality |
Another point with |
And if |
I also believe that I might have been wrong with the Vogen/src/Vogen/WriteStaticAbstracts.cs Line 41 in 1265a0e
|
The non-null constraint on TPrimitive, found in the IVogen interface in the WriteStaticAbstracts.cs file, has been removed based on comment: #511 (comment)
Released in 4.0.5 |
Add support for static abstract members. From what I've seen, we can add at least these members:
This will require the language version check and the runtime check, as I understand
The main usecase I see is user-defined extensions that don't need direct support from Vogen.
As an example, I'm currently using it to define a generic EF Core Comparer
The text was updated successfully, but these errors were encountered: