Skip to content

ConstructObjectInitializer cannot be used if the generic parameter T is a base type #100

@TonyTroeff

Description

@TonyTroeff

Describe the bug
I have the following code:

public interface IEntity { }
public class Entity<T> : IEntity { }

var entityType = typeof(Entity<>).MakeGenericType(typeof(int));
var constructor = entityType.GetConstructor(Type.EmptyTypes);

var initializer = constructor!.ConstructObjectInitializer<IEntity>();

An exception will always be thrown saying that the constructor was obtained from a different type.

Expected behavior
I want the generated expression to be typed according to the known base type.

Environment (please complete the following information):

  • OS: Windows 11
  • .NET Version: .NET 7
  • Package Version: 1.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions