public void WriteServerCode(CodeBuilder cb) { var orderedMembers = TopologicalSort(members); foreach (var us in serverUsings) { cb.AppendLine("using " + us.Key + ";"); } cb.AppendLine(); if (!string.IsNullOrEmpty(nmspace)) { cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine(); } cb.AppendFormat("public partial class " + className) .Append(" : ") .Append(ServerInheritanceList) .Append(" {").AppendLine().Indent() .AppendLine("partial void Constructed();").AppendLine() .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();").AppendLine() .AppendLine("private Position position = PositionHelper.NotPositioned;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position { get { return position; } set { position = value; } }").AppendLine(); WriteIdProperty(cb, true, this, orderedMembers); cb.AppendLine(); WriteGetConfig(cb, this, orderedMembers); cb.AppendLine(); foreach (var m in orderedMembers) { m.WriteCode(this, MemberCodePoint.ServerDefinition, cb); } cb.AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent() .AppendLine("get {").Indent() .AppendLine("if (string.IsNullOrEmpty(id))").Indent() .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent() .AppendLine("return " + MainRenderFunctionName + "();").Outdent() .AppendLine("}").Outdent() .AppendLine("}").AppendLine(); WriteServerConstructor(cb, this); cb.AppendLine(); WriteServerDependenciesAvailable(cb, this, orderedMembers); cb.Outdent().AppendLine("}"); if (!string.IsNullOrEmpty(nmspace)) { cb.Outdent().AppendLine("}"); } }
internal static void WriteClientDependenciesAvailable(CodeBuilder cb, ITemplate tpl, IList <IMember> orderedMembers) { cb.AppendLine("public void DependenciesAvailable() {").Indent() .AppendLine("if (" + ParserUtils.ConfigObjectName + " != null) {").Indent() .AppendLine("this.id = (string)" + ParserUtils.ConfigObjectName + "[\"id\"];"); foreach (var m in orderedMembers) { m.WriteCode(tpl, MemberCodePoint.TransferConstructor, cb); } cb.AppendLine("Constructed();") .AppendLine("AttachSelf();") .Outdent().AppendLine("}") .AppendLine("else {").Indent(); if (tpl.EnableClientCreate) { cb.AppendLine("this.position = PositionHelper.NotPositioned;"); foreach (var m in orderedMembers) { m.WriteCode(tpl, MemberCodePoint.ClientConstructor, cb); } cb.AppendLine("Constructed();"); } else { cb.AppendLine("throw new Exception(\"This control must be created server-side\");"); } cb.Outdent().AppendLine("}") .Outdent().AppendLine("}"); }
public void WriteClientCode(CodeBuilder cb) { var orderedMembers = TopologicalSort(members); foreach (var us in clientUsings) cb.AppendLine("using " + us.Key + ";"); cb.AppendLine(); if (!string.IsNullOrEmpty(nmspace)) cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine(); cb.AppendFormat("public partial class " + className) .Append(" : ") .Append(ClientInheritanceList) .Append(" {").AppendLine().Indent() .AppendLine("partial void Constructed();") .AppendLine("partial void Attached();").AppendLine() .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();") .AppendLine("private JsDictionary " + ParserUtils.ConfigObjectName + ";") .AppendLine() .AppendLine("private Position position;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position {").Indent() .AppendLine("get { return isAttached ? PositionHelper.GetPosition(GetElement()) : position; }") .AppendLine("set {").Indent() .AppendLine("position = value;") .AppendLine("if (isAttached)").Indent() .AppendLine("PositionHelper.ApplyPosition(GetElement(), value);").Outdent() .Outdent().AppendLine("}") .Outdent().AppendLine("}").AppendLine() .AppendLine("private bool isAttached = false;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Element GetElement() { return isAttached ? Document.GetElementById(id) : null; }").AppendLine(); WriteIdProperty(cb, false, this, orderedMembers); cb.AppendLine(); foreach (var m in orderedMembers) m.WriteCode(this, MemberCodePoint.ClientDefinition, cb); WriteAttachSelf(cb, this, orderedMembers); cb.AppendLine(); if (enableClientCreate) { WriteAttach(cb, this, orderedMembers); cb.AppendLine() .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent() .AppendLine("get {").Indent() .AppendLine("if (string.IsNullOrEmpty(id))").Indent() .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent() .AppendLine("return " + MainRenderFunctionName + "();").Outdent() .AppendLine("}").Outdent() .AppendLine("}").AppendLine() .AppendLine("[AlternateSignature]") .AppendLine("public " + className + "() {}"); } WriteClientConstructor(cb, this); cb.AppendLine(); WriteClientDependenciesAvailable(cb, this, orderedMembers); cb.Outdent().AppendLine("}"); if (!string.IsNullOrEmpty(nmspace)) cb.Outdent().AppendLine("}"); }
public void WriteServerCode(CodeBuilder cb) { var orderedMembers = TopologicalSort(members); foreach (var us in serverUsings) cb.AppendLine("using " + us.Key + ";"); cb.AppendLine(); if (!string.IsNullOrEmpty(nmspace)) cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine(); cb.AppendFormat("public partial class " + className) .Append(" : ") .Append(ServerInheritanceList) .Append(" {").AppendLine().Indent() .AppendLine("partial void Constructed();").AppendLine() .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();").AppendLine() .AppendLine("private Position position = PositionHelper.NotPositioned;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position { get { return position; } set { position = value; } }").AppendLine(); WriteIdProperty(cb, true, this, orderedMembers); cb.AppendLine(); WriteGetConfig(cb, this, orderedMembers); cb.AppendLine(); foreach (var m in orderedMembers) m.WriteCode(this, MemberCodePoint.ServerDefinition, cb); cb.AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent() .AppendLine("get {").Indent() .AppendLine("if (string.IsNullOrEmpty(id))").Indent() .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent() .AppendLine("return " + MainRenderFunctionName + "();").Outdent() .AppendLine("}").Outdent() .AppendLine("}").AppendLine(); WriteServerConstructor(cb, this); cb.AppendLine(); WriteServerDependenciesAvailable(cb, this, orderedMembers); cb.Outdent().AppendLine("}"); if (!string.IsNullOrEmpty(nmspace)) cb.Outdent().AppendLine("}"); }
internal static void WriteClientDependenciesAvailable(CodeBuilder cb, ITemplate tpl, IList<IMember> orderedMembers) { cb.AppendLine("public void DependenciesAvailable() {").Indent() .AppendLine("if (" + ParserUtils.ConfigObjectName + " != null) {").Indent() .AppendLine("this.id = (string)" + ParserUtils.ConfigObjectName + "[\"id\"];"); foreach (var m in orderedMembers) m.WriteCode(tpl, MemberCodePoint.TransferConstructor, cb); cb.AppendLine("Constructed();") .AppendLine("AttachSelf();") .Outdent().AppendLine("}") .AppendLine("else {").Indent(); if (tpl.EnableClientCreate) { cb.AppendLine("this.position = PositionHelper.NotPositioned;"); foreach (var m in orderedMembers) m.WriteCode(tpl, MemberCodePoint.ClientConstructor, cb); cb.AppendLine("Constructed();"); } else { cb.AppendLine("throw new Exception(\"This control must be created server-side\");"); } cb.Outdent().AppendLine("}") .Outdent().AppendLine("}"); }
public void WriteClientCode(CodeBuilder cb) { var orderedMembers = TopologicalSort(members); foreach (var us in clientUsings) { cb.AppendLine("using " + us.Key + ";"); } cb.AppendLine(); if (!string.IsNullOrEmpty(nmspace)) { cb.AppendFormat("namespace {0} {{", nmspace).Indent().AppendLine(); } cb.AppendFormat("public partial class " + className) .Append(" : ") .Append(ClientInheritanceList) .Append(" {").AppendLine().Indent() .AppendLine("partial void Constructed();") .AppendLine("partial void Attached();").AppendLine() .AppendLine("private Dictionary<string, IControl> controls = new Dictionary<string, IControl>();") .AppendLine("private JsDictionary " + ParserUtils.ConfigObjectName + ";") .AppendLine() .AppendLine("private Position position;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Position Position {").Indent() .AppendLine("get { return isAttached ? PositionHelper.GetPosition(GetElement()) : position; }") .AppendLine("set {").Indent() .AppendLine("position = value;") .AppendLine("if (isAttached)").Indent() .AppendLine("PositionHelper.ApplyPosition(GetElement(), value);").Outdent() .Outdent().AppendLine("}") .Outdent().AppendLine("}").AppendLine() .AppendLine("private bool isAttached = false;") .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "Element GetElement() { return isAttached ? Document.GetElementById(id) : null; }").AppendLine(); WriteIdProperty(cb, false, this, orderedMembers); cb.AppendLine(); foreach (var m in orderedMembers) { m.WriteCode(this, MemberCodePoint.ClientDefinition, cb); } WriteAttachSelf(cb, this, orderedMembers); cb.AppendLine(); if (enableClientCreate) { WriteAttach(cb, this, orderedMembers); cb.AppendLine() .AppendLine("public " + (generateImplementationsAsOverrides ? "override " : "") + "string Html {").Indent() .AppendLine("get {").Indent() .AppendLine("if (string.IsNullOrEmpty(id))").Indent() .AppendLine("throw new InvalidOperationException(\"Must assign Id before rendering.\");").Outdent() .AppendLine("return " + MainRenderFunctionName + "();").Outdent() .AppendLine("}").Outdent() .AppendLine("}").AppendLine() .AppendLine("[AlternateSignature]") .AppendLine("public " + className + "() {}"); } WriteClientConstructor(cb, this); cb.AppendLine(); WriteClientDependenciesAvailable(cb, this, orderedMembers); cb.Outdent().AppendLine("}"); if (!string.IsNullOrEmpty(nmspace)) { cb.Outdent().AppendLine("}"); } }