How to expose types generated by a Provider of type F # in C # and XAML

So, I'm using an XML type provider to create types from an XML document.

One of the elements of the XML file has the property Date:

<Edit Date="06/30/2015 16:57:46"
      ... />

Which of course leads to a type like this:

type Edit = 
    inherit XmlElement

    member Date:  DateTime
    ...

Is there any way to add the following code:

 member this.LocalTime
    with get() =
        this.Date.ToLocalTime()

To the resulting type Edit?

The reason for this is because I bind to instances Editfrom XAML, and I really don't want to write IValueConverterjust for that.

Edit:

So, I just realized that these types do not fall into my XAML. Instead, I get instances FSharp.Data.Runtime.BaseTypes.XmlElementthat, of course, do not even contain the properties that I see in F # code. I also need to use these types from C # code, and even there I only get XmlElementwithout properties

, XPath XAML XElements , , #, XAML.

Edit2:

, Type Extension :

type Catalog.Edit with
    member this.LocalTime with get() = this.Date.ToLocalTime()

F # , . :

1 - namespace module, , #, , .

2 - ( ) # XAML.

?

+4
1

F # XML JSON - . , , , F #, - ( XmlElement).

, , , F #.

- F # XML . , , - , XML , , XAML!

, - :

type Edit = { Date : DateTime }

let GetData () = 
  let doc = MyXmlType.Load("somefile.xml")
  seq { for item in doc.Edits -> { Date = item.Date } }
+6
source

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


All Articles