コード例 #1
0
        private void InitializeControlProperties(StringBuilder sb, ComponentRepresentation data)
        {
            sb.AppendLine("            //");
            sb.AppendLine($"            // {data.Name}");
            sb.AppendLine("            //");

            string controlName;

            if (data.IsRoot)
            {
                controlName = "this";
            }
            else
            {
                controlName = $"this.{data.Name}";
            }

            foreach (var property in data.ValueProperties)
            {
                var valueCode = ProvideValueCode(property.Value);
                if (valueCode != null)
                {
                    sb.AppendLine($"            {controlName}.{property.Name} = {valueCode};");
                }
            }

            foreach (CollectionProperty property in data.CollectionProperties)
            {
                foreach (var value in property.Values)
                {
                    var valueCode = ProvideValueCode(value);
                    sb.AppendLine($"            {controlName}.{property.Name}.Add({valueCode});");
                }
            }
        }
コード例 #2
0
        public string SerializeControl(ComponentRepresentation root)
        {
            var allControls = root.Flattern().ToArray();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"namespace {root.ComponentType.Namespace}");
            sb.AppendLine("{");
            sb.AppendLine($"    partial class {root.ComponentType.Name}");
            sb.AppendLine("    {");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Required designer variable.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        private System.ComponentModel.IContainer components = null;");
            sb.AppendLine("");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Clean up any resources being used.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"disposing\">true if managed resources should be disposed; otherwise, false.</param>");
            sb.AppendLine("        protected override void Dispose(bool disposing)");
            sb.AppendLine("        {");
            sb.AppendLine("            if (disposing && (components != null))");
            sb.AppendLine("            {");
            sb.AppendLine("                components.Dispose();");
            sb.AppendLine("            }");
            sb.AppendLine("            base.Dispose(disposing);");
            sb.AppendLine("        }");
            sb.AppendLine("");
            sb.AppendLine("        #region Windows Form Designer generated code");
            sb.AppendLine("");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Required method for Designer support - do not modify");
            sb.AppendLine("        /// the contents of this method with the code editor.");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        private void InitializeComponent()");
            sb.AppendLine("        {");

            InitializeVariables(sb, allControls);
            InitializeControlsProperties(sb, allControls);

            sb.AppendLine("            this.PerformLayout();");
            sb.AppendLine("        }");
            sb.AppendLine("");
            sb.AppendLine("        #endregion");

            DeclareVariables(sb, allControls);

            sb.AppendLine("    }");
            sb.AppendLine("}");

            return(sb.ToString());
        }