1

私は、一部のスクリプトを C#.NET で記述できるようにする ABBYY Flexicapture に取り組んでいます。C#.NET を使用したことはありませんが、Java に十分近いので、問題なく使用できます。次のことをmethod示す宣言があります。

Document:
    Property (name: string) : VARIANT
        Description: Retrieves the value of a specified property by its name. The returned value can be in the form of a string, a number or time.
        Properties names and returned values: 
            Exported - when the document was exported 
            ExportedBy - who exported the document 
            Created - when the document was created 
            CreatedBy - who created the document 

したがって、「Exported By」の値を取得しようとしていますが、次の行のいずれかを試すとエラーが発生します。

string = Document.Property("CreatedBy"); // Returns Error: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?) (line 95, pos 21)
string = Document.Property(CreatedBy);  // Returns Error: Error: The name 'CreatedBy' does not exist in the current context (line 95, pos 39)
string = Document.Property("CreatedBy").Text; //Error: 'object' does not contain a definition for 'Text' (line 95, pos 52

私はVARIANT以前に使用されたのを見たことがありません、誰かが私にこれを説明できますか. 明らかな構文エラーがありませんか?

4

2 に答える 2

2

私は ABBYY Flexicapture に精通していませんが、当時 COM を実行したことがあり、VARIANT を多用していました。これは基本的に、文字列、数値、または日付のいずれかになる値の型です。

これは、引用した宣言で指定された説明と一致しているようです。

戻り値は、文字列、数値、または時間の形式にすることができます。

VARIANT は、javascript のような弱く型付けされた (スクリプト) 言語の変数に似ています。

詳細については、ウィキペディアを参照してください。

于 2012-07-03T15:43:58.693 に答える
1

バリアントは、実際には異なるタイプの「結合」です。これを表現する良い方法は、

object o = Document.Property("CreatedBy");

の正確なタイプを確認できるようになりましたo:

if (o is string)
{
    string s = (string)o;
    // work with string s
}
else if (o is int)
{
    int i = (int)o;
    // work with int i
}
// etc. for all possible actual types

または、オブジェクトを文字列表現 ( o.ToString()) に変換して操作することもできます。

于 2012-07-03T17:29:02.113 に答える