リフレクションインターフェイスでこれを行うことができます。ドキュメントで "rf_manager"を参照してください。すべてが文書化されていない、しかし...ここで
、私はフィールドbaz
の存在をテストしています:
struct foo {
bar : int;
};
struct baz {
};
extend sys {
run() is also {
var f : foo = new;
var rf_f : rf_struct = rf_manager.get_exact_subtype_of_instance(f);
var f_bar_field : rf_field = rf_f.get_field("bar");
if f_bar_field != NULL {
message(NONE,"struct 'foo' has a field called 'bar'");
} else {
message(NONE,"struct 'foo' doesn't have a field called 'bar'");
};
var b : baz = new;
var rf_b : rf_struct = rf_manager.get_exact_subtype_of_instance(b);
var b_bar_field : rf_field = rf_b.get_field("bar");
if b_bar_field != NULL {
message(NONE,"struct 'baz' has a field called 'bar'");
} else {
message(NONE,"struct 'baz' doesn't have a field called 'bar'");
};
};
};
あなたがフィールドを反復処理する必要がある場合はこれが
[...]
Starting the test ...
Running the test ...
[0] [email protected]: struct 'foo' has a field called 'bar'
[0] [email protected]: struct 'baz' doesn't have a field called 'bar'
を生み出します、do:
rf_manager.get_exact_subtype_of_instance(whatever).get_declared_fields()