Calling C# static method from F#

Viewed 906

I have this class in C#:

using System.Collections.Generic;

namespace StrassGlassLib
{
    public class Mesh
    {
        private List<Model.Node> _ns;
        private List<Model.Plate> _ps;

        public Mesh()
        {
            _ns = new List<Model.Node>();
            _ps = new List<Model.Plate>();
        }

        public List<Model.Node> Nodes => _ns;

        public List<Model.Plate> Plates => _ps;

        public void AddNode(Model.Node n)
        {
            _ns.Add(n);
        }

        public void AddPlate(Model.Plate p)
        {
            _ps.Add(p);
        }

        // CREATION METHOD
        public static Mesh CreatePlanarMesh()
        {
            // create new mesh
            Mesh m = new Mesh();
            // add node
            for (int y = 0; y < 2; y += 1)
            {
                for (int x = 0; x < 4; x += 1)
                {
                    m.AddNode(new Model.Node(0, x, y, 0.0));
                }
            }

            return m;
        }
    }
}

I'm trying to call from F# to learn how to make test with this language, but:

namespace StraussGlassTest

open System

module MeshTesting =
    open StrassGlassLib

    let m = Mesh.CreatePlanarMesh()

The problems are:

  • I've got error FS0039: The namespace or module 'Mesh' is not defined.
  • No error on the console, the code looks good
  • if I try to access to Nodes property I've got error FS0039: The field, constructor or member 'Nodes' is not defined

I imagine i miss more than something on how F# works, Do you have some hints?

1 Answers

ok the problem was the interactive part

#if INTERACTIVE
#r @"C:\Users\p.cappelletto\Documents\Visual Studio 2015\Projects\StraussGlass\StraussGlassLib\bin\Debug\StraussGlassLib.dll"
#r @"C:\Users\p.cappelletto\Documents\Visual Studio 2015\Projects\StraussGlass\StraussGlassLib\bin\Debug\StrausLib.dll"   
#endif

namespace StraussGlassTest

open System

module MeshTesting =
    open StraussGlassLib
    open StrausLib

    let m = Mesh.CreatePlanarMesh()
    printfn "%A" m.Nodes.Count

Now it works, see it also this

Related