public static object readArbitraryResult(IKernelLink ml, GH_Component component) { Object exprOrObjectResult = null; ILinkMark mark = ml.CreateMark(); try { exprOrObjectResult = ml.GetObject(); } catch (MathLinkException) { ml.ClearError(); ml.SeekMark(mark); // Technically, GetExpr() should never throw MathLinkException. But there was at least one bug I found and fixed where it did. // So to be safe we leave this try/catch here, otherwise the link will get in a bad state. try { Expr ex = ml.GetExpr(); exprOrObjectResult = new ExprType(ex); } catch (MathLinkException) { ml.ClearError(); component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error reading result as an Expr. This is a bug in RhinoLink, not the user program."); } } finally { ml.DestroyMark(mark); ml.NewPacket(); } return(exprOrObjectResult); }
private static object ReadSingleItemAsType(string type, IKernelLink link) { object res = null; switch (type) { case "Text": { res = link.GetString(); break; } case "Integer": { res = link.GetInteger(); break; } case "Number": { res = link.GetDouble(); break; } case "Boolean": { res = link.GetBoolean(); break; } case "Any": { res = ReadAsAny(link); break; } case "Expr": { res = new ExprType(link.GetExpr()); break; } } return(res); }
// Copy Constructor public ExprType(ExprType source) { Value = source.Value; }