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 :)
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With