diff --git a/samples/SampleModels/Models/NullableAttribute.cs b/samples/SampleModels/Models/NullableAttribute.cs index c71a8a4..9bf3d09 100644 --- a/samples/SampleModels/Models/NullableAttribute.cs +++ b/samples/SampleModels/Models/NullableAttribute.cs @@ -3,7 +3,7 @@ namespace SampleModels.Models { [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] - public class NullableAttribute: Attribute + public class NullableAttribute : Attribute { } } diff --git a/samples/SampleModels/Models/Person.cs b/samples/SampleModels/Models/Person.cs index dc1c5c0..43c655f 100644 --- a/samples/SampleModels/Models/Person.cs +++ b/samples/SampleModels/Models/Person.cs @@ -42,5 +42,7 @@ public class Person [UnknownObject] [Optional] public object ShouldBeUnknown { get; set; } + + [Optional] public Dictionary Pairs { get; set; } } } diff --git a/samples/SampleModels/Models/TypeUnions.cs b/samples/SampleModels/Models/TypeUnions.cs index 92b8587..ccdc3da 100644 --- a/samples/SampleModels/Models/TypeUnions.cs +++ b/samples/SampleModels/Models/TypeUnions.cs @@ -2,7 +2,7 @@ namespace SampleModels.Models { [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] - public class TypeUnionAttribute: Attribute + public class TypeUnionAttribute : Attribute { public TypeUnionAttribute(params string[] args) { } public TypeUnionAttribute(params double[] args) { } diff --git a/samples/SampleModels/Typescript/Person.ts b/samples/SampleModels/Typescript/Person.ts index 04cc2b8..8e76124 100644 --- a/samples/SampleModels/Typescript/Person.ts +++ b/samples/SampleModels/Typescript/Person.ts @@ -30,4 +30,5 @@ export interface Person { typeUnionDouble: 1.2 | 2.2; shouldBeAny: any; shouldBeUnknown?: unknown; + pairs?: Map; } diff --git a/src/Onbox.TypeSharp/Onbox.TypeSharp.csproj b/src/Onbox.TypeSharp/Onbox.TypeSharp.csproj index 3fb56a8..ff2737a 100644 --- a/src/Onbox.TypeSharp/Onbox.TypeSharp.csproj +++ b/src/Onbox.TypeSharp/Onbox.TypeSharp.csproj @@ -6,7 +6,7 @@ TypeSharp false Onbox.TypeSharp - 0.3.9 + 0.4.0 Thiago Almeida Onbox Command line app to convert CSharp data models into Typescript diff --git a/src/Onbox.TypeSharp/Services/TypeConverter.cs b/src/Onbox.TypeSharp/Services/TypeConverter.cs index 0ae6e6d..9606715 100644 --- a/src/Onbox.TypeSharp/Services/TypeConverter.cs +++ b/src/Onbox.TypeSharp/Services/TypeConverter.cs @@ -116,6 +116,7 @@ public string ConvertModel(Type type) foreach (var prop in props) { var contextPropType = prop.PropertyType; + if (this.propertyUtils.ShouldImport(contextPropType) && contextPropType != type) { // Collection needs to be checked for its generic item type @@ -224,6 +225,8 @@ public string ConvertModel(Type type) } classBodyBuilder.AppendLine("}"); + importStatments = string.Join("\n", importStatments.Split("\n").Where(l => l.StartsWith("export { Object } from \"./Object\"") == false).Distinct()); + var result = importStatments.Any() ? importStatments + Environment.NewLine + classBodyBuilder.ToString() : classBodyBuilder.ToString(); return result; } diff --git a/src/Onbox.TypeSharp/Services/TypeNamingService.cs b/src/Onbox.TypeSharp/Services/TypeNamingService.cs index 6f5d43d..49ebc3c 100644 --- a/src/Onbox.TypeSharp/Services/TypeNamingService.cs +++ b/src/Onbox.TypeSharp/Services/TypeNamingService.cs @@ -84,6 +84,14 @@ public string GetPropertyTypeName(Type type) { return "CustomEvent"; } + else if (this.typeUtils.IsCustomPropObjects(type)) + { + return "Map"; + } + //else if (this.typeUtils.IsDictionary(type)) + //{ + // Implement Dictionaries in the future + //} else if (this.typeUtils.IsCollection(type)) { var arg = this.genericTypeUtils.GetGenericType(type); diff --git a/src/Onbox.TypeSharp/Services/TypeUtils.cs b/src/Onbox.TypeSharp/Services/TypeUtils.cs index c5a0b1d..d0f903c 100644 --- a/src/Onbox.TypeSharp/Services/TypeUtils.cs +++ b/src/Onbox.TypeSharp/Services/TypeUtils.cs @@ -99,5 +99,23 @@ internal bool IsUnion(Type type) return false; } + + internal bool IsCustomPropObjects(Type type) + { + var startsWithLongFormat = type.FullName?.StartsWith("System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib"); + var includesObjectFormat = type.FullName?.Contains("[System.Object"); + if (startsWithLongFormat == true && includesObjectFormat == true) + { + return true; + } + + var startsWithSimpleFormat = type.FullName?.StartsWith("System.Collections.Generic.Dictionary`2[System.String,System.Object]"); + if (startsWithSimpleFormat == true) + { + return true; + } + + return false; + } } }