ValidElements プロパティは、ポインターが指し示す配列またはバッファーについて、正常に読み取ることのできる要素数を指定します。 このプロパティは Pre 属性および Post 属性で使用でき、ポインター型または配列データ型に対して使用できます。 このプロパティの値は別のパラメーターを含む式であり、このパラメーターは実際の有効な要素数を指定します。
使用例
ValidElements プロパティの使用例を次のコードに示します。
// C
#include <CodeAnalysis\SourceAnnotations.h>
void f([SA_Pre(ValidElements="count") ] char *pc, size_t count);
// The keyword 'return' is used to indicate the return value,
// which in this case is the number of valid elements.
[returnvalue:SA_Post(MustCheck=SA_Yes)]int f([SA_Post(ValidElements="return")] char *pc);
// C++
#include <CodeAnalysis\SourceAnnotations.h>
using namespace vc_attributes;
void f([Pre(ValidElements="count") ] char *pc, size_t count);
// The keyword 'return' is used to indicate the return value,
// which in this case is the number of valid elements.
[returnvalue:Post(MustCheck=Yes)]int f([Post(ValidElements="return")] char *pc);