What happens if GetInputValue() returns an integer and the port has a type T that is a float?
What value is returned by this method?
Answer:
The returned value is `0` (and always and only `0`) because `integer is not float` and thus the check is False and the default value is returned. However, one would expect that an integer *can* be cast to a float, returning `(T)obj` instead.
~~The correct line on 157 should be `return obj != null && obj.GetType().IsInstanceOfType(typeof(T)) ? (T)obj : default(T);`~~
I get this part wrong all the time. I *meant* `IsAssignableFrom` but that doesn't actually work here either. Had to do this:
```csharp
public T GetInputValue() {
object obj = GetInputValue();
if (typeof(IConvertible).IsAssignableFrom(typeof(T)) && obj is IConvertible)
{
return (T)Convert.ChangeType(obj, typeof(T));
}
return obj is T ? (T)obj : default(T);
}
```
https://github.com/Siccity/xNode/blob/82f78879316817dc5c7f8703352f5660a22ec3d4/Scripts/NodePort.cs#L155-L158
What happens if
GetInputValue()
returns an integer and the port has a typeT
that is a float?What value is returned by this method?
Answer:
The returned value is `0` (and always and only `0`) because `integer is not float` and thus the check is False and the default value is returned. However, one would expect that an integer *can* be cast to a float, returning `(T)obj` instead. ~~The correct line on 157 should be `return obj != null && obj.GetType().IsInstanceOfType(typeof(T)) ? (T)obj : default(T);`~~ I get this part wrong all the time. I *meant* `IsAssignableFrom` but that doesn't actually work here either. Had to do this: ```csharp public T GetInputValue