Skip to content

Generic class with itself as argument of base type equality problem #119

@Xriuk

Description

@Xriuk

Hello, I don't know if I'm missing something here (about your library or Roslyn), but until know I had compared all class types by equality:

classType1 = // some code which returns IClass

classType2 = // some other code which returns IClass

if classType1 == classType2
    }} same {{
end

However if I have a class like this in C#:

public class Base<T>{}

public class Derived : Base<Derived>{}

This does not work:

classType = // some code which returns IClass = Derived

if classType.BaseType.IsGeneric && classType.BaseType.TypeArguments[0] == classType
    }} same {{
end

So apparently Derived and its parent generic argument Derived are different types, why?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions