Test validity of input for number does not differentiate between Points and numbers!

I created a test for validity of number, but when I connect a Point to it. It does not give the false output for it. Any idea why?
Here is the Code:

private void RunScript(double x, ref object A)
  {

    if (RhinoMath.IsValidDouble(x))
    {
      Print("All Good");
    }
    else
    {
      Print("Please Provide number");
    }

Here is the output on Grasshopper canvas:
image

Grasshopper implicitly converts GH_Point to double, When you select double type hint for your input.


You can check whether the input data can directly be converted to double or not, but first, you need to deactivate grasshopper implicit data conversion by selecting System.Object type hint.

private void RunScript(object x, ref object A)
  {
    A = x is double;
  }


NumberOrNot.gh (13.8 KB)

Thanks! That was really helpful.

@Mahdiyar In relation to the problem, How do we test the same condition in visual studio?

Here is the Code Snippet:
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter(“Number”, “Number”, “Number”, GH_ParamAccess.tree);
}

    /// <summary>
    /// Registers all the output parameters for this component.
    /// </summary>
    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddGenericParameter("Output Number", "Output Number", "Output Number", GH_ParamAccess.tree);
    }

    /// <summary>
    /// This is the method that actually does the work.
    /// </summary>
    /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
    protected override void SolveInstance(IGH_DataAccess DA)
    {
        DA.GetDataTree(0, out GH_Structure<IGH_Goo> myInputs);

        Type typeInformation = myInputs.GetType();

        if (typeInformation == typeof(double))
        {
            DA.SetDataTree(0, myInputs);
        }
        else
        {
            AddRuntimeMessage(GH_RuntimeMessageLevel.Error,"Please Provide Number");
        }

But for some reason when I connect input for numbers, it still gives only error.

As far as I know, you need to check each item in your tree like this:

    protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
    {
        pManager.AddGenericParameter("input", "input", "input", GH_ParamAccess.tree);
    }
    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
    {
        pManager.AddBooleanParameter("isNumber", "isNumber", "isNumber", GH_ParamAccess.item);
    }
    protected override void SolveInstance(IGH_DataAccess DA)
    {
        DA.GetDataTree(0, out GH_Structure<IGH_Goo> inputs);
        var isNumber = inputs.AllData(true).All(input => input is GH_Number);
        DA.SetData(0, isNumber);
    }

NumberOrNot.zip (22.6 KB)

Oh! I was hoping that maybe one can check the incoming Data Structure Type. But I guess this works fine as well.