-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
190 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
TypeScript.ContractGenerator.Tests/Files/Options.Expected/global-nullable-disabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
export type GlobalNullableRootType = { | ||
int: number; | ||
nullableInt?: null | number; | ||
nullableInts?: null | Nullable<number>[]; | ||
intGeneric?: null | GenericClass<number>; | ||
nullableIntGeneric?: null | GenericClass<Nullable<number>>; | ||
}; | ||
export type Nullable<T> = { | ||
hasValue: boolean; | ||
value: T; | ||
}; | ||
export type GenericClass<T> = { | ||
genericType?: T; | ||
}; |
15 changes: 15 additions & 0 deletions
15
TypeScript.ContractGenerator.Tests/Files/Options.Expected/global-nullable-disabled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
export type GlobalNullableRootType = { | ||
int: number; | ||
nullableInt?: null | number; | ||
nullableInts?: null | Nullable<number>[]; | ||
intGeneric?: null | GenericClass<number>; | ||
nullableIntGeneric?: null | GenericClass<Nullable<number>>; | ||
}; | ||
export type Nullable<T> = { | ||
hasValue: boolean; | ||
value: T; | ||
}; | ||
export type GenericClass<T> = { | ||
genericType?: T; | ||
}; |
11 changes: 11 additions & 0 deletions
11
TypeScript.ContractGenerator.Tests/Files/Options.Expected/global-nullable-enabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export type GlobalNullableRootType = { | ||
int: number; | ||
nullableInt?: ?number; | ||
nullableInts?: ??number[]; | ||
intGeneric?: ?GenericClass<number>; | ||
nullableIntGeneric?: ?GenericClass<?number>; | ||
}; | ||
export type GenericClass<T> = { | ||
genericType?: T; | ||
}; |
11 changes: 11 additions & 0 deletions
11
TypeScript.ContractGenerator.Tests/Files/Options.Expected/global-nullable-enabled.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
export type GlobalNullableRootType = { | ||
int: number; | ||
nullableInt?: Nullable<number>; | ||
nullableInts?: Nullable<Nullable<number>[]>; | ||
intGeneric?: Nullable<GenericClass<number>>; | ||
nullableIntGeneric?: Nullable<GenericClass<Nullable<number>>>; | ||
}; | ||
export type GenericClass<T> = { | ||
genericType?: T; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
TypeScript.ContractGenerator.Tests/Types/GlobalNullableRootType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace SkbKontur.TypeScript.ContractGenerator.Tests.Types | ||
{ | ||
public class GlobalNullableRootType | ||
{ | ||
public int Int { get; set; } | ||
public int? NullableInt { get; set; } | ||
public int?[] NullableInts { get; set; } | ||
public GenericClass<int> IntGeneric { get; set; } | ||
public GenericClass<int?> NullableIntGeneric { get; set; } | ||
} | ||
|
||
public class GenericClass<T> | ||
{ | ||
public T GenericType { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
TypeScript.ContractGenerator/TypeBuilders/NullableTypeBuildingContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
|
||
using SkbKontur.TypeScript.ContractGenerator.CodeDom; | ||
|
||
namespace SkbKontur.TypeScript.ContractGenerator.TypeBuilders | ||
{ | ||
public class NullableTypeBuildingContext : ITypeBuildingContext | ||
{ | ||
public NullableTypeBuildingContext(Type nullableType) | ||
{ | ||
itemType = nullableType.GetGenericArguments()[0]; | ||
} | ||
|
||
public bool IsDefinitionBuilt => true; | ||
|
||
public void Initialize(ITypeGenerator typeGenerator) | ||
{ | ||
} | ||
|
||
public void BuildDefinition(ITypeGenerator typeGenerator) | ||
{ | ||
} | ||
|
||
public FlowTypeType ReferenceFrom(FlowTypeUnit targetUnit, ITypeGenerator typeGenerator) | ||
{ | ||
var itemFlowType = typeGenerator.ResolveType(itemType).ReferenceFrom(targetUnit, typeGenerator); | ||
return new FlowTypeNullableType(itemFlowType); | ||
} | ||
|
||
private readonly Type itemType; | ||
} | ||
} |