public void Simple() { var tsInterface = new TsInterface { ExportKind = TsExportKind.Named, Name = "SomeInterface", Properties = new[] { new TsPropertySignature { Name = "FirstProperty", Type = TsPredefinedType.Boolean() }, new TsPropertySignature { Name = "SecondProperty", Type = TsPredefinedType.Number(), Optional = true }, new TsPropertySignature { Name = "ThirdProperty", Type = new TsUnionType(TsPredefinedType.String(), new TsNull()) }, new TsPropertySignature { Name = "FourthProperty", Type = new TsArrayType { ElementType = new TsUnionType(TsPredefinedType.String(), new TsNull()) } } } }; tsInterface.ShouldBeTranslatedTo("export interface SomeInterface {", " FirstProperty: boolean;", " SecondProperty?: number;", " ThirdProperty: (string | null);", " FourthProperty: (string | null)[];", "}"); }
private void PopulateProperties(TsInterface type, IReadOnlyDictionary <Type, TsTypeDefinitionBase> typeDict) { var properties = this._propertyProvider.GetProperties(type.CSharpType); foreach (var propertyInfo in properties) { type.Properties.Add(this._propertyProvider.CreateInterfaceProperty(propertyInfo, GetTsType(propertyInfo.PropertyType, typeDict))); } }
public bool InterfaceGenerate(TsInterfaceEntity entity) { var tsInterface = new TsInterface(entity); var pageContent = tsInterface.TransformText(); File.WriteAllText(FileName, pageContent); return(true); }
private string GetMethodsString(TsInterface netInterface) { var methods = string.Join(_config.NewLines(2), netInterface.Methods.Select(m => WriteMethod(m, false))); if (!string.IsNullOrWhiteSpace(methods)) { methods = methods.Indent(_indent) + _config.NewLine; } return(methods); }
private string GetEventsString(TsInterface netInterface) { var events = string.Join(_config.NewLine, netInterface.Events.Select(p => WriteEvent(p) + ";")); if (!string.IsNullOrWhiteSpace(events)) { events = events.Indent(_indent) + _config.NewLine; } return(events); }
//interfaces can't have properties //private string GetPropertiesString(TsInterface netInterface) //{ // var properties = string.Join(_config.NewLine, // netInterface.Properties.Select(p => WriteField(p, p.IsNullable) + ";")); // if (!string.IsNullOrWhiteSpace(properties)) // properties = properties.Indent(_config.Indent) + _config.NewLine; // return properties; //} private string GetFieldsString(TsInterface netInterface) { var fields = string.Join(_config.NewLine, netInterface.Fields.Select(f => WriteField(f, f.IsNullable) + ";")); if (!string.IsNullOrWhiteSpace(fields)) { fields = fields.Indent(_indent) + _config.NewLine; } return(fields); }
public static MetadataInfoModel GetMetaDataInfoModel(TsInterface type, Compilation compilation) { MetadataInfoModel model = new MetadataInfoModel { Name = $"{type.Name.Name}Metadata" }; foreach (var property in type.Properties) { model._propertyInfoModels.Add(property.CreatePropertyInfoModel(compilation)); } return(model); }
public virtual string WriteInterface(TsInterface netInterface) { var exportStr = netInterface.IsPublic ? "export " : ""; var extends = netInterface.BaseTypes.Any() ? " extends " + string.Join(", ", netInterface.BaseTypes.Select(WriteTypeName)) : ""; var generics = netInterface.GenericParameters.Any() ? $"<{string.Join(", ", netInterface.GenericParameters.Select(WriteGenericParameterName))}>" : ""; var methods = GetMethodsString(netInterface); var fields = GetFieldsString(netInterface); var events = GetEventsString(netInterface); var body = JoinBodyText(fields, events, methods); return($"{exportStr}interface {netInterface.Name}{generics}{extends}" + _config.NewLine + @"{" + _config.NewLine + body + @"}"); }
private static void AddContent(StringBuilder builder, string indententionString, TsInterface type) { builder.Append(indententionString); if (type.IsExport) { builder.Append("export "); } builder.Append("interface "); builder.Append(type.Name); if (type.IsGeneric) { builder.Append("<" + string.Join(", ", type.GenericArguments.Select(x => x.Name)) + ">"); } if (type.BaseType != null) { builder.Append($" extends {GetGenericContent(type.BaseType)}"); } builder.Append(" {"); builder.AppendLine(); foreach (var property in type.Properties) { builder.Append($"{indententionString}\t"); builder.Append(GenerateContent(property)); builder.AppendLine(); } builder.Append(indententionString + "}"); }
private void PopulateBaseType(TsInterface type, IReadOnlyDictionary <Type, TsTypeDefinitionBase> typeDict) { PopulateBaseType(type.CSharpType.BaseType, t => type.BaseType = t, typeDict); }