C # static method call from F #

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 am trying to call from F # to find out how to do a test with this language, but:

namespace StraussGlassTest

open System

module MeshTesting =
    open StrassGlassLib

    let m = Mesh.CreatePlanarMesh()

Problems:

  • I have error FS0039: the namespace or module "Mesh" is not defined.
  • There is no error on the console, the code looks good
  • If I try to access the Nodes property, I get error FS0039: field, constructor or member 'Nodes' not defined

I guess I miss more than something about how F # works, do you have any tips?

+4
source share
1 answer

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 also this

+3
source

Source: https://habr.com/ru/post/1689184/


All Articles