F # upcasting TextBlock for UIElement

What's wrong:

let (x:UIElement) = upcast new TextBlock()

Error: type "System.ComponentModel.ISupportInitialize" is required and not available here. You must add a link to the assembly "System, Version = 4.0.0 ...."

TextBlockis a subtype UIElement...

Note that running the error message solves the problem, but why is it necessary to do something the same as raising it?

+3
source share
2 answers

As lasseespeholt mentions in his (now deleted) answer, there is nothing wrong with the code, and you just need to add a link to System.dllhow this suggests an error message.

? , , - System.dll ( ISupportInitialize, TextBlock), , , .

- :

let x = new TextBlock() 
x.  // If you get IntelliSense here, you'll see just '<Note>' 
    // with the same error message as the one you're getting

IntelliSense ( ).

+8

:

" - , F # : , , upcasting , . . (F #)."

:

let (x:#UIElement) = new TextBlock()

( #), . :

" , , . '#', '_' 'c:\path\Program. fs ' " TextBlock".

-3

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


All Articles