How to expose types generated by an F# Type Provider to C# and XAML -
so, i'm using xml type provider create types xml document.
one of elements in xml file has date
property:
<edit date="06/30/2015 16:57:46" ... />
which of course results in type this:
type edit = inherit xmlelement member date: datetime ...
is there way can add following code:
member this.localtime get() = this.date.tolocaltime()
to resulting edit
type?
the reason i'm binding instances of edit
xaml , don't want write ivalueconverter
that.
edit:
so, realized these types not make xaml. instead, instances of fsharp.data.runtime.basetypes.xmlelement
of course not contain properties see in f# code. need consume these types c# code, , there xmlelement
s without properties
i know use xpath in xaml navigate xelements inside this, still need way access resulting object model in typed way, both c# , xaml.
edit2:
so wrote type extension this:
type catalog.edit member this.localtime get() = this.date.tolocaltime()
and see member in f# code generated members. there's 2 drawbacks approach:
1 - forced me change namespace
module
, less convenient since these types consumed c# code , in there see them nested classes module class, ugly.
2 - still can't see member (nor generated ones) either c# nor xaml.
what's correct way implement in described scenario?
the f# data type providers xml , json erasing type providers. means types see when use them f# not exist @ runtime - replaced underlying runtime representation (here xmlelement
).
unfortunately, means types not real types , visible f#.
my recommendation define simple domain type using f# records , load data xml records. bit more work, gives bit more safety, because explicitly defining structure - , if xml changes, you'll know need change xaml code too!
it should easy this:
type edit = { date : datetime } let getdata () = let doc = myxmltype.load("somefile.xml") seq { item in doc.edits -> { date = item.date } }
Comments
Post a Comment