-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Looks like the new Vogen broke on ARM64
- Loading branch information
Showing
8 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/BUTR.Site.NexusMods.Server.ValueObjects.Vogen/Utils/IVogen.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace BUTR.Site.NexusMods.Server.ValueObjects.Utils; | ||
|
||
public interface IVogen<TVogen, TValueObject> | ||
where TVogen : IVogen<TVogen, TValueObject> | ||
where TValueObject : notnull | ||
{ | ||
static abstract explicit operator TVogen(TValueObject value); | ||
static abstract explicit operator TValueObject(TVogen value); | ||
|
||
static abstract bool operator ==(TVogen left, TVogen right); | ||
static abstract bool operator !=(TVogen left, TVogen right); | ||
|
||
static abstract bool operator ==(TVogen left, TValueObject right); | ||
static abstract bool operator !=(TVogen left, TValueObject right); | ||
|
||
static abstract bool operator ==(TValueObject left, TVogen right); | ||
static abstract bool operator !=(TValueObject left, TVogen right); | ||
|
||
static abstract TVogen From(TValueObject value); | ||
|
||
static abstract int GetHashCode(TVogen value); | ||
|
||
static abstract bool Equals(TVogen left, TVogen right); | ||
static abstract bool Equals(TVogen left, TVogen right, IEqualityComparer<TVogen> comparer); | ||
|
||
static abstract int CompareTo(TVogen left, TVogen right); | ||
|
||
TValueObject Value { get; } | ||
|
||
bool IsInitialized(); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/BUTR.Site.NexusMods.Server.ValueObjects.Vogen/Utils/VogenSchemaFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Microsoft.OpenApi.Models; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
namespace BUTR.Site.NexusMods.Server.ValueObjects.Utils; | ||
|
||
public sealed class VogenSchemaFilter : ISchemaFilter | ||
{ | ||
private static T CopyPublicProperties<T>(T oldObject, T newObject) where T : class | ||
{ | ||
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; | ||
|
||
if (ReferenceEquals(oldObject, newObject)) return newObject; | ||
|
||
var type = typeof(T); | ||
var propertyList = type.GetProperties(flags); | ||
if (propertyList.Length <= 0) return newObject; | ||
|
||
foreach (var newObjProp in propertyList) | ||
{ | ||
var oldProp = type.GetProperty(newObjProp.Name, flags)!; | ||
if (!oldProp.CanRead || !newObjProp.CanWrite) continue; | ||
|
||
var value = oldProp.GetValue(oldObject); | ||
newObjProp.SetValue(newObject, value); | ||
} | ||
|
||
return newObject; | ||
} | ||
|
||
public void Apply(OpenApiSchema schema, SchemaFilterContext context) | ||
{ | ||
if (context.Type.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IVogen<,>)) is not { } vogen) | ||
return; | ||
|
||
if (vogen.GetGenericArguments() is not [_, { } valueObject]) | ||
return; | ||
|
||
var schemaValueObject = context.SchemaGenerator.GenerateSchema(valueObject, context.SchemaRepository, context.MemberInfo, context.ParameterInfo); | ||
CopyPublicProperties(schemaValueObject, schema); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters