Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetInterfaces() returns generic interface type with FullName = null

Can anyone explain to me why GetInterfaces() in the below code returns an interface type that has FullName = null?

public class Program
{
    static void Main(string[] args)
    {
        Type[] interfaces = typeof (Data<>).GetInterfaces();
        foreach (Type @interface in interfaces)
        {
            Console.WriteLine("Name='{0}' FullName='{1}'", @interface.Name, @interface.FullName ?? "null");
        }
    }
}

public class Data<T> : IData<T>
{
    public T Content { get; set; }
}

public interface IData<T>
{
    T Content { get; set; }
}

The output of the program is:

Name=IData`1' FullName='null'

I kind of expected:

Name=IData`1'
FullName='ConsoleApplication2.IData`1'

Please enlighten me :)

like image 934
asgerhallas Avatar asked Jun 28 '26 21:06

asgerhallas


1 Answers

https://learn.microsoft.com/archive/blogs/haibo_luo/type-fullname-returns-null-when

Update: Microsoft documentation is improved:

https://msdn.microsoft.com/en-us/library/system.type.fullname.aspx

Type.FullName is null if the current instance represents a generic type parameter, an array type, pointer type, or byref type based on a type parameter, or a generic type that is not a generic type definition but contains unresolved type parameters.

Here is an example of a situation where Type.FullName is null, boiled down from the documentation:

    [Fact]
    public void FullNameOfUnresolvedGenericArgumentIsNull()
    {
        Type openGenericType = typeof(Nullable<>);
        Type typeOfUnresolvedGenericArgument = openGenericType.GetGenericArguments()[0];

        Assert.Null(typeOfUnresolvedGenericArgument.FullName);
    }
like image 62
Lars Udengaard Avatar answered Jun 30 '26 15:06

Lars Udengaard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!