/// <summary> /// Copy values of this extension's own settings to equivalent values of this page. /// </summary> private void Load() { TabSize = Settings.Current.TabSize; UseTabSizeInTextEditor = Settings.Current.UseTabSizeInTextEditor ? Toggle.On : Toggle.Off; FixedIndentSize = Settings.Current.FixedIndentSize; TrimTrailingSpaces = Settings.Current.TrimTrailingSpaces ? Toggle.On : Toggle.Off; HtmlEncode = Settings.Current.HtmlEncode ? Toggle.On : Toggle.Off; NewLineType = Settings.Current.NewLineType; }
public override bool Generate( TableDescriptor descriptor, string reader, string outputDir, NewLineType newLineType) { this.descriptor = descriptor; this.reader = reader; if (newLineType == NewLineType.Dos) { this.newLineStr = "\r\n"; } else { this.newLineStr = "\n"; } for (int i = 0; i < this.descriptor.GlobalStructs.Count; ++i) { TableDescriptor.StructDef def = this.descriptor.GlobalStructs[i]; string filePath = Path.Combine( outputDir, def.Name + ".cs"); string fileContent = GenerateGlobalStructFile(def); try { File.WriteAllText(filePath, fileContent); } catch (Exception e) { Console.Error.WriteLine(string.Format( "error: write file {0} failed: {1}", filePath, e.Message)); return(false); } } for (int i = 0; i < this.descriptor.Tables.Count; ++i) { TableDescriptor.TableDef def = this.descriptor.Tables[i]; string filePath = Path.Combine( outputDir, def.Name + ".cs"); string fileContent = GenerateTableFile(def); try { File.WriteAllText(filePath, fileContent); } catch (Exception e) { Console.Error.WriteLine(string.Format( "error: write file {0} failed: {1}", filePath, e.Message)); return(false); } } return(true); }
public static string Format( string source, int tabSize = 4, int fixedIndentSize = 0, bool trimTrailingSpaces = true, bool htmlEncode = false, NewLineType newLineType = NewLineType.CrLf) { if (string.IsNullOrEmpty(source)) return source; var newLine = (newLineType == NewLineType.CrLf) ? "\r\n" : "\n"; var trimmed = TrimSpaces(source, tabSize, fixedIndentSize, trimTrailingSpaces); var joined = string.Join(newLine, trimmed.Concat(new[] { string.Empty })); // The last empty string is to add new line at the tail. return htmlEncode ? WebUtility.HtmlEncode(joined) : joined; }
public static string Format( string source, int tabSize = 4, int fixedIndentSize = 0, bool trimTrailingSpaces = true, bool htmlEncode = false, NewLineType newLineType = NewLineType.CrLf) { if (string.IsNullOrEmpty(source)) { return(source); } var newLine = (newLineType == NewLineType.CrLf) ? "\r\n" : "\n"; var trimmed = TrimSpaces(source, tabSize, fixedIndentSize, trimTrailingSpaces); var joined = string.Join(newLine, trimmed.Concat(new[] { string.Empty })); // The last empty string is to add new line at the tail. return(htmlEncode ? WebUtility.HtmlEncode(joined) : joined); }
/// <summary> /// Set the new line property to the given new line type (<paramref name="a_newLineType"/>). /// </summary> /// <param name="a_newLineType">New line type.</param> private void SetNewLine(NewLineType a_newLineType) { switch (a_newLineType) { case NewLineType.Environment: _newLineLength = Environment.NewLine.Length; break; case NewLineType.CrNl: _newLineLength = 2; break; case NewLineType.Nl: case NewLineType.Cr: _newLineLength = 1; break; default: throw new ArgumentOutOfRangeException(nameof(a_newLineType), a_newLineType, null); } }
public abstract bool Generate( TableDescriptor descriptor, string reader, string outputDir, NewLineType newLineType);
/// <summary> /// Initializes a new instance of the <see cref="T:System.IO.StreamReader"/> class for the specified a_stream, with the specified character a_encoding, byte order mark detection option, and buffer size. /// </summary> /// <param name="a_stream">The a_stream to be read.</param> /// <param name="a_encoding">The character a_encoding to use.</param> /// <param name="a_detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param> /// <param name="a_bufferSize">The minimum buffer size.</param> /// <param name="a_newLine">New line type.</param> /// <exception cref="T:System.ArgumentException">The a_stream does not support reading.</exception> /// <exception cref="T:System.ArgumentNullException"><paramref name="a_stream"/> or <paramref name="a_encoding"/> is null.</exception> /// <exception cref="T:System.ArgumentOutOfRangeException"><paramref name="a_bufferSize"/> is less than or equal to zero.</exception> public AdvancedStreamReader(Stream a_stream, Encoding a_encoding, bool a_detectEncodingFromByteOrderMarks, int a_bufferSize, NewLineType a_newLine = NewLineType.Environment) : base(a_stream, a_encoding, a_detectEncodingFromByteOrderMarks, a_bufferSize) { SetNewLine(a_newLine); ResetBaseStream(); }
public static void Add(this List <string> list, object obj, NewLineType newLineType = NewLineType.None) { list.Add(obj, null, newLineType); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.IO.StreamReader"/> class for the specified file name. /// </summary> /// <param name="a_path">The complete file a_path to be read.</param> /// <param name="a_newLine">New line type.</param> /// <exception cref="T:System.ArgumentException"><paramref name="a_path"/> is an empty string ("").</exception> /// <exception cref="T:System.ArgumentNullException"><paramref name="a_path"/> is null.</exception> /// <exception cref="T:System.IO.FileNotFoundException">The file cannot be found.</exception> /// <exception cref="T:System.IO.DirectoryNotFoundException">The specified a_path is invalid, such as being on an unmapped drive.</exception> /// <exception cref="T:System.IO.IOException"><paramref name="a_path"/> includes an incorrect or invalid syntax for file name, directory name, or volume label.</exception> public AdvancedStreamReader(string a_path, NewLineType a_newLine = NewLineType.Environment) : base(a_path) { SetNewLine(a_newLine); ResetBaseStream(); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.IO.StreamReader"/> class for the specified a_stream, with the specified character a_encoding. /// </summary> /// <param name="a_stream">The a_stream to be read.</param> /// <param name="a_encoding">The character a_encoding to use.</param> /// <param name="a_newLine">New line type.</param> /// <exception cref="T:System.ArgumentException"><paramref name="a_stream"/> does not support reading.</exception> /// <exception cref="T:System.ArgumentNullException"><paramref name="a_stream"/> or <paramref name="a_encoding"/> is null. </exception> public AdvancedStreamReader(Stream a_stream, Encoding a_encoding, NewLineType a_newLine = NewLineType.Environment) : base(a_stream, a_encoding) { SetNewLine(a_newLine); ResetBaseStream(); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.IO.StreamReader"/> class for the specified a_stream, with the specified byte order mark detection option. /// </summary> /// <param name="a_stream">The a_stream to be read.</param> /// <param name="a_detectEncodingFromByteOrderMarks">Indicates whether to look for byte order marks at the beginning of the file.</param> /// <param name="a_newLine">New line type.</param> /// <exception cref="T:System.ArgumentException"><paramref name="a_stream"/> does not support reading. </exception> /// <exception cref="T:System.ArgumentNullException"><paramref name="a_stream"/> is null. </exception> public AdvancedStreamReader(Stream a_stream, bool a_detectEncodingFromByteOrderMarks, NewLineType a_newLine = NewLineType.Environment) : base(a_stream, a_detectEncodingFromByteOrderMarks) { SetNewLine(a_newLine); ResetBaseStream(); }
public abstract bool Generate( ProtocolDescriptor descriptor, string outputDir, NewLineType newLineType);
public static void Add(this List <string> list, object obj, ConsoleColor?color, NewLineType newLineType = NewLineType.None) { string text = (color != null) ? obj.InsertTag((ConsoleColor)color) : obj.ToString(); if (newLineType == NewLineType.Append || newLineType == NewLineType.Both) { text += Environment.NewLine; } if (newLineType == NewLineType.Prepend || newLineType == NewLineType.Both) { text = Environment.NewLine + text; } list.Add(text); }