public void WriteClass(IJsonClassGeneratorConfig config, StringBuilder sw, JsonType type) { string indentTypes = GetTypeIndent(config, type.IsRoot); string indentMembers = indentTypes + " "; string indentBodies = indentMembers + " "; const string visibility = "public"; var className = type.AssignedName; sw.AppendFormat(indentTypes + "{0} class {1}{2}", visibility, className, Environment.NewLine); sw.AppendLine(indentTypes + "{"); #if CAN_SUPRESS var shouldSuppressWarning = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization; if (shouldSuppressWarning) { sw.AppendFormat("#pragma warning disable 0649"); if (!config.UsePascalCase) { sw.AppendLine(); } } if (config.ExplicitDeserialization) { if (config.UseProperties) { WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix); } else { WriteClassWithFieldsExplicitDeserialization(sw, type, prefix); } } else #endif { if (config.ImmutableClasses) { this.WriteClassConstructor(config, sw, type, indentMembers: indentMembers, indentBodies: indentBodies); } this.WriteClassMembers(config, sw, type, indentMembers); } #if CAN_SUPPRESS if (shouldSuppressWarning) { sw.WriteLine(); sw.WriteLine("#pragma warning restore 0649"); sw.WriteLine(); } #endif if ((!config.UseNestedClasses) || (config.UseNestedClasses && !type.IsRoot)) { sw.AppendLine(indentTypes + "}"); } sw.AppendLine(); }
public GCodeGeometryOutput(StringBuilder stringOut) { feed = 1; sb = stringOut; sb.WriteLine("G20"); // inches sb.WriteLine("G90"); // absolute sb.WriteLine("G17"); // XY plane sb.WriteLine("M3"); // start spindle }
public void GenerateCarDetailsFile(IList<int> carIds, string location) { var cars = dataProvider.GetCars().Query<Car>().Where(x => carIds.Contains(x.Id)); StringBuilder builder = new StringBuilder(); builder.AppendLine("Make, Model, Year"); foreach(var car in cars) { builder.WriteLine("{0},{1},{2}", car.Make, car.Model, car.Year); } storage.SaveText(location, builder.ToString()); }
} // method public StringBuilder CreateRecordScript() { long newmax = maxnum + 20; StringBuilder buf = new StringBuilder(); buf.WriteLine("echo \"// Executing Record\""); buf.WriteLine("alias rc r1"); long step = 1; // Use a single letter as prefix for (long idx = maxnum + 1; idx < newmax; ++idx, ++step) { buf.WriteLine("alias r{0} \"record c{1};alias rc r{2}\"", step, idx.ToString("D5"), step + 1); } buf.WriteLine("alias r{0} \"record c{1};alias rc nop\"", step, newmax.ToString("D5")); buf.WriteLine("bind F11 rc"); string cfgname = Path.Combine(csgo_folder, "cfg", "myrecord.cfg"); File.WriteAllText(cfgname, buf.ToString(), new UTF8Encoding(false)); return(buf); } // method
public bool CreateTable <TSchema>(string tableName) where TSchema : IEntityBase { log.Describe($"{nameof(CreateTable)}<{typeof(TSchema).Name}>: {tableName}"); if (string.IsNullOrWhiteSpace(tableName)) { throw new ArgumentNullException(nameof(tableName)); } var type = typeof(TSchema); var columns = ReflectionUtil.GetColumnSchemas(type).ToArray(); var sql = new StringBuilder(512); if (columns.Length == 0) { throw new Exception("No columns defined by " + nameof(PostgreSqlColumnAttribute) + " in class: " + type.Name); } sql.AppendFormat("CREATE TABLE ") .WriteLine(ResolveTableName(tableName)) .WriteLine("("); foreach (var column in columns) { var columnName = '"' + column.Name + '"'; var columnType = column.DataType; var columnNotNull = column.Nullable ? null : " NOT NULL"; sql.WriteTabbedLine(1, $"{columnName} {columnType}{columnNotNull},"); } var pk = columns.SingleOrDefault(k => k.PrimaryKey); if (pk != null) { sql.WriteTabbedLine(1, $"PRIMARY KEY(\"{pk.Name}\")"); } else { sql.TrimEndLineBreaks() .TrimEnd(',') .NewLine(); } sql.WriteLine(")"); return(db.Execute(sql.ToString()) > 0); }
} // method public void ToStringBuilder(StringBuilder buf, int indent = 0) { string tindent = String.Empty; if (indent > 0) { tindent = new String(' ', indent); } VifEntry entry = this; while (entry != null) { if (entry.first != null) { buf.WriteLine("{0}{1}", tindent, entry.name); entry.first.ToStringBuilder(buf, indent + 3); } else { buf.WriteLine("{0}{1} {2}", tindent, entry.name, entry.value); } entry = entry.next; } } // method
} // method public static StringBuilder ProcessCSGO(Arguments options) { StringBuilder buf = new StringBuilder(); Steam steam = new Steam(); string appid = "730"; VifEntry manifest = steam.GetManifest(appid); if (manifest == null) { throw new Exception(string.Format("Failed to read the manifest for csgo (appid={0}) from \"{1}\"", appid, steam.apps_folder)); } string game_folder = Path.Combine(steam.apps_folder, "common", manifest.Get("AppState", "installdir")); string game_name = manifest.Get("AppState", "name"); if (!Directory.Exists(game_folder)) { throw new Exception(string.Format("Folder does not exist: {0}", game_folder)); } buf.WriteLine("Appid {0}", appid); buf.WriteLine(game_name); buf.WriteLine(game_folder); //manifest.ToStringBuilder(buf); CSGO csgo = new CSGO(game_folder, options.output_folder); if (options.docfg) { buf.WriteLine("Created Script:"); buf.Write(csgo.CreateRecordScript().ToString()); } buf.WriteLine("{0}{1}", "Files found: ", csgo.files.Count); buf.WriteLine("{0}{1}", "Next demo number: ", csgo.maxnum + 1); if (options.docopy) { csgo.CopyFiles(); buf.WriteLine("Copied {0} files to {1}", csgo.files_copied, csgo.output_folder); } return(buf); } // method
private void DoWriteUsing(StringBuilder builder, CsNamespace ns, string indent) { if (ns.Uses.Length > 0) { foreach (CsUsingDirective u in ns.Uses) { builder.WriteLine("{0}using {1};", indent, u.Namespace); } builder.WriteLine(); } }
private void DoWriteDelimitedComment(StringBuilder builder, string text) { int j = text.IndexOf("*/"); if (j >= 0) { builder.WriteLine(text.Substring(0, j + 2)); builder.WriteLine(); } }
// Files often start with things like copyright notices which we want to preserve. private void DoWriteSingleLineComments(StringBuilder builder, string text) { int i = 0; while (i + 2 < text.Length && text[i] == '/' && text[i + 1] == '/') { int j = text.IndexOf('\n', i); if (j >= 0) { builder.WriteLine(text.Substring(i, j - i)); i = j + 1; } else break; } builder.WriteLine(); }
private void DoBuildNewFile(string name, CsGlobalNamespace globals, CsDeclaration first, StringBuilder builder, string text, int offset, int length) { // If the file starts with a comment then write it out. if (text.Length > 2 && text[0] == '/' && text[1] == '/') DoWriteSingleLineComments(builder, text); else if (text.Length > 2 && text[0] == '/' && text[1] == '*') DoWriteDelimitedComment(builder, text); // Write the global using directives. DoWriteUsing(builder, globals, string.Empty); // Write the namespace the declaration was in. CsNamespace ns = DoGetNamespace(first); if (ns != null && ns.Name != "<globals>") { builder.WriteLine("namespace {0}{1}{2}", ns.Name, Constants.Bullet, "{"); DoWriteUsing(builder, ns, "\t"); } // If we're moving a member then create a dummy type. CsMember member = first as CsMember; if (member != null && member.DeclaringType != null) { string keyword = "?"; if (member.DeclaringType is CsClass) keyword = "class"; else if (member.DeclaringType is CsInterface) keyword = "interface"; else if (member.DeclaringType is CsStruct) keyword = "struct"; string modifiers; if (member.DeclaringType != null) modifiers = member.DeclaringType.Modifiers.ToString().ToLower(); else modifiers = member.Modifiers.ToString().ToLower(); modifiers = modifiers.Replace(",", string.Empty); builder.WriteLine("\t{0} {1} {2}", modifiers, keyword, name); builder.WriteLine("\t{"); } // Write the selection. builder.Write(text.Substring(offset, length)); // Close up type and namespaces. if (member != null && member.DeclaringType != null) builder.WriteLine("\t}"); if (ns != null && ns.Name != "<globals>") builder.WriteLine("}"); }
internal static void CreateAndSerialize() { XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable()); const string NamespacePrefix = "dixin"; namespaceManager.AddNamespace(NamespacePrefix, "https://weblogs.asp.net/dixin"); XmlDocument document = new XmlDocument(namespaceManager.NameTable); XmlElement rss = document.CreateElement("rss"); rss.SetAttribute("vewrsion", "2.0"); XmlAttribute attribute = document.CreateAttribute( "xmlns", NamespacePrefix, namespaceManager.LookupNamespace("xmlns")); attribute.Value = namespaceManager.LookupNamespace(NamespacePrefix); rss.SetAttributeNode(attribute); document.AppendChild(rss); XmlElement channel = document.CreateElement("channel"); rss.AppendChild(channel); XmlElement item = document.CreateElement("item"); channel.AppendChild(item); XmlElement title = document.CreateElement("title"); title.InnerText = "LINQ via C#"; item.AppendChild(title); XmlElement link = document.CreateElement("link"); link.InnerText = "https://weblogs.asp.net/dixin/linq-via-csharp"; item.AppendChild(link); XmlElement description = document.CreateElement("description"); description.InnerXml = "<p>This is a tutorial of LINQ and functional programming. Hope it helps.</p>"; item.AppendChild(description); XmlElement pubDate = document.CreateElement("pubDate"); pubDate.InnerText = new DateTime(2009, 9, 7).ToString("r"); item.AppendChild(pubDate); XmlElement guid = document.CreateElement("guid"); guid.InnerText = "https://weblogs.asp.net/dixin/linq-via-csharp"; guid.SetAttribute("isPermaLink", "true"); item.AppendChild(guid); XmlElement category1 = document.CreateElement("category"); category1.InnerText = "C#"; item.AppendChild(category1); XmlNode category2 = category1.CloneNode(false); category2.InnerText = "LINQ"; item.AppendChild(category2); XmlComment comment = document.CreateComment("Comment."); item.AppendChild(comment); XmlElement source = document.CreateElement(NamespacePrefix, "source", namespaceManager.LookupNamespace(NamespacePrefix)); source.InnerText = "https://github.com/Dixin/CodeSnippets/tree/master/Dixin/Linq"; item.AppendChild(source); // Serialize XmlDocument to string. StringBuilder xmlString = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", OmitXmlDeclaration = true }; using (XmlWriter writer = XmlWriter.Create(xmlString, settings)) { document.Save(writer); } // rssItem.ToString() returns "System.Xml.XmlElement". // rssItem.OuterXml returns a single line of XML text. xmlString.WriteLine(); }
void GenerateLine() { sb.WriteLine("{0}", "<path style='fill:none;stroke:#000000;stroke-width:1px' d='" + line.ToString() + "' id='" + name + "-" + nid.ToString() + "' />"); ++nid; }
public SVGGeometryOutput(StringBuilder stringOut) { sb = stringOut; sb.WriteLine("<?xml version='1.0' encoding='UTF-8' standalone='no'?>"); sb.WriteLine("<!-- created with Enchanted Gears (http://www.enchantedage.com/gears) -->"); sb.WriteLine("<svg xmlns:dc='http://purl.org/dc/elements/1.1/'"); sb.WriteLine(" xmlns:cc='http://creativecommons.org/ns#'"); sb.WriteLine(" xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"); sb.WriteLine(" xmlns:svg='http://www.w3.org/2000/svg'"); sb.WriteLine(" xmlns='http://www.w3.org/2000/svg'"); sb.WriteLine(" version='1.1'"); sb.WriteLine(" width='1000'"); sb.WriteLine(" height='1000'"); sb.WriteLine(" id='gears-svg'>"); sb.WriteLine("<defs id='defs-dummy' />"); sb.WriteLine("<circle id='center' fill='none' stroke='#808080' cx='500' cy='500' r='10' />"); }
public string Finish() { sb.WriteLine("M5"); // stop spindle sb.WriteLine("X0Y0"); // home position sb.WriteLine("M2"); // end of program return(sb.ToString()); }
public static string GetStatsString(string compiler, ICompilerCache cache) { var sb = new StringBuilder(); sb.WriteLine("compiler: {0}", compiler); sb.WriteLine("cachedir: {0}", Settings.CacheDirectory); if (Settings.DebugEnabled) { sb.WriteLine("debug file: {0}", Settings.DebugFile); } if (Settings.Disabled) { sb.WriteLine("disabled: yes"); } else { sb.WriteLine("disabled: no"); } if (compiler != null) { if (cache != null) { var stats = new CacheInfo(cache.OutputCache); sb.WriteLine("outputCache usage: {0} kb", (int)(stats.CacheSize / 1024)); sb.WriteLine("cached files: {0}", stats.CacheObjects); sb.WriteLine("hits: {0}", stats.CacheHits); sb.WriteLine("misses: {0}", stats.CacheMisses); sb.WriteLine("unsupported: {0}", stats.CacheUnsupported); sb.WriteLine("slow hits: {0}", stats.SlowHitCount); } } return(sb.ToString()); }
public static string GetStatsString(string compiler, ICompilerCache cache) { var sb = new StringBuilder(); sb.WriteLine("compiler: {0}", compiler); sb.WriteLine("cachedir: {0}", Settings.CacheDirectory); if (Settings.DebugEnabled) { sb.WriteLine("debug file: {0}", Settings.DebugFile); } if (Settings.Disabled) { sb.WriteLine("disabled: yes"); } else { sb.WriteLine("disabled: no"); } if (compiler != null) { if (cache != null) { var stats = new CacheInfo(cache.OutputCache); sb.WriteLine("outputCache usage: {0} kb", (int)(stats.CacheSize / 1024)); sb.WriteLine("cached files: {0}", stats.CacheObjects); sb.WriteLine("hits: {0}", stats.CacheHits); sb.WriteLine("misses: {0}", stats.CacheMisses); sb.WriteLine("unsupported: {0}", stats.CacheUnsupported); sb.WriteLine("slow hits: {0}", stats.SlowHitCount); } } return sb.ToString(); }