Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
What's the output from the Console.WriteLine() calls? –  billmuell 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
    
no problem jason :P –  George Aug 14 '10 at 22:07
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
    
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
    
Herb, ESRIs docs says ref, but Intellisense says out. So I stuck with Intellisense :P –  George Sep 1 '10 at 15:33
    
Yep. And as @petr_k mentions, the compiler won't allow it. And it was a red herring anyway - the real issue is what Validate claims it might do vs. what it really does.... –  Herb Sep 1 '10 at 16:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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