private static IEnumerable <Namespace> GetNamespaceResults(NamespaceMetrics metrics) { foreach (NamespaceMetric namespaceMetric in metrics.Results) { Namespace @namespace = new Namespace(); @namespace.Name = namespaceMetric.Name; Namespace namespace1 = @namespace; if (namespaceMetric.Metrics != null) { namespace1.Add(MetricsReportBuilder.GetMetricsResult(namespaceMetric.Metrics)); } namespace1.Add(MetricsReportBuilder.GetTypesResult(namespaceMetric.TypeMetrics)); yield return(namespace1); } }
static void Main(string[] args) { var cls = Class.Add("MyClass") .AddFields( Field.Add("myfield") .Type("string") .Access(AccessModifier.Public), Field.Add("myfield2") .Type("string") .Access(AccessModifier.Public), Field.Add("myfield3") .Type("string") .Access(AccessModifier.Public) ) .AddConstructor( Constructor.Add() .Parameter("string", "myfield") ) .AddMethod( Method.Add("GetFields") .ReturnedType("string") .AddParameter("string", "request") .Access(AccessModifier.Public) ) .AddAncesor(""); var nmsps = Namespace.Add("MyNamespace").Using("System").Class(cls).Build(); Console.WriteLine(nmsps); string path = "code.cs"; if (File.Exists(path)) { File.Delete(path); } FileInfo fi = new FileInfo(path); using (var file = new StreamWriter(File.OpenWrite(path))) { file.WriteLine(nmsps); } Process.Start( new ProcessStartInfo( @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe", $"-target:library {fi.FullName}" ) ); }
private IEnumerable <Namespace> GetPageNamespacesToSearch(Type originType) { Namespace ns = Namespace.FromType(originType); if (this.IsAccessorType(originType)) { if (ns.AsTypeName().Name == "Accessors") { ns = ns.Up(); } if (this.HasAccessorSuffix(originType, out string prefix)) { yield return(ns.Add("Queries").Add(prefix)); yield return(ns.Add("Commands").Add(prefix)); yield return(ns.Add("Queries.Shared")); yield return(ns.Add("Commands.Shared")); } yield return(ns.Add("Queries")); yield return(ns.Add("Commands")); } else if (this.IsPageType(originType)) { Namespace root = ns.Traverse().FirstOrDefault(ns2 => ns2.AsTypeName().Name == "Queries" || ns2.AsTypeName().Name == "Commands"); yield return(ns); if (root != null) { yield return(root); yield return(root.Add("Shared")); } } }