コード例 #1
0
        private void GenerateForm(Type type, FormScriptAttribute formScriptAttribute)
        {
            var codeNamespace = GetNamespace(type);

            cw.Indented("public partial class ");
            var generatedName = MakeFriendlyName(type, codeNamespace);
            generatedTypes.Add((codeNamespace.IsEmptyOrNull() ? "" : codeNamespace + ".") + generatedName);
            sb.AppendLine(" : PrefixedContext");

            cw.InBrace(delegate
            {
                cw.Indented("[InlineConstant] public const string FormKey = \"");
                sb.Append(formScriptAttribute.Key);
                sb.AppendLine("\";");
                sb.AppendLine();

                cw.Indented("public ");
                sb.Append(generatedName);
                sb.AppendLine("(string idPrefix) : base(idPrefix) {}");
                sb.AppendLine();

                foreach (var item in PropertyGrid.PropertyItemHelper.GetPropertyItemsFor(type))
                {
                    var editorType = item.EditorType ?? "String";

                    ExternalType scriptType = null;

                    foreach (var rootNamespace in RootNamespaces)
                    {
                        string wn = rootNamespace + "." + editorType;
                        if ((scriptType = (GetScriptType(wn) ?? GetScriptType(wn + "Editor"))) != null)
                            break;
                    }

                    if (scriptType == null &&
                        (scriptType = (GetScriptType(editorType) ?? GetScriptType(editorType + "Editor"))) == null)
                        continue;

                    var fullTypeName = scriptType.FullName;
                    if (type.FullName == "Serenity.Widget")
                        fullTypeName = "Serenity.Widget<any>";

                    var shortTypeName = ShortenFullName(scriptType, codeNamespace);

                    cw.Indented("public ");
                    sb.Append(shortTypeName);
                    sb.Append(" ");
                    sb.Append(item.Name);
                    sb.Append(" { ");
                    sb.Append("[InlineCode(\"{this}.w('");
                    sb.Append(item.Name);
                    sb.Append("', ");
                    sb.Append(fullTypeName);
                    sb.AppendLine(")\")] get; private set; }");
                }
            });
        }
コード例 #2
0
        private void GenerateForm(Type type, FormScriptAttribute formScriptAttribute)
        {
            var codeNamespace = GetNamespace(type);

            cw.Indented("export class ");
            var generatedName = MakeFriendlyName(type, codeNamespace);
            generatedTypes.Add((codeNamespace.IsEmptyOrNull() ? "" : codeNamespace + ".") + generatedName);

            sb.Append(" extends Serenity.PrefixedContext");
            cw.InBrace(delegate
            {
                cw.Indented("static formKey = '");
                sb.Append(formScriptAttribute.Key);
                sb.AppendLine("';");
                sb.AppendLine();
            });

            sb.AppendLine();

            cw.Indented("export interface ");
            MakeFriendlyName(type, codeNamespace);

            StringBuilder initializer = new StringBuilder("[");

            cw.InBrace(delegate
            {
                int j = 0;
                foreach (var item in Serenity.PropertyGrid.PropertyItemHelper.GetPropertyItemsFor(type))
                {
                    var editorType = item.EditorType ?? "String";

                    ExternalType scriptType = null;

                    foreach (var rootNamespace in RootNamespaces)
                    {
                        string wn = rootNamespace + "." + editorType;
                        if ((scriptType = (GetScriptType(wn) ?? GetScriptType(wn + "Editor"))) != null)
                            break;
                    }

                    if (scriptType == null &&
                        (scriptType = (GetScriptType(editorType) ?? GetScriptType(editorType + "Editor"))) == null)
                        continue;

                    var fullName = ShortenFullName(scriptType, codeNamespace);

                    if (j++ > 0)
                        initializer.Append(", ");

                    initializer.Append("['");
                    initializer.Append(item.Name);
                    initializer.Append("', () => ");
                    initializer.Append(fullName);
                    initializer.Append("]");

                    cw.Indented(item.Name);
                    sb.Append(": ");
                    sb.Append(fullName);
                    sb.AppendLine(";");
                }
            });

            initializer.Append("].forEach(x => Object.defineProperty(");
            MakeFriendlyName(type, codeNamespace, initializer);
            initializer.Append(".prototype, <string>x[0], { get: function () { return this.w(x[0], (x[1] as any)()); }, enumerable: true, configurable: true }));");

            sb.AppendLine();
            cw.IndentedLine(initializer.ToString());
        }
コード例 #3
0
        private void GenerateForm(Type type, FormScriptAttribute formScriptAttribute)
        {
            var codeNamespace = GetNamespace(type);

            cw.Indented("public partial class ");

            var identifier = type.Name;
            if (identifier.EndsWith(requestSuffix) &&
                type.IsSubclassOf(typeof(ServiceRequest)))
            {
                identifier = identifier.Substring(0,
                    identifier.Length - requestSuffix.Length) + "Form";
                this.fileIdentifier = identifier;
            }

            sb.Append(identifier);

            sb.AppendLine(" : PrefixedContext");

            cw.InBrace(delegate
            {
                cw.Indented("[InlineConstant] public const string FormKey = \"");
                sb.Append(formScriptAttribute.Key);
                sb.AppendLine("\";");
                sb.AppendLine();

                cw.Indented("public ");
                sb.Append(identifier);
                sb.AppendLine("(string idPrefix) : base(idPrefix) {}");
                sb.AppendLine();

                foreach (var item in PropertyGrid.PropertyItemHelper.GetPropertyItemsFor(type))
                {
                    var editorType = item.EditorType ?? "String";

                    ExternalType scriptType = null;

                    foreach (var rootNamespace in RootNamespaces)
                    {
                        string wn = rootNamespace + "." + editorType;
                        if ((scriptType = (GetScriptType(wn) ?? GetScriptType(wn + "Editor"))) != null)
                            break;
                    }

                    if (scriptType == null &&
                        (scriptType = (GetScriptType(editorType) ?? GetScriptType(editorType + "Editor"))) == null)
                        continue;

                    var fullTypeName = scriptType.FullName;
                    if (type.FullName == "Serenity.Widget")
                        fullTypeName = "Serenity.Widget<any>";

                    var shortTypeName = ShortenFullName(scriptType, codeNamespace);

                    cw.Indented("public ");
                    sb.Append(shortTypeName);
                    sb.Append(" ");
                    sb.Append(item.Name);
                    sb.Append(" { ");
                    sb.Append("[InlineCode(\"{this}.w('");
                    sb.Append(item.Name);
                    sb.Append("', ");
                    sb.Append(fullTypeName);
                    sb.AppendLine(")\")] get; private set; }");
                }
            });
        }