1

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 26, 2010 at 17:36
7
  • What's the output from the Console.WriteLine() calls? Commented Jul 27, 2010 at 9:50
  • I don't think we should be using tags for specific interfaces... that would get messy real quick. Commented 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 documentation Commented 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. Commented Sep 1, 2010 at 12:49
  • Neat. So ESRI's documentation is ... off. Righty-ho. Off to the compiler I go, then. Commented Sep 1, 2010 at 14:17

1 Answer 1

2

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.

answered Sep 1, 2010 at 15:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.