You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tested and the PrivatAssets works. But omitting the namespace declaration dosn't work, because then the generated partial class is in the global namespace and this is not the same as the original namespace.
But I think I've found the solution 😀
During my tests I noticed that the problem only occurs, if I used file scoped namespaces. If I changed my code to use block-scoped namespaces all went fine. So I looked in TypeDefinitionExtractor.GetNamespace() and found the following line:
// determine the namespace the class/enum/struct is declared in, if anystaticstringGetNamespace(BaseTypeDeclarationSyntaxsyntax){// If we don't have a namespace at all we'll return an empty string// This accounts for the "default namespace" casestringnameSpace=string.Empty;// Get the containing syntax node for the type declaration// (could be a nested type, for example)SyntaxNode?potentialNamespaceParent=syntax.Parent;// Keep moving "out" of nested classes etc until we get to a namespace// or until we run out of parentswhile(potentialNamespaceParent!=null&&potentialNamespaceParentis not NamespaceDeclarationSyntax&&potentialNamespaceParentis not FileScopedNamespaceDeclarationSyntax){potentialNamespaceParent=potentialNamespaceParent.Parent;}// Build up the final namespace by looping until we no longer have a namespace declarationif(potentialNamespaceParentisBaseNamespaceDeclarationSyntaxnamespaceParent){// We have a namespace. Use that as the typenameSpace=namespaceParent.Name.ToString();// Keep moving "out" of the namespace declarations until we // run out of nested namespace declarationswhile(true){if(namespaceParent.Parentis not NamespaceDeclarationSyntaxparent){break;}// Add the outer namespace as a prefix to the final namespacenameSpace=$"{namespaceParent.Name}.{nameSpace}";namespaceParent=parent;}}// return the final namespacereturnnameSpace;}
This will fix it. Same method must be changed in TypeDefinitionExtractor in the project AutoSerialization.
Originally posted by @jensbrand in #4446
The text was updated successfully, but these errors were encountered: