// References: // - YamlSerializer.dll // - SharpPad.exe // // Imports: // - System.Yaml // // RunsAfter: // - cscript://172.16.96.171/scripts/networking/simpleserver.csc#1.0.481+ // // Requires: // - ReflectionPermission // - CodeAccessPermission // - // EnvironmentVariable: USERNAME // AccessLevel: EnvironmentPermission.Read // - // EnvironmentVariable: COMPUTERNAME // AccessLevel: EnvironmentPermission.Write // // Summary: "Defines the header format // to be used by scripts for supplying // metadata. This includes referenced // assemblies and namespaces to be imported." // // Version: 0.3 // // Author: Zachary Gramana // // Date: 4/15/2011 // // Revisions: // - // Version: 0.1 // Author: Zachary Gramana // Date: 4/13/2011 // - // Version: 0.2 // Author: Brandon Berry // Date: 4/13/2011 P("SharpScript Header After Uncommenting:"); P(); var codeReader = new StringReader(host.SourceCode.Text); var sitem = new StringBuilder(); bool inHeader = true; while (inHeader) { var line = codeReader.ReadLine(); var nextLine = codeReader.ReadLine(); // If this line is empty, then skip to the next line. bool thisLineQualifies = false; bool thisLineEmpty = String.IsNullOrWhiteSpace(line); if (thisLineEmpty || line.StartsWith(@"//")) { if (!thisLineEmpty) sitem.AppendLine(line.Replace(@"//", String.Empty)); thisLineQualifies = true; } bool nextLineQualifies = false; bool nextLineEmpty = String.IsNullOrWhiteSpace(nextLine); if (nextLineEmpty || nextLine.StartsWith(@"//")) { if (!nextLineEmpty) sitem.AppendLine(nextLine.Replace(@"//", String.Empty)); nextLineQualifies = true; } if (!thisLineQualifies && !nextLineQualifies) { inHeader = false; } else { inHeader = true; } } var uncommentedSitem = sitem.ToString(); P(uncommentedSitem); P(); P(); var deserializer = new System.Yaml.Serialization.YamlSerializer(); deserializer = new System.Yaml.Serialization.YamlSerializer(); dynamic ditem = null; try { ditem = deserializer.Deserialize(uncommentedSitem, typeof(object)); } catch (Exception ex) { P(ex); } P("Resulting C# Class File Header:"); P(); foreach (Dictionary aitem in ditem) { P(@"/*"); P(); P(" Summary:"); if (aitem.ContainsKey("Requires")) { P("\t\t{0}", aitem["Summary"]); } P(" References:"); if (aitem.ContainsKey("References")) { foreach (var asm in aitem["References"] as IEnumerable) { P("\t\t{0}", asm); } } P(" Revisions:"); if (aitem.ContainsKey("Revisions")) { foreach (dynamic nspace in aitem["Revisions"] as IEnumerable) { P("\t{0},\t{2}, {1}", nspace["Version"], nspace["Author"], nspace["Date"]); } } P(@"*/"); P(); if (aitem.ContainsKey("Imports")) { foreach (var nspace in aitem["Imports"] as IEnumerable) { P("using {0};", nspace); } } }