BamlLocalization.ResourceTextWriter.WriteColumn C# (CSharp) Метод

WriteColumn() приватный Метод

private WriteColumn ( string value ) : void
value string
Результат void
        internal void WriteColumn(string value)
        {
            if (value == null)
                    value = string.Empty;

            // if it contains delimeter, quote, newline, we need to escape them
            if (value.IndexOfAny(new char[]{'\"', '\r', '\n', _delimiter}) >= 0)
            {
                // make a string builder at the minimum required length;
                StringBuilder builder = new StringBuilder(value.Length + 2);

                // put in the opening quote
                builder.Append('\"');

                // double quote each quote
                for (int i = 0; i < value.Length; i++)
                {
                    builder.Append(value[i]);
                    if (value[i] == '\"')
                    {
                        builder.Append('\"');
                    }
                }

                // put in the closing quote
                builder.Append('\"');
                value = builder.ToString();
            }

            if (!_firstColumn)
            {
                // if we are not the first column, we write delimeter
                // to seperate the new cell from the previous ones.
                _writer.Write(_delimiter);
            }
            else
            {
                _firstColumn = false;   // set false
            }

            _writer.Write(value);
        }

Usage Example

        /// <summary>
        /// Write the localizable key-value pairs
        /// </summary>
        /// <param name="options"></param>
        internal static void Write(LocBamlOptions options)
        {
            Stream output = new FileStream(options.Output, FileMode.Create);
            InputBamlStreamList bamlStreamList = new InputBamlStreamList(options);

            using (ResourceTextWriter writer = new ResourceTextWriter(options.TranslationFileType, output))
            {
                options.WriteLine(StringLoader.Get("WriteBamlValues"));
                for (int i = 0; i < bamlStreamList.Count; i++)
                {
                    options.Write("    ");
                    options.Write(StringLoader.Get("ProcessingBaml", bamlStreamList[i].Name));

                    // Search for comment file in the same directory. The comment file has the extension to be
                    // "loc".
                    string     commentFile   = Path.ChangeExtension(bamlStreamList[i].Name, "loc");
                    TextReader commentStream = null;

                    try
                    {
                        if (File.Exists(commentFile))
                        {
                            commentStream = new StreamReader(commentFile);
                        }

                        // create the baml localizer
                        BamlLocalizer mgr = new BamlLocalizer(
                            bamlStreamList[i].Stream,
                            new BamlLocalizabilityByReflection(options.Assemblies),
                            commentStream
                            );

                        // extract localizable resource from the baml stream
                        BamlLocalizationDictionary dict = mgr.ExtractResources();

                        // write out each resource
                        foreach (DictionaryEntry entry in dict)
                        {
                            // column 1: baml stream name
                            writer.WriteColumn(bamlStreamList[i].Name);

                            BamlLocalizableResourceKey key      = (BamlLocalizableResourceKey)entry.Key;
                            BamlLocalizableResource    resource = (BamlLocalizableResource)entry.Value;

                            // column 2: localizable resource key
                            writer.WriteColumn(LocBamlConst.ResourceKeyToString(key));

                            // column 3: localizable resource's category
                            writer.WriteColumn(resource.Category.ToString());

                            // column 4: localizable resource's readability
                            writer.WriteColumn(resource.Readable.ToString());

                            // column 5: localizable resource's modifiability
                            writer.WriteColumn(resource.Modifiable.ToString());

                            // column 6: localizable resource's localization comments
                            writer.WriteColumn(resource.Comments);

                            // column 7: localizable resource's content
                            writer.WriteColumn(resource.Content);

                            // Done. finishing the line
                            writer.EndLine();
                        }

                        options.WriteLine(StringLoader.Get("Done"));
                    }
                    finally
                    {
                        if (commentStream != null)
                        {
                            commentStream.Close();
                        }
                    }
                }

                // close all the baml input streams, output stream is closed by writer.
                bamlStreamList.Close();
            }
        }
All Usage Examples Of BamlLocalization.ResourceTextWriter::WriteColumn