Browse Source

feat: generate Volo.Abp.NameValue as generic type

pull/5209/head
Arman Ozak 6 years ago
parent
commit
7c480461e3
  1. 10
      npm/ng-packs/packages/schematics/src/constants/volo.ts
  2. 11
      npm/ng-packs/packages/schematics/src/utils/model.ts

10
npm/ng-packs/packages/schematics/src/constants/volo.ts

@ -4,19 +4,19 @@ export const VOLO_REGEX = /^Volo\.Abp\.(Application\.Dtos|ObjectExtending)/;
export const VOLO_NAME_VALUE = new Interface({
base: null,
identifier: 'NameValue',
identifier: 'NameValue<T = string>',
ref: 'Volo.Abp.NameValue',
namespace: 'Volo.Abp',
properties: [
new Property({
name: 'Name',
name: 'name',
type: 'string',
refs: ['System.String'],
}),
new Property({
name: 'Value',
type: 'string',
refs: ['System.String'],
name: 'value',
type: 'T',
refs: ['T'],
}),
],
});

11
npm/ng-packs/packages/schematics/src/utils/model.ts

@ -40,10 +40,11 @@ export function createImportRefsToModelReducer(params: ModelGeneratorParams) {
const index = models.findIndex(m => m.namespace === _interface.namespace);
if (index > -1) {
if (models[index].interfaces.some(i => i.identifier === _interface.identifier)) return;
if (_interface.ref.startsWith(VOLO_NAME_VALUE.ref)) return;
models[index].interfaces.push(_interface);
} else {
if (_interface.ref === VOLO_NAME_VALUE.ref) _interface = VOLO_NAME_VALUE;
if (_interface.ref.startsWith(VOLO_NAME_VALUE.ref)) _interface = VOLO_NAME_VALUE;
const { namespace } = _interface;
@ -135,13 +136,7 @@ export function createImportRefToInterfaceReducerCreator(params: ModelGeneratorP
prop.refs.forEach(type => !types[type]?.isEnum && refs.push(type));
return refs;
}, [])
.concat(
base
? parseGenerics(typeDef.baseType!)
.toGenerics()
.join('')
: [],
)
.concat(base ? parseGenerics(typeDef.baseType!).toGenerics() : [])
.reduce<Interface[]>(reduceRefsToInterfaces, interfaces);
}
}

Loading…
Cancel
Save