slavniyteo / one-line

One line property drawer for Unity3d
MIT License
146 stars 12 forks source link

Using inheritance and generics cause index out of range exception. #12

Closed SKlimkov closed 6 years ago

SKlimkov commented 6 years ago

For example i have an abstract generic class A and inherited non-generic class B.

public abstract class A<TValue> 
{ 
    [OneLine]
    public List<TValue> List; 
}

public class B : A<ConreteValue> 
{ 
}

This case cause Index out of range exception for SerializedPropertyExtension in 104 line. You will replace

type = type.GetGenericArguments()[0];

for

if (type.GetGenericArguments().Length == 0)
{                            
    var baseType = type.BaseType;
    type = baseType.GetGenericArguments()[0];
}
else
{
    type = type.GetGenericArguments()[0];
} 

for fix it.

slavniyteo commented 6 years ago

Thank you for this bug report. I edited issue text to make it more readable.

I will fix it soon.

slavniyteo commented 6 years ago

This is more complex bug based on wrong BindingFlags passed into type.GetField.

Your solution with type.BaseType works only in this custom case. But If your have the same classes A and B but whithout any generic behaviour, but is still here:

public abstract class A
{ 
    [OneLine]
    public List<Vector2> List; 
}

public class B : A
{ 
}

Now, in e3f3297 it is fully fixed.