我有以下幾種類型:如何區分達特種
class AddressEditor extends TextEditor {}
class TypeEditor extends TextEditor {}
我試圖找出編輯是這樣:如果我用鏡子
import 'dart:mirrors';
getTypeName(dynamic obj)
{
return reflect(obj).type.reflectedType.toString();
}
void validationErrorHandler(ValidationError e)
{
var editor = e.editor;
if(editor is AddressEditor)
print(getTypeName(editor)) // prints TextEditor
if(editor is TypeEditor)
print(getTypeName(editor)) // prints TextEditor
}
void validationErrorHandler(ValidationError e)
{
var editor = e.editor;
if(editor is AddressEditor)
print(editor.runtimeType.toString()) // prints TextEditor
if(editor is TypeEditor)
print(editor.runtimeType.toString()) // prints TextEditor
}
爲什麼編輯器類型爲TypeEditor
和AddressEditor
沒有被識別?是的,我知道要麼是TextEditor
,但有什麼方法可以確定Dart中的TypeEditor
或AddressEditor
。
我需要使這些標識與驗證的結果一起工作。
感謝
如果你需要編譯你r代碼轉換爲JavaScript,不要使用dart:鏡像,除非您確定輸出非常大。 – 2014-09-05 02:23:27
謝謝賽斯。但我非常渴望不惜一切代價尋找解決方案。 – 2014-09-05 10:54:05