I'm having some problems using IfieldChecker
.
I have this following code, which I'm trying to test permitted/not permitted fields, according to my workspace
public IEnumerable<IFieldError> GetFieldErrors()
{
IFieldChecker checker = new FieldCheckerClass();
IEnumFieldError fieldErrors = null;
checker.ValidateWorkspace = this.WorkspaceHandler.GetCurrentWorkspace;
checker.Validate(this.Fields,out fieldErrors,out this._ValidatedFields);
if (fieldErrors == null)
{
yield return null;
}
else
{
fieldErrors.Reset();
IFieldError fError = fieldErrors.Next();
while (fError != null)
{
// debug only
Console.WriteLine(fError.FieldIndex.ToString());
Console.WriteLine(fError.FieldError.ToString());
yield return fError;
fError = fieldErrors.Next();
}
}
yield break;
}
Heres the test
[TestMethod]
public void FieldBuilder_TestGetFieldErrors()
{
fBuilder = new FieldBuilder(this.wHandler);
fBuilder.AddField(name, alias, esriFieldType.esriFieldTypeBlob, length, doublePrecision, doubleScale, false, false, null,
false, null);
Assert.AreEqual(2, fBuilder.GetFieldErrors().Count());
}
In my opinion, this should yield 1. The test completes, and it gives me a green light, but it should fail, since I'm testing with a bunch of values (1, 2, etc.);
The workspace I'm creating is one on C:,円 therefore, should not allow a Blob field type.
Any ideas why this is working like this?
EDIT: I'm working under the premise that after setting the workspace, ArcObjects would take care of validating it and telling me which types of fields are permitted or not.
Example: FileSystemWorkspace - cannot have Blob field types;
Or, does IFieldChecker
does not work the way I'm thinking?
-
What's the output from the Console.WriteLine() calls?Javi Mollá– Javi Mollá2010年07月27日 09:50:41 +00:00Commented Jul 27, 2010 at 9:50
-
I don't think we should be using tags for specific interfaces... that would get messy real quick.JasonBirch– JasonBirch2010年08月13日 22:55:25 +00:00Commented Aug 13, 2010 at 22:55
-
Shouldn't those last couple of parameters to Validate be ref, not out? I'd have to gin up a test here to be sure, but this sort of thing has nailed me before. IFieldChecker.Validate documentationHerb– Herb2010年09月01日 12:07:39 +00:00Commented Sep 1, 2010 at 12:07
-
No, the type library importer turns it into "out". Anyway, in C#, you cannot freely interchange out and ref modifiers, using ref when the signature defines a parameter as out wouldn't even compile.Petr Krebs– Petr Krebs2010年09月01日 12:49:22 +00:00Commented Sep 1, 2010 at 12:49
-
Neat. So ESRI's documentation is ... off. Righty-ho. Off to the compiler I go, then.Herb– Herb2010年09月01日 14:17:32 +00:00Commented Sep 1, 2010 at 14:17
1 Answer 1
Short version is that the types are (apparently) not checked. I can get Validate to fail for a shapefile if I give it a long field name, or names with invalid characters, but not by giving a bad data type. The documentation does imply that it's only checking names as it states:
"The error codes are stored as a esriFieldNameErrorType." See esriFieldNameErrorType.
What's interesting is that when I feed it a esriFieldTypeBlob and call Validate, the field type gets changed to esriFieldTypeInteger, even though no error is thrown.
It's kind of implied by the other [out] parameter - "fixedFields". It's thoughtfully fixed your incorrect field definitions for you.