Skip to content

Commit

Permalink
Merge branch 'add-builtin-types'
Browse files Browse the repository at this point in the history
  • Loading branch information
fakefeik committed Feb 22, 2019
2 parents 3c3f9fc + d992c2a commit 716d71f
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 645 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;

using SkbKontur.TypeScript.ContractGenerator.CodeDom;
using SkbKontur.TypeScript.ContractGenerator.TypeBuilders;

namespace SkbKontur.TypeScript.ContractGenerator.Tests.CustomTypeGenerators
{
public class CollectionTypeBuildingContext : ITypeBuildingContext
{
public CollectionTypeBuildingContext(Type arrayType)
{
elementType = arrayType.GetGenericArguments()[0];
}

public static bool Accept(Type type)
{
return type.IsGenericType &&
type.GetGenericArguments().Length == 1 &&
type.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICollection<>));
}

public bool IsDefinitionBuilt => true;

public void Initialize(ITypeGenerator typeGenerator)
{
}

public void BuildDefinition(ITypeGenerator typeGenerator)
{
}

public FlowTypeType ReferenceFrom(FlowTypeUnit targetUnit, ITypeGenerator typeGenerator)
{
var itemType = typeGenerator.ResolveType(elementType).ReferenceFrom(targetUnit, typeGenerator);
return new FlowTypeArrayType(itemType);
}

private readonly Type elementType;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ public string GetTypeLocation(Type type)

public ITypeBuildingContext ResolveType(string initialUnitPath, Type type, IFlowTypeUnitFactory unitFactory)
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
return new ListTypeBuildingContext(type);
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>))
return new DictionaryTypeBuildingContext(type);
if (type == typeof(Guid))
if (CollectionTypeBuildingContext.Accept(type))
return new CollectionTypeBuildingContext(type);

if (type == typeof(TimeSpan))
return new StringBuildingContext();

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type ArrayRootType = {
ints?: null | number[];
nullableInts?: null | Array<null | number>;
byteArray?: null | string;
nullableByteArray?: null | Array<null | Byte>;
nullableByteArray?: null | Array<null | number>;
enums?: null | AnotherEnum[];
nullableEnums?: null | Array<null | AnotherEnum>;
strings?: null | string[];
Expand All @@ -12,8 +12,7 @@ export type ArrayRootType = {
customTypesDict?: null | {
[key: string]: AnotherCustomType;
};
};
export type Byte = {
set?: null | string[];
};
export type AnotherEnum = 'B' | 'C';
export const AnotherEnums = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type ArrayRootType = {
ints?: null | number[];
nullableInts?: null | Array<null | number>;
byteArray?: null | string;
nullableByteArray?: null | Array<null | Byte>;
nullableByteArray?: null | Array<null | number>;
enums?: null | AnotherEnum[];
nullableEnums?: null | Array<null | AnotherEnum>;
strings?: null | string[];
Expand All @@ -12,8 +12,7 @@ export type ArrayRootType = {
customTypesDict?: null | {
[key in string]?: AnotherCustomType;
};
};
export type Byte = {
set?: null | string[];
};
export type AnotherEnum = 'B' | 'C';
export const AnotherEnums = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,19 @@

export type SimpleNullableRootType = {
long?: null | string;
uLong?: null | UInt64;
uLong?: null | string;
int?: null | number;
uInt?: null | UInt32;
short?: null | Int16;
uShort?: null | UInt16;
uInt?: null | number;
short?: null | number;
uShort?: null | number;
bool?: null | boolean;
double?: null | Double;
double?: null | number;
decimal?: null | number;
float?: null | Single;
byte?: null | Byte;
sByte?: null | SByte;
char?: null | Char;
float?: null | number;
byte?: null | number;
sByte?: null | number;
char?: null | string;
dateTime?: null | (Date | string);
timeSpan?: null | TimeSpan;
timeSpan?: null | string;
guid?: null | string;
};
export type UInt64 = {
};
export type UInt32 = {
};
export type Int16 = {
};
export type UInt16 = {
};
export type Double = {
};
export type Single = {
};
export type Byte = {
};
export type SByte = {
};
export type Char = {
};
export type TimeSpan = {
ticks: string;
days: number;
hours: number;
milliseconds: number;
minutes: number;
seconds: number;
totalDays: Double;
totalHours: Double;
totalMilliseconds: Double;
totalMinutes: Double;
totalSeconds: Double;
};
Original file line number Diff line number Diff line change
@@ -1,50 +1,19 @@

export type SimpleNullableRootType = {
long?: null | string;
uLong?: null | UInt64;
uLong?: null | string;
int?: null | number;
uInt?: null | UInt32;
short?: null | Int16;
uShort?: null | UInt16;
uInt?: null | number;
short?: null | number;
uShort?: null | number;
bool?: null | boolean;
double?: null | Double;
double?: null | number;
decimal?: null | number;
float?: null | Single;
byte?: null | Byte;
sByte?: null | SByte;
char?: null | Char;
float?: null | number;
byte?: null | number;
sByte?: null | number;
char?: null | string;
dateTime?: null | (Date | string);
timeSpan?: null | TimeSpan;
timeSpan?: null | string;
guid?: null | string;
};
export type UInt64 = {
};
export type UInt32 = {
};
export type Int16 = {
};
export type UInt16 = {
};
export type Double = {
};
export type Single = {
};
export type Byte = {
};
export type SByte = {
};
export type Char = {
};
export type TimeSpan = {
ticks: string;
days: number;
hours: number;
milliseconds: number;
minutes: number;
seconds: number;
totalDays: Double;
totalHours: Double;
totalMilliseconds: Double;
totalMinutes: Double;
totalSeconds: Double;
};
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@

export type SimpleRootType = {
long: string;
uLong: UInt64;
uLong: string;
int: number;
uInt: UInt32;
short: Int16;
uShort: UInt16;
uInt: number;
short: number;
uShort: number;
bool: boolean;
double: Double;
float: Single;
double: number;
float: number;
decimal: number;
byte: Byte;
sByte: SByte;
char: Char;
byte: number;
sByte: number;
char: string;
string?: null | string;
dateTime: (Date | string);
timeSpan: TimeSpan;
timeSpan: string;
guid: string;
};
export type UInt64 = {
};
export type UInt32 = {
};
export type Int16 = {
};
export type UInt16 = {
};
export type Double = {
};
export type Single = {
};
export type Byte = {
};
export type SByte = {
};
export type Char = {
};
export type TimeSpan = {
ticks: string;
days: number;
hours: number;
milliseconds: number;
minutes: number;
seconds: number;
totalDays: Double;
totalHours: Double;
totalMilliseconds: Double;
totalMinutes: Double;
totalSeconds: Double;
};
Original file line number Diff line number Diff line change
@@ -1,51 +1,20 @@

export type SimpleRootType = {
long: string;
uLong: UInt64;
uLong: string;
int: number;
uInt: UInt32;
short: Int16;
uShort: UInt16;
uInt: number;
short: number;
uShort: number;
bool: boolean;
double: Double;
float: Single;
double: number;
float: number;
decimal: number;
byte: Byte;
sByte: SByte;
char: Char;
byte: number;
sByte: number;
char: string;
string?: null | string;
dateTime: (Date | string);
timeSpan: TimeSpan;
timeSpan: string;
guid: string;
};
export type UInt64 = {
};
export type UInt32 = {
};
export type Int16 = {
};
export type UInt16 = {
};
export type Double = {
};
export type Single = {
};
export type Byte = {
};
export type SByte = {
};
export type Char = {
};
export type TimeSpan = {
ticks: string;
days: number;
hours: number;
milliseconds: number;
minutes: number;
seconds: number;
totalDays: Double;
totalHours: Double;
totalMilliseconds: Double;
totalMinutes: Double;
totalSeconds: Double;
};
Loading

0 comments on commit 716d71f

Please sign in to comment.