BamlLocalization.LocBamlConst.IsValidCultureName C# (CSharp) Метод

IsValidCultureName() статический приватный Метод

static private IsValidCultureName ( string name ) : bool
name string
Результат bool
        internal static bool IsValidCultureName(string name)
        {
            try
            {
                // try create a culture to see if the name is a valid culture name
                CultureInfo culture = new CultureInfo(name);
                return (culture != null);
            }
            catch (Exception )
            {
                return false;
            }
        }

Usage Example

        //-----------------------------------------
        // private function dealing with naming
        //-----------------------------------------

        // return the local output file name, i.e. without directory
        private static string GetOutputFileName(LocBamlOptions options)
        {
            string outputFileName;
            string inputFileName = Path.GetFileName(options.Input);

            switch (options.InputType)
            {
            case FileType.BAML:
            {
                return(inputFileName);
            }

            case FileType.EXE:
            {
                inputFileName = inputFileName.Remove(inputFileName.LastIndexOf('.')) + ".resources.dll";
                return(inputFileName);
            }

            case FileType.DLL:
            {
                return(inputFileName);
            }

            case FileType.RESOURCES:
            {
                // get the output file name
                outputFileName = inputFileName;

                // get to the last dot separating filename and extension
                int lastDot       = outputFileName.LastIndexOf('.');
                int secondLastDot = outputFileName.LastIndexOf('.', lastDot - 1);
                if (secondLastDot > 0)
                {
                    string cultureName = outputFileName.Substring(secondLastDot + 1, lastDot - secondLastDot - 1);
                    if (LocBamlConst.IsValidCultureName(cultureName))
                    {
                        string extension = outputFileName.Substring(lastDot);
                        string frontPart = outputFileName.Substring(0, secondLastDot + 1);
                        outputFileName = frontPart + options.CultureInfo.Name + extension;
                    }
                }
                return(outputFileName);
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }