internal/*For test*/ Byte[] GenerateCodeInternal(String inputFileName, String inputFileContent)
		{
			using (var stream = new MemoryStream())
			{
				using (var writer = new IndentStreamWriter(stream, Encoding.UTF8))
				{
					using (var reader = new ContentReader(inputFileContent))
					{
						var headerProcessor = new HeaderProcessor
						{
							Namespace = this.FileNamespace,
							ClassName = inputFileName.Split('/', '\\').Last().Split('.').First(),
						};
						var headerOver = false;
						while (true)
						{
							var line = reader.ReadLine();
							if (line == null)
							{	// EOL
								break;
							}

							if (line.StartsWith("@") && !headerOver)
							{	// Processing headers.
								headerOver = !headerProcessor.Process(line);
								if (headerOver)
								{
									headerProcessor.WriteHeader(writer);
								}
							} else
							{	// End processing headers.
								if (!headerOver)
								{	// Header is just over last line.
									headerOver = true;
									headerProcessor.WriteHeader(writer);
								}
								// Read documents
								var document = new StringBuilder();
								while (ContentReader.IsDocumentLine(line))
								{
									document.AppendLine(line.TrimStart().Remove(0, 3).TrimStart());
									line = reader.ReadLine();
								}
								using (var propertyProcessor = new PropertyProcessor(line))
								{
									propertyProcessor.Default = headerProcessor.PropertyDefaultSettings;
									propertyProcessor.Document = document.ToString();
									propertyProcessor.Process();
									propertyProcessor.WriteProperty(writer);
								}
							}	// End header detection.
						}	// End loop.
					}	// End ContentgReader.
					writer.Flush();
				}	// End IndentStreamWriter.
				stream.Flush();
				return stream.ToArray();
			}
		}
コード例 #2
0
		public void WriteProperty(IndentStreamWriter writer)
		{
			this.WriteDocument(writer);
			var declare = new String[]
			{
				this.propertyAccess,
				this.propertyStatic,
				this.propertyType, 
				this.propertyName,
			};
			var declareLine = String.Join(" ", declare.Where(w => w != PropertyReader.Missed));

			writer.WriteLineIndent(declareLine);
			using (new BraceWriter(writer))
			{
				if (this.propertyGettable)
				{
					writer.WriteIndent(String.Empty);
					if (!String.IsNullOrWhiteSpace(this.propertyGetAccess))
					{
						writer.Write("{0} ", this.propertyGetAccess);
					}
					writer.WriteLine("get");
					using (new BraceWriter(writer))
					{
						writer.WriteLineIndent(this.GetterTemplate, this.propertyCode);
					}
				}
				if (this.propertySettable)
				{
					writer.WriteIndent(String.Empty);
					if (!String.IsNullOrWhiteSpace(this.propertySetAccess))
					{
						writer.Write("{0} ", this.propertySetAccess);
					}
					writer.WriteLine("set");
					using (new BraceWriter(writer))
					{
						writer.WriteLineIndent(this.SetterTemplate, this.propertyCode);
					}
				}
			}
			writer.WriteLine();
		}
コード例 #3
0
		public BraceWriter(IndentStreamWriter writer)
		{
			this.writer = writer;
			this.writer.WriteOpenBrace();
		}
コード例 #4
0
		public void WriteHeader(IndentStreamWriter writer)
		{
			if (this._fullUsings.Count == 0)
			{
				writer.WriteLine("using System;");
			} else
			{
				foreach (var @using in this._fullUsings.OrderBy(key => key))
				{
					writer.WriteLine("using {0};", @using);
				}
			}
			writer.WriteLine();

			writer.WriteLine("namespace {0}", this._namespace ?? this.Namespace);
			writer.WriteOpenBrace();
			foreach (var @using in this._shortUsings.OrderBy(key => key))
			{
				writer.WriteLineIndent("using {0};", @using);
			}
			writer.WriteLine();
			writer.WriteIndent("public partial class {0}", this.ClassName);
			if (this._base != null)
			{
				writer.Write(" : {0}", this._base);
			}
			if (this._implements.Count != 0)
			{
				writer.Write(this._base == null ? " : {0}" : ", {0}", String.Join(", ", this._implements));
			}
			writer.WriteLine();
			writer.WriteOpenBrace();
		}
コード例 #5
0
		private void WriteDocument(IndentStreamWriter writer)
		{
			if (String.IsNullOrWhiteSpace(this.Document))
			{
				return;
			}
			writer.WriteLineIndent("/// <summary>");
			using (var docReader = new StringReader(this.Document))
			{
				while (true)
				{
					var line = docReader.ReadLine();
					if (line == null)
					{
						break;
					}
					writer.WriteLineIndent("/// {0}", line);
				}
			}
			writer.WriteLineIndent("/// </summary>");
		}