Skip to content

Commit

Permalink
fix: inherience of dynamic interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed Aug 21, 2024
1 parent 332b3d8 commit 3f3c414
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/Shared/V2/DynamicTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,23 @@ public static bool IsTypeBuilderInstantiation(Type type)

public bool ContainsPropertyFromInterfaceInBaseClass(string propertyName, out Type[] interfaceType, bool build=false)
{
interfaceType = Interfaces.Where(i =>
Type[] GetInterfaceChain()
{
var result = new List<Type>();
var queue = new Queue<Type>(Interfaces);
while (queue.Count > 0)
{
var current = queue.Dequeue();
result.Add(current);
foreach (var i in IsTypeBuilderInstantiation(current) ? current.GetGenericTypeDefinition().GetInterfaces() : current.GetInterfaces())
{
queue.Enqueue(i);
}
}
return result.Distinct().ToArray();
}

interfaceType = GetInterfaceChain().Where(i =>
(!IsTypeBuilderInstantiation (i) && i.GetProperties().Any(p => p.Name == propertyName))
||i.IsGenericType && i.GetGenericTypeDefinition().GetProperties().Any(p => p.Name == propertyName))
.Select( t=> build && t.IsGenericType ?
Expand Down
47 changes: 43 additions & 4 deletions test/EAVFramework.UnitTest/GenericTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public async Task TestOIDCModule()
{

o.DTOBaseInterfaces = new Type[] {
typeof(IIdentity), typeof(IIdentity),
typeof(IIdentity), typeof(IIdentity),typeof(IAuditFields), //typeof(IAuditOwnerFields<>),
typeof(IContact),typeof(IWebsite),typeof(IContactInformation<>),
typeof(IOpenIdConnectClient<,>),
typeof(IOpenIdConnectAuthorization<,,>),
Expand Down Expand Up @@ -278,15 +278,54 @@ public interface IWebsite


}
[EntityInterface(EntityKey = "Contact Information")]

public interface IAuditOwnerFields
{
public DateTime? CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }

public Guid? CreatedById { get; set; }
public Guid? OwnerId { get; set; }

public Guid? ModifiedById { get; set; }
public byte[] RowVersion { get; set; }
}

[EntityInterface(EntityKey = "*")]

public interface IAuditOwnerFields<T> : IAuditOwnerFields
where T : IIdentity
{
public T CreatedBy { get; set; }
public T ModifiedBy { get; set; }

}

public interface IContactInformation
{
Guid Id { get; set; }
public string Value { get; set; }
}

[EntityInterface(EntityKey = "Contact Information")]
[ConstraintMapping(AttributeKey = "Type", ConstraintName = nameof(TContactInformationType))]
public interface IContactInformation<TContactInformationType>
public interface IContactInformation<TContactInformationType> : IContactInformation
where TContactInformationType : struct, IConvertible
{


string Value { get; set; }


TContactInformationType? Type { get; set; }
}

[EntityInterface(EntityKey = "*")]
public interface IAuditFields
{
public Guid? ModifiedById { get; set; }
public Guid? CreatedById { get; set; }
public DateTime? CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
public byte[] RowVersion { get; set; }
}
}

0 comments on commit 3f3c414

Please sign in to comment.