internal static string CreateManifestNameImpl
        (
            string fileName,
            string linkFileName,
            bool prependCultureAsDirectory, // true by default
            string rootNamespace,           // May be null
            string dependentUponFileName,   // May be null
            string culture,
            Stream binaryStream,            // File contents binary stream, may be null
            TaskLoggingHelper log,
            bool treatAsCultureNeutral = false
        )
        {
            // Use the link file name if there is one, otherwise, fall back to file name.
            string embeddedFileName = linkFileName;

            if (string.IsNullOrEmpty(embeddedFileName))
            {
                embeddedFileName = fileName;
            }

            Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName, treatAsCultureNeutral);

            // If the item has a culture override, respect that.
            if (!string.IsNullOrEmpty(culture))
            {
                info.culture = culture;
            }

            var manifestName = StringBuilderCache.Acquire();

            if (binaryStream != null)
            {
                // Resource depends on a form. Now, get the form's class name fully
                // qualified with a namespace.
                ExtractedClassName result = VisualBasicParserUtilities.GetFirstClassNameFullyQualified(binaryStream);

                if (result.IsInsideConditionalBlock)
                {
                    log?.LogWarningWithCodeFromResources("CreateManifestResourceName.DefinitionFoundWithinConditionalDirective", dependentUponFileName, embeddedFileName);
                }

                if (!string.IsNullOrEmpty(result.Name))
                {
                    if (!string.IsNullOrEmpty(rootNamespace))
                    {
                        manifestName.Append(rootNamespace).Append('.');
                    }

                    manifestName.Append(result.Name);


                    // Append the culture if there is one.
                    if (!string.IsNullOrEmpty(info.culture))
                    {
                        manifestName.Append('.').Append(info.culture);
                    }
                }
            }

            // If there's no manifest name at this point, then fall back to using the
            // RootNamespace+Base file name
            if (manifestName.Length == 0)
            {
                // If Rootnamespace was null, then it wasn't set from the project resourceFile.
                // Empty namespaces are allowed.
                if (!string.IsNullOrEmpty(rootNamespace))
                {
                    manifestName.Append(rootNamespace).Append('.');
                }

                // only strip extension for .resx and .restext files
                string sourceExtension = Path.GetExtension(info.cultureNeutralFilename);
                if (
                    string.Equals(sourceExtension, resxFileExtension, StringComparison.OrdinalIgnoreCase)
                    ||
                    string.Equals(sourceExtension, restextFileExtension, StringComparison.OrdinalIgnoreCase)
                    ||
                    string.Equals(sourceExtension, resourcesFileExtension, StringComparison.OrdinalIgnoreCase)
                    )
                {
                    manifestName.Append(Path.GetFileNameWithoutExtension(info.cultureNeutralFilename));

                    // Append the culture if there is one.
                    if (!string.IsNullOrEmpty(info.culture))
                    {
                        manifestName.Append('.').Append(info.culture);
                    }

                    // If the original extension was .resources, add it back
                    if (string.Equals(sourceExtension, resourcesFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        manifestName.Append(sourceExtension);
                    }
                }
                else
                {
                    manifestName.Append(Path.GetFileName(info.cultureNeutralFilename));

                    if (prependCultureAsDirectory)
                    {
                        // Prepend the culture as a subdirectory if there is one.
                        if (!string.IsNullOrEmpty(info.culture))
                        {
                            manifestName.Insert(0, Path.DirectorySeparatorChar);
                            manifestName.Insert(0, info.culture);
                        }
                    }
                }
            }

            return(StringBuilderCache.GetStringAndRelease(manifestName));
        }
Beispiel #2
0
        private static ExtractedClassName Extract(CSharpTokenizer tokens)
        {
            ParseState         state = new ParseState();
            ExtractedClassName name  = new ExtractedClassName();

            foreach (Token token in tokens)
            {
                if (token is KeywordToken)
                {
                    state.Reset();
                    if (token.InnerText == "namespace")
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            name.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (token.InnerText == "class")
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            name.IsInsideConditionalBlock = true;
                        }
                    }
                }
                else if (token is CSharpTokenizer.OpenScopeToken)
                {
                    state.PushNamespacePart(state.Namespace);
                    state.Reset();
                }
                else if (token is CSharpTokenizer.CloseScopeToken)
                {
                    state.Reset();
                    state.PopNamespacePart();
                }
                else if (token is OperatorOrPunctuatorToken)
                {
                    if (state.ResolvingNamespace && (token.InnerText == "."))
                    {
                        state.Namespace = state.Namespace + ".";
                    }
                }
                else if (token is IdentifierToken)
                {
                    if (!state.ResolvingNamespace)
                    {
                        if (state.ResolvingClass)
                        {
                            name.Name = state.ComposeQualifiedClassName(token.InnerText);
                            return(name);
                        }
                    }
                    else
                    {
                        state.Namespace = state.Namespace + token.InnerText;
                    }
                }
                else if (token is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (token is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }
            return(name);
        }
Beispiel #3
0
        /// <summary>
        /// Extract the class name.
        /// </summary>
        private static ExtractedClassName Extract(CSharpTokenizer tokens)
        {
            var state  = new ParseState();
            var result = new ExtractedClassName();

            foreach (Token t in tokens)
            {
                // Search first for the namespace keyword
                if (t is KeywordToken)
                {
                    state.Reset();

                    if (t.InnerText == "namespace")
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.InnerText == "class")
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                }
                else if (t is CSharpTokenizer.OpenScopeToken)
                {
                    state.PushNamespacePart(state.Namespace);
                    state.Reset();
                }
                else if (t is CSharpTokenizer.CloseScopeToken)
                {
                    state.Reset();
                    state.PopNamespacePart();
                }
                else if (t is OperatorOrPunctuatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        if (t.InnerText == ".")
                        {
                            state.Namespace += ".";
                        }
                    }
                }
                else if (t is IdentifierToken)
                {
                    // If we're resolving a namespace, then this is part of the namespace.
                    if (state.ResolvingNamespace)
                    {
                        state.Namespace += t.InnerText;
                    }
                    // If we're resolving a class, then we're done. We found the class name.
                    else if (state.ResolvingClass)
                    {
                        // We're done.
                        result.Name = state.ComposeQualifiedClassName(t.InnerText);
                        return(result);
                    }
                }
                else if (t is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (t is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Extract the class name.
        /// </summary>
        private static ExtractedClassName Extract(CSharpTokenizer tokens)
        {
            var state  = new ParseState();
            var result = new ExtractedClassName();

            foreach (Token t in tokens)
            {
                // Search first for the namespace keyword
                if (t is KeywordToken)
                {
                    state.Reset();

                    if (t.InnerText == "namespace")
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.InnerText == "class")
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                }
                else if (t is CSharpTokenizer.OpenScopeToken)
                {
                    state.PushNamespacePart(state.Namespace);
                    state.Reset();
                }
                else if (t is CSharpTokenizer.CloseScopeToken)
                {
                    state.Reset();
                    state.PopNamespacePart();
                }
                else if (t is OperatorOrPunctuatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        // If we see a ';' while resolving a namespace, we assume it's a file-scoped namespace
                        // namespace foo.bar; <- At this point in code, we're at the semicolon.
                        // class test { ... }
                        // https://github.com/dotnet/csharplang/blob/088f20b6f9b714a7b68f6d792d54def0f3b3057e/proposals/csharp-10.0/file-scoped-namespaces.md
                        if (t.InnerText == ";")
                        {
                            state.PushNamespacePart(state.Namespace);
                            state.Reset();
                        }
                        else if (t.InnerText == ".")
                        {
                            state.Namespace += ".";
                        }
                    }
                }
                else if (t is IdentifierToken)
                {
                    // If we're resolving a namespace, then this is part of the namespace.
                    if (state.ResolvingNamespace)
                    {
                        state.Namespace += t.InnerText;
                    }
                    // If we're resolving a class, then we're done. We found the class name.
                    else if (state.ResolvingClass)
                    {
                        // We're done.
                        result.Name = state.ComposeQualifiedClassName(t.InnerText);
                        return(result);
                    }
                }
                else if (t is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (t is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }

            return(result);
        }
        /// <summary>
        /// Utility function for creating a C#-style manifest name from
        /// a resource name. Note that this function attempts to emulate the
        /// Everret implementation of this code which can be found by searching for
        /// ComputeNonWFCResourceName() or ComputeWFCResourceName() in
        /// \vsproject\langproj\langbldmgrsite.cpp
        /// </summary>
        /// <param name="fileName">The file name of the dependent (usually a .resx)</param>
        /// <param name="linkFileName">The file name of the dependent (usually a .resx)</param>
        /// <param name="rootNamespace">The root namespace (usually from the project file). May be null</param>
        /// <param name="prependCultureAsDirectory">should the culture name be prepended to the manifest name as a path</param>
        /// <param name="dependentUponFileName">The file name of the parent of this dependency (usually a .cs file). May be null</param>
        /// <param name="culture">The override culture of this resource, if any</param>
        /// <param name="binaryStream">File contents binary stream, may be null</param>
        /// <param name="log">Task's TaskLoggingHelper, for logging warnings or errors</param>
        /// <returns>Returns the manifest name</returns>
        internal static string CreateManifestNameImpl
        (
            string fileName,
            string linkFileName,
            bool prependCultureAsDirectory, // true by default
            string rootNamespace,           // May be null
            string dependentUponFileName,   // May be null
            string culture,                 // may be null
            Stream binaryStream,            // File contents binary stream, may be null
            TaskLoggingHelper log
        )
        {
            // Use the link file name if there is one, otherwise, fall back to file name.
            string embeddedFileName = FileUtilities.FixFilePath(linkFileName);

            if (embeddedFileName == null || embeddedFileName.Length == 0)
            {
                embeddedFileName = FileUtilities.FixFilePath(fileName);
            }

            dependentUponFileName = FileUtilities.FixFilePath(dependentUponFileName);
            Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName);

            // If the item has a culture override, respect that.
            if (!String.IsNullOrEmpty(culture))
            {
                info.culture = culture;
            }

            StringBuilder manifestName = new StringBuilder();

            if (binaryStream != null)
            {
                // Resource depends on a form. Now, get the form's class name fully
                // qualified with a namespace.
                ExtractedClassName result = CSharpParserUtilities.GetFirstClassNameFullyQualified(binaryStream);

                if (result.IsInsideConditionalBlock && log != null)
                {
                    log.LogWarningWithCodeFromResources("CreateManifestResourceName.DefinitionFoundWithinConditionalDirective", dependentUponFileName, embeddedFileName);
                }

                if (result.Name != null && result.Name.Length > 0)
                {
                    manifestName.Append(result.Name);

                    // Append the culture if there is one.
                    if (info.culture != null && info.culture.Length > 0)
                    {
                        manifestName.Append(".").Append(info.culture);
                    }
                }
            }

            // If there's no manifest name at this point, then fall back to using the
            // RootNamespace+Filename_with_slashes_converted_to_dots
            if (manifestName.Length == 0)
            {
                // If Rootnamespace was null, then it wasn't set from the project resourceFile.
                // Empty namespaces are allowed.
                if ((rootNamespace != null) && (rootNamespace.Length > 0))
                {
                    manifestName.Append(rootNamespace).Append(".");
                }

                // Replace spaces in the directory name with underscores. Needed for compatibility with Everett.
                // Note that spaces in the file name itself are preserved.
                string everettCompatibleDirectoryName = CreateManifestResourceName.MakeValidEverettIdentifier(Path.GetDirectoryName(info.cultureNeutralFilename));

                // only strip extension for .resx and .restext files

                string sourceExtension = Path.GetExtension(info.cultureNeutralFilename);
                if (
                    (0 == String.Compare(sourceExtension, ".resx", StringComparison.OrdinalIgnoreCase))
                    ||
                    (0 == String.Compare(sourceExtension, ".restext", StringComparison.OrdinalIgnoreCase))
                    ||
                    (0 == String.Compare(sourceExtension, ".resources", StringComparison.OrdinalIgnoreCase))
                    )
                {
                    manifestName.Append(Path.Combine(everettCompatibleDirectoryName, Path.GetFileNameWithoutExtension(info.cultureNeutralFilename)));

                    // Replace all '\' with '.'
                    manifestName.Replace(Path.DirectorySeparatorChar, '.');
                    manifestName.Replace(Path.AltDirectorySeparatorChar, '.');

                    // Append the culture if there is one.
                    if (info.culture != null && info.culture.Length > 0)
                    {
                        manifestName.Append(".").Append(info.culture);
                    }

                    // If the original extension was .resources, add it back
                    if (String.Equals(sourceExtension, ".resources", StringComparison.OrdinalIgnoreCase))
                    {
                        manifestName.Append(sourceExtension);
                    }
                }
                else
                {
                    manifestName.Append(Path.Combine(everettCompatibleDirectoryName, Path.GetFileName(info.cultureNeutralFilename)));

                    // Replace all '\' with '.'
                    manifestName.Replace(Path.DirectorySeparatorChar, '.');
                    manifestName.Replace(Path.AltDirectorySeparatorChar, '.');

                    if (prependCultureAsDirectory)
                    {
                        // Prepend the culture as a subdirectory if there is one.
                        if (info.culture != null && info.culture.Length > 0)
                        {
                            manifestName.Insert(0, Path.DirectorySeparatorChar);
                            manifestName.Insert(0, info.culture);
                        }
                    }
                }
            }

            return(manifestName.ToString());
        }
Beispiel #6
0
        private static ExtractedClassName Extract(VisualBasicTokenizer tokens)
        {
            var state  = new ParseState();
            var result = new ExtractedClassName();

            foreach (Token t in tokens)
            {
                // Search first for keywords that we care about.
                if (t is KeywordToken)
                {
                    state.Reset();

                    if (t.EqualsIgnoreCase("namespace"))
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.EqualsIgnoreCase("class"))
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.EqualsIgnoreCase("end"))
                    {
                        state.PopNamespacePart();
                    }
                }
                else if (t is VisualBasicTokenizer.LineTerminatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        state.PushNamespacePart(state.Namespace);
                    }
                    state.Reset();
                }
                else if (t is VisualBasicTokenizer.SeparatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        if (t.InnerText == ".")
                        {
                            state.Namespace += ".";
                        }
                    }
                }
                else if (t is IdentifierToken)
                {
                    // If we're resolving a namespace, then this is part of the namespace.
                    if (state.ResolvingNamespace)
                    {
                        state.Namespace += t.InnerText;
                    }
                    // If we're resolving a class, then we're done. We found the class name.
                    else if (state.ResolvingClass)
                    {
                        // We're done.
                        result.Name = state.ComposeQualifiedClassName(t.InnerText);
                        return(result);
                    }
                }
                else if (t is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (t is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }

            return(result);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fileName">The file name of the dependent (usually a .resx)</param>
 /// <param name="binaryStream">File contents binary stream, may be null</param>
 /// <param name="log">Task's TaskLoggingHelper, for logging warnings or errors</param>
 /// <returns></returns>
 private static ExtractedClassName GetFirstClassNameFullyQualified(string fileName, Stream binaryStream,TaskLoggingHelper log)
 {
     Match m = null;
     string currentNamespace = "";
     ExtractedClassName name = new ExtractedClassName();
     int conditionalDepth = 0;
     StreamReader reader = new StreamReader(binaryStream, true); // let the reader determine the encoding
     var namespaces = new Stack<string>();
     while (! reader.EndOfStream)
     {
         var line = reader.ReadLine();
         // Does the line contain "CLASS"
         m = classRx.Match(line);
         if (m.Success)
         {
             name.Name = currentNamespace + m.Groups[1].Value;
             name.IsInsideConditionalBlock = conditionalDepth > 0;
             return name;
         }
         // Does the line contain "BEGIN NAMESPACE"
         m = namespaceBeginRx.Match(line);
         if (m.Success)
         {
             namespaces.Push(currentNamespace);
             currentNamespace = currentNamespace + (m.Groups[1].Value + ".");
         }
         // Does the line contain "END NAMESPACE"
         else if (namespaceEndRx.Match(line).Success)
         {
             if (namespaces.Count > 0)
             {
                 currentNamespace = namespaces.Pop();
             }
             else
             {
                 object[] messageArgs = new object[] { fileName };
                 log.LogError("CreateXSharpManifestResourceName: found 'END NAMESPACE' with no matching 'BEGIN NAMESPACE' in '{0}'", messageArgs);
             }
         }
         // Does the line contain "#IFDEF"
         else if (ifdefRx.Match(line).Success)
         {
             conditionalDepth++;
         }
         // Does the line contain "#ENDIF"
         else if (endifRx.Match(line).Success)
         {
             conditionalDepth--;
         }
     }
     return name;
 }
        /// <summary>
        /// Extract the class name.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        private static ExtractedClassName Extract(VisualBasicTokenizer tokens)
        {
            ParseState state = new ParseState();
            ExtractedClassName result = new ExtractedClassName();

            foreach (Token t in tokens)
            {
                // Search first for keywords that we care about.
                if (t is KeywordToken)
                {
                    state.Reset();

                    if (t.EqualsIgnoreCase("namespace"))
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.EqualsIgnoreCase("class"))
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.EqualsIgnoreCase("end"))
                    {
                        state.PopNamespacePart();
                    }
                }
                else if (t is VisualBasicTokenizer.LineTerminatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        state.PushNamespacePart(state.Namespace);
                    }
                    state.Reset();
                }
                else if (t is VisualBasicTokenizer.SeparatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        if (t.InnerText == ".")
                        {
                            state.Namespace += ".";
                        }
                    }
                }
                else if (t is IdentifierToken)
                {
                    // If we're resolving a namespace, then this is part of the namespace.
                    if (state.ResolvingNamespace)
                    {
                        state.Namespace += t.InnerText;
                    }
                    // If we're resolving a class, then we're done. We found the class name.
                    else if (state.ResolvingClass)
                    {
                        // We're done.
                        result.Name = state.ComposeQualifiedClassName(t.InnerText);
                        return result;
                    }
                }
                else if (t is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (t is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }

            return result;
        }
 private static ExtractedClassName Extract(CSharpTokenizer tokens)
 {
     ParseState state = new ParseState();
     ExtractedClassName name = new ExtractedClassName();
     foreach (Token token in tokens)
     {
         if (token is KeywordToken)
         {
             state.Reset();
             if (token.InnerText == "namespace")
             {
                 state.ResolvingNamespace = true;
                 if (state.InsideConditionalDirective)
                 {
                     name.IsInsideConditionalBlock = true;
                 }
             }
             else if (token.InnerText == "class")
             {
                 state.ResolvingClass = true;
                 if (state.InsideConditionalDirective)
                 {
                     name.IsInsideConditionalBlock = true;
                 }
             }
         }
         else if (token is CSharpTokenizer.OpenScopeToken)
         {
             state.PushNamespacePart(state.Namespace);
             state.Reset();
         }
         else if (token is CSharpTokenizer.CloseScopeToken)
         {
             state.Reset();
             state.PopNamespacePart();
         }
         else if (token is OperatorOrPunctuatorToken)
         {
             if (state.ResolvingNamespace && (token.InnerText == "."))
             {
                 state.Namespace = state.Namespace + ".";
             }
         }
         else if (token is IdentifierToken)
         {
             if (!state.ResolvingNamespace)
             {
                 if (state.ResolvingClass)
                 {
                     name.Name = state.ComposeQualifiedClassName(token.InnerText);
                     return name;
                 }
             }
             else
             {
                 state.Namespace = state.Namespace + token.InnerText;
             }
         }
         else if (token is OpenConditionalDirectiveToken)
         {
             state.OpenConditionalDirective();
         }
         else if (token is CloseConditionalDirectiveToken)
         {
             state.CloseConditionalDirective();
         }
     }
     return name;
 }
        internal static string CreateManifestNameImpl(string fileName, string linkFileName, bool prependCultureAsDirectory, string rootNamespace, string dependentUponFileName, Stream binaryStream, TaskLoggingHelper log)
        {
            string str = linkFileName;

            if ((str == null) || (str.Length == 0))
            {
                str = fileName;
            }
            Culture.ItemCultureInfo itemCultureInfo = Culture.GetItemCultureInfo(str, dependentUponFileName);
            StringBuilder           builder         = new StringBuilder();

            if (binaryStream != null)
            {
                ExtractedClassName firstClassNameFullyQualified = CSharpParserUtilities.GetFirstClassNameFullyQualified(binaryStream);
                if (firstClassNameFullyQualified.IsInsideConditionalBlock && (log != null))
                {
                    log.LogWarningWithCodeFromResources("CreateManifestResourceName.DefinitionFoundWithinConditionalDirective", new object[] { dependentUponFileName, str });
                }
                if ((firstClassNameFullyQualified.Name != null) && (firstClassNameFullyQualified.Name.Length > 0))
                {
                    builder.Append(firstClassNameFullyQualified.Name);
                    if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0))
                    {
                        builder.Append(".").Append(itemCultureInfo.culture);
                    }
                }
            }
            if (builder.Length == 0)
            {
                if ((rootNamespace != null) && (rootNamespace.Length > 0))
                {
                    builder.Append(rootNamespace).Append(".");
                }
                string str2      = CreateManifestResourceName.MakeValidEverettIdentifier(Path.GetDirectoryName(itemCultureInfo.cultureNeutralFilename));
                string extension = Path.GetExtension(itemCultureInfo.cultureNeutralFilename);
                if (((string.Compare(extension, ".resx", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(extension, ".restext", StringComparison.OrdinalIgnoreCase) == 0)) || (string.Compare(extension, ".resources", StringComparison.OrdinalIgnoreCase) == 0))
                {
                    builder.Append(Path.Combine(str2, Path.GetFileNameWithoutExtension(itemCultureInfo.cultureNeutralFilename)));
                    builder.Replace(Path.DirectorySeparatorChar, '.');
                    builder.Replace(Path.AltDirectorySeparatorChar, '.');
                    if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0))
                    {
                        builder.Append(".").Append(itemCultureInfo.culture);
                    }
                    if (string.Equals(extension, ".resources", StringComparison.OrdinalIgnoreCase))
                    {
                        builder.Append(extension);
                    }
                }
                else
                {
                    builder.Append(Path.Combine(str2, Path.GetFileName(itemCultureInfo.cultureNeutralFilename)));
                    builder.Replace(Path.DirectorySeparatorChar, '.');
                    builder.Replace(Path.AltDirectorySeparatorChar, '.');
                    if ((prependCultureAsDirectory && (itemCultureInfo.culture != null)) && (itemCultureInfo.culture.Length > 0))
                    {
                        builder.Insert(0, Path.DirectorySeparatorChar);
                        builder.Insert(0, itemCultureInfo.culture);
                    }
                }
            }
            return(builder.ToString());
        }
        private static ExtractedClassName Extract(VisualBasicTokenizer tokens)
        {
            ParseState         state = new ParseState();
            ExtractedClassName name  = new ExtractedClassName();

            foreach (Token token in tokens)
            {
                if (token is KeywordToken)
                {
                    state.Reset();
                    if (token.EqualsIgnoreCase("namespace"))
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            name.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (token.EqualsIgnoreCase("class"))
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            name.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (token.EqualsIgnoreCase("end"))
                    {
                        state.PopNamespacePart();
                    }
                }
                else if (token is VisualBasicTokenizer.LineTerminatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        state.PushNamespacePart(state.Namespace);
                    }
                    state.Reset();
                }
                else if (token is VisualBasicTokenizer.SeparatorToken)
                {
                    if (state.ResolvingNamespace && (token.InnerText == "."))
                    {
                        state.Namespace = state.Namespace + ".";
                    }
                }
                else if (token is IdentifierToken)
                {
                    if (!state.ResolvingNamespace)
                    {
                        if (state.ResolvingClass)
                        {
                            name.Name = state.ComposeQualifiedClassName(token.InnerText);
                            return(name);
                        }
                    }
                    else
                    {
                        state.Namespace = state.Namespace + token.InnerText;
                    }
                }
                else if (token is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (token is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }
            return(name);
        }
        /// <summary>
        /// Extract the class name.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        private static ExtractedClassName Extract(CSharpTokenizer tokens)
        {
            ParseState state = new ParseState();
            ExtractedClassName result = new ExtractedClassName();

            foreach (Token t in tokens)
            {
                // Search first for the namespace keyword
                if (t is KeywordToken)
                {
                    state.Reset();

                    if (t.InnerText == "namespace")
                    {
                        state.ResolvingNamespace = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                    else if (t.InnerText == "class")
                    {
                        state.ResolvingClass = true;
                        if (state.InsideConditionalDirective)
                        {
                            result.IsInsideConditionalBlock = true;
                        }
                    }
                }
                else if (t is CSharpTokenizer.OpenScopeToken)
                {
                    state.PushNamespacePart(state.Namespace);
                    state.Reset();
                }
                else if (t is CSharpTokenizer.CloseScopeToken)
                {
                    state.Reset();
                    state.PopNamespacePart();
                }
                else if (t is OperatorOrPunctuatorToken)
                {
                    if (state.ResolvingNamespace)
                    {
                        if (t.InnerText == ".")
                        {
                            state.Namespace += ".";
                        }
                    }
                }
                else if (t is IdentifierToken)
                {
                    // If we're resolving a namespace, then this is part of the namespace.
                    if (state.ResolvingNamespace)
                    {
                        state.Namespace += t.InnerText;
                    }
                    // If we're resolving a class, then we're done. We found the class name.
                    else if (state.ResolvingClass)
                    {
                        // We're done.
                        result.Name = state.ComposeQualifiedClassName(t.InnerText);
                        return result;
                    }
                }
                else if (t is OpenConditionalDirectiveToken)
                {
                    state.OpenConditionalDirective();
                }
                else if (t is CloseConditionalDirectiveToken)
                {
                    state.CloseConditionalDirective();
                }
            }

            return result;
        }