Görünümlerim için XAML kullanarak bir Xamarin.Forms uygulaması yazıyorum ve girdisi false
olan işin döndürülmesi gereken bir IValueConverter
yazmaya çalışıyorum Bu semantiklerin anlamlı olduğu türler için "boş" (dizeler/listeler/diziler/diziler/IEnumerables). Ben boş dizeleri için false döndüren aşağıdaki malzemeleri başladı ancak ben listeleri, diziler, diziler ve IEnumerables bu genişletmek için nasıl bilemiyorum:Herhangi bir liste, dizi, dizi veya IEnumerable boş olup olmadığını belirleme
type FalseIfEmptyConverter() =
interface IValueConverter with
member __.Convert(value:obj, _, _, _) =
match value with
| :? string as s -> (s <> "" && not (isNull s)) |> box
// TODO: extend to enumerables
| x -> invalidOp <| "unsupported type " + x.GetType().FullName
member __.ConvertBack(_, _, _, _) =
raise <| System.NotImplementedException()
şeyler denedim o don' t work:
:? list<_>
does not match bir (boxed) list (at least not of ints) ve produces bir warningThis construct causes code to be less generic than indicated by its type annotations. The type variable implied by the use of a '#', '_' or other type annotation at or near [...] has been constrained to be type 'obj'
:? list<obj>
does not produce the warning, but also does n't match bir boxed list of inrol- It 'Nin aynı
:? seq<_>
ve:? seq<obj>
Bu:? System.Collections.Generic.IEnumerable<obj>
veIEnumerable<_>
(aynı şey - ile ve yukarıda verildiği gibi ben de benzer
seq
maçın altına yerleştirin, eğer kural eşleşti AFAIKseq
tekabül beri mantıklı hangi asla konusunda uyarıyor kullanmak Sisli Finder'ın fikrini kullanarakIEnumerable
)
' ile eşleşme değeri | :? System.Collections.IEnumerable s -> s.GetEnumerator(). MoveNext() |> değil | x -> invalidOp <| "Desteklenmeyen tip" + x.GetType(). FullName' –