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?

  • What's the output from the Console.WriteLine() calls? – Javi Mollá Jul 27 '10 at 9:50
  • I don't think we should be using tags for specific interfaces... that would get messy real quick. – JasonBirch Aug 13 '10 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 – Herb Sep 1 '10 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 Sep 1 '10 at 12:49
  • Neat. So ESRI's documentation is ... off. Righty-ho. Off to the compiler I go, then. – Herb Sep 1 '10 at 14:17
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.