It looks like what you need is the Proxy functionality.

For example, if I have the following type in C#:

1
2
3
4
5
6
7
8
9
class Example
{
    public Example(int property)
    {
	Property = property;
    }

    public int Property { get; private set; }
}

then I can write a new type ExampleProxy in F# and mark it as a proxy for Example:

1
2
3
4
5
6
7
8
9
10
open IntelliFactory.WebSharper

[<Proxy(typeof<Example>)>]
type ExampleProxy [<JavaScript>] (p: int) =

    let mutable property = p

    member this.Property
        with [<JavaScript>] get() = property
        and [<JavaScript>] private set v = property <- v

This way, when WebSharper tries to translate a call to a constructor or method of the class Example, it will use the corresponding method from ExampleProxy instead:

1
2
3
4
5
6
7
8
9
10
module Test =

    [<JavaScript>]
    let f() =

        // in JS, the constructor for ExampleProxy is called
        let ex = new Example(12)

        // same here, ExampleProxy.Property getter is called
        ex.Property

The error messages you show here seem to be about something else, though; it looks like your C# library depends on some assemblies and your WebSharper project needs to reference them as well.

By on 6/27/2013 1:55 PM ()

Thank you. The thing is, using a type from the portable lib only fails when I reference Websharper targets.
Basically Websharper fails as soon as I reference the portable c# project.
I'm using the latest Alpha 2.5.x from Nuget. I should probably put up a sample...
A question, can I also use the "Example" type without a proxie, when I only want to access some properties (doesn't need to generate a js function type, can be an anonymous object)?

By on 6/29/2013 6:58 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper