示例#1
0
        internal CompilationUnitSyntax GenerateCompilationUnit()
        {
            var ctx = SourceFileContext.CreateFullyQualified(SystemClock.Instance);
            var ns  = Namespace(PackageName);

            using (ctx.InNamespace(ns))
            {
                var serviceClass     = GenerateServiceClass(ctx);
                var baseRequestClass = GenerateBaseRequestClass(ctx);
                ns = ns.AddMembers(serviceClass, baseRequestClass);

                foreach (var resource in Resources)
                {
                    var resourceClass = resource.GenerateClass(ctx);
                    ns = ns.AddMembers(resourceClass);
                }
            }
            var dataNs = Namespace(PackageName + ".Data");

            using (ctx.InNamespace(dataNs))
            {
                var dataModels = DataModels
                                 .Where(dm => !dm.IsPlaceholder)
                                 .OrderBy(dm => dm.Typ.Name, StringComparer.Ordinal);
                foreach (var dataModel in dataModels)
                {
                    dataNs = dataNs.AddMembers(dataModel.GenerateClass(ctx));
                }
            }
            return(ctx.CreateCompilationUnit(ns).AddMembers(dataNs));
        }