algorithmic modeling for Rhino
My class was derived from IGH_Goo.
public bool CastTo<T>(out T target)
{
if (typeof(T).IsAssignableFrom(typeof(int))) {
object ptr = this.data;
target = (T)ptr;
return true;
}
return false; // <- error
}
Throws this error.
Error : The Out Parameter must be assigned before control leaves the current method.
Older IGH_Goo interface has CastTo<T>(ref T target) instead of out.
Tags:
If the method doesn't end up in your if-statement the variable "target" will never be assigned. This is a requirement when using out-parameters. Setting "target" to null in an else-scope might be working. Something like this:
public bool CastTo<T>(out T target)
{
if (typeof(T).IsAssignableFrom(typeof(int))) {
object ptr = this.data;
target = (T)ptr;
return true;
}
else{
target = null;
return false; // <- error
}
}
target = null;
won't work because T may be a value type. You should use:
target = default(T);
--
David Rutten
david@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by