public override void Visit(RtIdentifier node) { if (node == null) { return; } Write(node.IdentifierName); if (node.IsNullable) { Write("?"); } }
/// <summary> /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to /// WriterWrapper (3rd argument) using TypeResolver if necessary /// </summary> /// <param name="element">Element code to be generated to output</param> /// <param name="result">Resulting node</param> /// <param name="resolver">Type resolver</param> public override RtField GenerateNode(MemberInfo element, RtField result, TypeResolver resolver) { if (Context.CurrentBlueprint.IsIgnored(element)) { return(null); } result.IsStatic = element.IsStatic(); result.Order = Context.CurrentBlueprint.GetOrder(element); var doc = Context.Documentation.GetDocumentationMember(element); if (doc != null) { RtJsdocNode jsdoc = new RtJsdocNode { Description = doc.Summary.Text }; result.Documentation = jsdoc; } var t = GetType(element); RtTypeName type = null; var propName = new RtIdentifier(element.Name); bool isNameOverridden = false; var tp = Context.CurrentBlueprint.ForMember <TsPropertyAttribute>(element); if (tp != null) { if (tp.StrongType != null) { type = resolver.ResolveTypeName(tp.StrongType); } else if (!string.IsNullOrEmpty(tp.Type)) { type = new RtSimpleTypeName(tp.Type); } type = tp.TypeInferers.Infer(element, resolver) ?? type; if (!string.IsNullOrEmpty(tp.Name)) { propName.IdentifierName = tp.Name; isNameOverridden = true; } if (tp.NilForceNullable.HasValue && !Context.SpecialCase) { propName.IsNullable = tp.NilForceNullable.Value; } } if (type == null) { type = resolver.ResolveTypeName(t); } if (tp != null && !tp.NilForceNullable.HasValue) { if (!propName.IsNullable && t.IsNullable() && !Context.SpecialCase) { propName.IsNullable = true; } } if (!isNameOverridden) { if (element is PropertyInfo) { propName.IdentifierName = Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName); } propName.IdentifierName = Context.CurrentBlueprint.CamelCaseFromAttribute(element, propName.IdentifierName); propName.IdentifierName = Context.CurrentBlueprint.PascalCaseFromAttribute(element, propName.IdentifierName); } if (this.Context.Location.CurrentClass != null) { this.FillInitialization(element, result, resolver, t, tp); } result.Identifier = propName; result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier(); result.Type = type; AddDecorators(result, Context.CurrentBlueprint.DecoratorsFor(element)); return(result); }
public abstract void Visit(RtIdentifier node);
public override void Visit(RtIdentifier node) { }
public abstract T Visit(RtIdentifier node);
/// <summary> /// Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to /// WriterWrapper (3rd argument) using TypeResolver if necessary /// </summary> /// <param name="element">Element code to be generated to output</param> /// <param name="result">Resulting node</param> /// <param name="resolver">Type resolver</param> public override RtField GenerateNode(MemberInfo element, RtField result, TypeResolver resolver) { if (element.IsIgnored()) { return(null); } result.IsStatic = element.IsStatic(); var doc = Context.Documentation.GetDocumentationMember(element); if (doc != null) { RtJsdocNode jsdoc = new RtJsdocNode { Description = doc.Summary.Text }; result.Documentation = jsdoc; } var t = GetType(element); RtTypeName type = null; var propName = new RtIdentifier(element.Name); var tp = ConfigurationRepository.Instance.ForMember <TsPropertyAttribute>(element); if (tp != null) { if (tp.StrongType != null) { type = resolver.ResolveTypeName(tp.StrongType); } else if (!string.IsNullOrEmpty(tp.Type)) { type = new RtSimpleTypeName(tp.Type); } if (!string.IsNullOrEmpty(tp.Name)) { propName.IdentifierName = tp.Name; } if (tp.ForceNullable && element.DeclaringType.IsExportingAsInterface() && !Context.SpecialCase) { propName.IsNullable = true; } } if (type == null) { type = resolver.ResolveTypeName(t); } if (!propName.IsNullable && t.IsNullable() && element.DeclaringType.IsExportingAsInterface() && !Context.SpecialCase) { propName.IsNullable = true; } if (element is PropertyInfo) { propName.IdentifierName = Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName); } propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName); propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName); result.Identifier = propName; result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier(); result.Type = type; return(result); }