コード例 #1
0
 /// <summary>
 ///     For display
 /// </summary>
 /// <returns></returns>
 internal virtual void Render(ConsoleStringBuilderInterlaced sb)
 {
     sb
     .AppendInterlacedLine("new GenericQueryPart {")
     .Up()
     .AppendInterlacedLine("QueryCommand = \"{0}\",", Prefix)
     .AppendInterlacedLine("Builder = \"{0}\",", Builder != null ? Builder.GetType().Name : "{NULL}")
     .AppendInterlaced("Parameter[{0}] = ", QueryParameters.Count());
     if (QueryParameters.Any())
     {
         sb.AppendInterlacedLine("{")
         .Up();
         foreach (var queryParameter in QueryParameters.Cast <QueryParameter>())
         {
             queryParameter.Render(sb);
             sb.AppendLine(",");
         }
         sb.Down()
         .AppendInterlacedLine("}");
     }
     else
     {
         sb.AppendLine("{}");
     }
     sb.Down()
     .AppendInterlaced("}");
     //return string.Format("{{QueryCommand = {0}, Parameter = [{1}]}}", Prefix, paraString);
 }
コード例 #2
0
        internal void Render(ConsoleStringBuilderInterlaced sb)
        {
            sb.AppendInterlacedLine("new IQueryContainer {")
            .Up()
            .AppendInterlacedLine("AllowParamterRenaming = {0},", AllowParamterRenaming.ToString().ToLower())
            .AppendInterlacedLine("AutoParameterCounter = {0},", AutoParameterCounter)
            .AppendInterlacedLine("QueryDebugger = ")
            .Insert(new QueryDebugger(Compile(), AccessLayer.Database).Render)
            .AppendInterlacedLine("Parts[{0}] = ", Parts.Count)
            .AppendInterlacedLine("{")
            .Up();

            foreach (var genericQueryPart in Parts)
            {
                genericQueryPart.Render(sb);
                sb.AppendLine(",");
            }

            sb.Down()
            .AppendInterlacedLine("}")
            .Down()
            .AppendInterlaced("}");
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public string RenderPocoClass(bool notifyPropertysChanged = false)
        {
            var sb = new ConsoleStringBuilderInterlaced();

            if (GenerateConfigMethod)
            {
                NamespaceImports.Add(typeof(ConfigurationResolver <>).Namespace);
            }

            if (notifyPropertysChanged)
            {
                NamespaceImports.Add(typeof(INotifyPropertyChanged).Namespace);
                NamespaceImports.Add(typeof(CallerMemberNameAttribute).Namespace);
            }

            NamespaceImports.Add(typeof(EagarDataRecord).Namespace);
            NamespaceImports.Add(typeof(GeneratedCodeAttribute).Namespace);
            NamespaceImports.Add(typeof(DbCollection <>).Namespace);

            sb.AppendInterlacedLine("//------------------------------------------------------------------------------");
            sb.AppendInterlacedLine("// <auto-generated>");
            sb.AppendInterlacedLine("// This code was generated by a tool.");
            sb.AppendInterlacedLine("// Runtime Version:2.0.50727.42");
            sb.AppendInterlacedLine("// Changes to this file may cause incorrect behavior and will be lost if");
            sb.AppendInterlacedLine("// the code is regenerated.");
            sb.AppendInterlacedLine("// </auto-generated>");
            sb.AppendInterlacedLine("//------------------------------------------------------------------------------");


            foreach (var namespaceImport in NamespaceImports)
            {
                sb.AppendLine($"using {namespaceImport};");
            }

            sb.AppendLine();
            sb.AppendLine("namespace " + Namespace);
            sb.AppendLine("{");
            sb.Up();
            sb.AppendLine();
            foreach (var headerLine in CompilerHeader)
            {
                sb.AppendInterlacedLine($"//{headerLine}");
            }


            sb.AppendLine();
            if (!GenerateConfigMethod)
            {
                foreach (var attributeInfo in Attributes)
                {
                    attributeInfo.Render(sb);
                }
            }
            if (GeneratedCodeAttribute != null)
            {
                sb.AppendInterlacedLine(
                    $"[{nameof(GeneratedCodeAttribute)}(tool: \"{GeneratedCodeAttribute.Tool}\", version: \"{GeneratedCodeAttribute.Version}\")]");
            }

            sb.AppendInterlaced("public partial class " + ClassName);
            if (!string.IsNullOrWhiteSpace(Inherts) || notifyPropertysChanged)
            {
                sb.Append($": {Inherts}");
                if (notifyPropertysChanged)
                {
                    if (!string.IsNullOrWhiteSpace(Inherts))
                    {
                        sb.Append(", ");
                    }
                    sb.Append(nameof(INotifyPropertyChanged));
                }
            }

            sb.AppendLine();
            sb.AppendInterlacedLine("{");
            sb.Up();
            sb.AppendInterlacedLine($"public {ClassName}() {{}}");

            if (GenerateConstructor && !GenerateFactory)
            {
                var readerName = "reader";
                sb.AppendInterlacedLine($"public {ClassName}({nameof(EagarDataRecord)} {readerName}) ");
                sb.AppendInterlacedLine("{").Up();

                foreach (var propertyInfo in Properties)
                {
                    propertyInfo.RenderAssignment(sb, readerName, "this");
                }

                sb.Down().AppendInterlacedLine("}");
            }

            if (!IsSuperClass)
            {
                foreach (var propertyInfo in Properties)
                {
                    propertyInfo.RenderProperty(sb, GenerateConfigMethod, notifyPropertysChanged);
                }
            }

            if (GenerateFactory)
            {
                var readerName = "reader";
                sb.AppendInterlacedLine($"public static {ClassName} Factory({nameof(EagarDataRecord)} {readerName})");
                sb.AppendInterlacedLine("{").Up();
                var targetName = "super";
                sb.AppendInterlacedLine($"var {targetName} = new {ClassName}();");

                foreach (var propertyInfo in Properties)
                {
                    propertyInfo.RenderAssignment(sb, readerName, targetName);
                }

                sb.AppendInterlacedLine($"return {targetName};");

                sb.Down().AppendInterlacedLine("}");
            }

            if (GenerateConfigMethod)
            {
                var      configArgument = string.Format("ConfigurationResolver<{0}>", ClassName);
                var      configName     = "config";
                string[] eventNames     =
                {
                    "BeforeConfig()", "AfterConfig()", $"BeforeConfig({configArgument} {configName})",
                    $"AfterConfig({configArgument} {configName})"
                };

                foreach (var eventName in eventNames)
                {
                    sb.AppendInterlacedLine($"static partial void {eventName};");
                }

                sb.AppendInterlacedLine($"[{nameof(ConfigMehtodAttribute)}]");
                sb.AppendInterlacedLine($"public static void Configuration({configArgument} {configName})");
                sb.AppendInterlacedLine("{");
                sb.Up();
                sb.AppendInterlacedLine("BeforeConfig();");
                sb.AppendInterlacedLine($"BeforeConfig({configName});");

                if (!GenerateConstructor)
                {
                    sb.AppendInterlacedLine(
                        $"config.{nameof(ConfigurationResolver<object>.SetFactory)}" +
                        "(" +
                        $"{ClassName}.Factory, " +
                        "true" +
                        ");");
                }

                foreach (var propertyInfoAttribute in Attributes)
                {
                    sb.AppendInterlacedLine(
                        $"config.{nameof(ConfigurationResolver<object>.SetClassAttribute)}" +
                        "(" +
                        $"new {propertyInfoAttribute.Name}({propertyInfoAttribute.RenderAssignments()})" +
                        ");");
                }

                foreach (var propertyInfo in Properties)
                {
                    foreach (var propertyInfoAttribute in propertyInfo.Attributes)
                    {
                        sb.AppendInterlacedLine(
                            $"config.{nameof(ConfigurationResolver<object>.SetPropertyAttribute)}" +
                            "(" +
                            $"s => s.{propertyInfo.Name}" +
                            ", " +
                            $"new {propertyInfoAttribute.Name}({propertyInfoAttribute.RenderAssignments()})" +
                            ");");
                    }
                }

                sb.AppendInterlacedLine($"AfterConfig({configName});");
                sb.AppendInterlacedLine("AfterConfig();");

                sb.Down();
                sb.AppendInterlacedLine("}");
            }

            if (notifyPropertysChanged)
            {
                sb.AppendInterlacedLine($"#region {nameof(INotifyPropertyChanged)}");
                sb.AppendInterlacedLine(
                    $"public event {nameof(PropertyChangedEventHandler)} {nameof(INotifyPropertyChanged.PropertyChanged)};");
                sb.AppendInterlacedLine("");
                sb.AppendInterlacedLine("protected virtual void SendPropertyChanged([CallerMemberName] string propertyName = null)");
                sb.AppendInterlacedLine("{").Up();
                sb.AppendInterlacedLine("PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));");
                sb.Down().AppendInterlacedLine("}");
                sb.AppendInterlacedLine("");
                sb.AppendInterlacedLine("#endregion");
            }

            sb.Down();
            sb.AppendInterlacedLine("}");
            sb.Down();
            sb.AppendLine("}");
            using (var writer = new StringWriter())
            {
                sb.WriteToSteam(writer, wrapper => { }, () => { });
                var stringBuilder = writer.GetStringBuilder();
                return(stringBuilder.ToString());
            }
        }