Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Namespace mapping not working #12

Closed
leorg99 opened this issue Dec 3, 2015 · 2 comments
Closed

Namespace mapping not working #12

leorg99 opened this issue Dec 3, 2015 · 2 comments

Comments

@leorg99
Copy link

leorg99 commented Dec 3, 2015

It appears that you always get a generated .net namspace even when you call the program with the -n parameter. I have been able to deduce it to the following code:

    public bool TryGetValue(NamespaceKey key, out string value)
    {
        if (InternalDictionary.TryGetValue(key, out value))
            return true;
        if (!TryGenerateNamespace(key, out value))
            return false;
        InternalDictionary.Add(key, value);
        return true;
    }

I don't believe that InternalDictionary.TryGetValue will ever succeed here because the NamespaceKey object passed through the "key" argument is a different instance from the one already in the collection. I have also found that the NamespaceKey:Source is populated with the full path to the xsd file in the "key" object. However since including the filename with the -n command line parameter appears to be optional, the NamespaceKey:Source properties of the two instances will not match. This will also occur if you do not specify the full path to the filename. I believe what you meant to do here is compare the NameSpaceKey:XmlSchemaNamespace properties for a match.

@leorg99
Copy link
Author

leorg99 commented Dec 3, 2015

Another issue that I am finding is that when one schema imports another schema via the <import> tag, it doesn't seem that the class generator is adding a using clause to the imported schema. For example, if A.xsd imports B.xsd and A.xsd maps to a .NET namespace of Foo.A and B.xsd maps to Foo.B, then when you generate the class A.cs, there should be a using Foo.B; statement.

@mganss mganss closed this as completed in f72c936 Dec 3, 2015
@mganss
Copy link
Owner

mganss commented Dec 3, 2015

Thanks for reporting this. The problem wasn't that the InternalDictionary.TryGetValue() never succeeded because NamespaceKey overrides Equals() and thus doesn't test only for instance equality. It was rather in the method FindNamespace() which checks several possible matches. If the first one didn't succeed it always automatically generated a namespace without checking the other alternatives.

The using clause is not necessary since references to classes in other namespaces are always fully qualified. This is automatically done by the CodeDomProvider which generates the code. If you know a way to make it generate usings instead of always fully qualifying type names (without adding ambiguities if names are the same across namespaces), a PR would be very welcome 😄

mganss pushed a commit that referenced this issue Dec 4, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants