예제 #1
0
        private void AppendMemberDoc(ScriptBuilder sb, MemberInfo member)
        {
            var provider = GetXmlDocProvider(member.DeclaringType.Assembly);
            if (provider == null) {
                return;
            }

            var doc = provider.GetDocumentation(member);
            if (string.IsNullOrWhiteSpace(doc)) {
                return;
            }

            sb.AppendLine();
            sb.AppendFormatIndented("/**");
            sb.AppendLine();
            sb.AppendFormatIndented(" * {0}", doc);
            sb.AppendLine();
            sb.AppendFormatIndented(" */");
            sb.AppendLine();
        }
예제 #2
0
        private void AppendMemberDoc(ScriptBuilder sb, MemberInfo member)
        {
            var provider = GetXmlDocProvider(member.DeclaringType.Assembly);

            if (provider == null)
            {
                return;
            }

            var doc = provider.GetDocumentation(member);

            if (string.IsNullOrEmpty(doc))
            {
                return;
            }

            sb.AppendLine();
            sb.AppendFormatIndented("/**");
            sb.AppendLine();
            sb.AppendFormatIndented(" * {0}", doc);
            sb.AppendLine();
            sb.AppendFormatIndented(" */");
            sb.AppendLine();
        }
예제 #3
0
        protected override void AppendClassDefinition(TsClass classModel, ScriptBuilder sb, TsGeneratorOutput generatorOutput)
        {
            string typeName   = this.GetTypeName(classModel);
            string visibility = this.GetTypeVisibility(classModel, typeName) ? "export " : "";

            sb.AppendFormatIndented(
                "{0}class {1} extends {2}",
                visibility,
                typeName,
                //all bottom-level classes must extend Backbone.Model.
                classModel.BaseType != null ? this.GetFullyQualifiedTypeName(classModel.BaseType) : "Backbone.Model");

            sb.AppendLine(" {");

            var members = new List <TsProperty>();

            if ((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties)
            {
                members.AddRange(classModel.Properties);
            }
            if ((generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields)
            {
                members.AddRange(classModel.Fields);
            }
            using (sb.IncreaseIndentation())
            {
                foreach (var property in members)
                {
                    if (property.IsIgnored)
                    {
                        continue;
                    }

                    sb.AppendLineIndented(string.Format(
                                              "get {0}(): {1} {{ return this.get(\"{0}\"); }}",
                                              this.GetPropertyName(property), this.GetPropertyType(property)));

                    sb.AppendLineIndented(string.Format(
                                              "set {0}(v: {1}) {{ this.set(\"{0}\", v); }}",
                                              this.GetPropertyName(property), this.GetPropertyType(property)));
                }
            }

            sb.AppendLineIndented("}");

            _generatedClasses.Add(classModel);
        }
        protected override void AppendClassDefinition(TsClass classModel, ScriptBuilder sb, TsGeneratorOutput generatorOutput)
        {
            string typeName = this.GetTypeName(classModel);
            string visibility = this.GetTypeVisibility(classModel, typeName) ? "export " : "";
            sb.AppendFormatIndented(
                "{0}class {1} extends {2}",
                visibility,
                typeName,
                //all bottom-level classes must extend Backbone.Model.
                classModel.BaseType != null ? this.GetFullyQualifiedTypeName(classModel.BaseType) : "Backbone.Model");

            sb.AppendLine(" {");

            var members = new List<TsProperty>();
            if ((generatorOutput & TsGeneratorOutput.Properties) == TsGeneratorOutput.Properties)
            {
                members.AddRange(classModel.Properties);
            }
            if ((generatorOutput & TsGeneratorOutput.Fields) == TsGeneratorOutput.Fields)
            {
                members.AddRange(classModel.Fields);
            }
            using (sb.IncreaseIndentation())
            {
                foreach (var property in members)
                {
                    if (property.IsIgnored)
                    {
                        continue;
                    }

                    sb.AppendLineIndented(string.Format(
                        "get {0}(): {1} {{ return this.get(\"{0}\"); }}",
                        this.GetPropertyName(property), this.GetPropertyType(property)));

                    sb.AppendLineIndented(string.Format(
                        "set {0}(v: {1}) {{ this.set(\"{0}\", v); }}",
                        this.GetPropertyName(property), this.GetPropertyType(property)));
                }
            }

            sb.AppendLineIndented("}");

            _generatedClasses.Add(classModel);
        }
예제 #5
0
        private void AppendClassDef(TsClass classModel, ScriptBuilder sb, TsGeneratorOutput generatorOutput)
        {
            AddNamespaceHeader(classModel.Name, sb);

            var typeName   = this.GetTypeName(classModel);
            var visibility = this.GetTypeVisibility(classModel, typeName) ? "export " : "";

            AddRequestRenameInformation(sb, classModel);
            AddDocCommentForCustomJsonConverter(sb, classModel);
            _docAppender.AppendClassDoc(sb, classModel, typeName);

            sb.AppendFormatIndented("{0}class {1}", visibility, typeName);
            if (CsharpTypeInfoProvider.StringAbstractions.Contains(classModel.Type))
            {
                sb.AppendLineIndented(" extends String {}");
                return;
            }

            void EnforceBaseClass <TInterface, TBase>()
            {
                if (classModel.BaseType != null)
                {
                    return;
                }
                if (classModel.Type == typeof(TBase))
                {
                    return;
                }
                if (typeof(TInterface).IsAssignableFrom(classModel.Type))
                {
                    classModel.BaseType = new TsClass(typeof(TBase));
                }
            }

            EnforceBaseClass <IAnalyzer, AnalyzerBase>();
            EnforceBaseClass <ITokenizer, TokenizerBase>();
            EnforceBaseClass <ITokenFilter, TokenFilterBase>();
            EnforceBaseClass <ICharFilter, CharFilterBase>();
            EnforceBaseClass <IProperty, PropertyBase>();
            EnforceBaseClass <IResponse, ResponseBase>();

            if (classModel.BaseType != null)
            {
                sb.AppendFormat(" extends {0}", this.GetFullyQualifiedTypeName(classModel.BaseType));
            }

            var interfaces = classModel.Interfaces.Where(m => CsharpTypeInfoProvider.ExposedInterfaces.Contains(m.Type)).ToList();

            if (interfaces.Count > 0)
            {
                var implementations = interfaces.Select(GetFullyQualifiedTypeName).ToArray();
                var prefixFormat    = " implements {0}";

                sb.AppendFormat(prefixFormat, string.Join(" ,", implementations));
            }

            sb.AppendLine(" {");

            GenerateProperties(classModel, sb, generatorOutput);

            sb.AppendLineIndented("}");
            _generatedClasses.Add(classModel);

            //generate a closed cat response type (NEST uses catresponse<TRecord> for all)
            if (typeof(ICatRecord).IsAssignableFrom(classModel.Type))
            {
                var catResponseName = classModel.Type.Name.Replace("Record", "Response");
                AddNamespaceHeader(classModel.Name, sb);
                sb.AppendLineIndented($"class {catResponseName} extends ResponseBase {{");
                using (sb.IncreaseIndentation())
                    sb.AppendLineIndented($"records: {typeName}[];");
                sb.AppendLineIndented("}");
            }
        }