updates to support typeconverters

This commit is contained in:
Garrett Serack 2019-05-06 08:59:30 -07:00
Родитель ddf3d90b9c
Коммит 007fa84c10
7 изменённых файлов: 34 добавлений и 11 удалений

Просмотреть файл

@ -67,9 +67,9 @@ ${this.attributeDeclaration}${this.accessModifier} ${stat}${partial}${this.class
}
public get definition(): string {
const fields = this.fields.sort(sortByName).map(m => m.declaration).join(EOL);
const methods = this.methods.sort(sortByNamePartialFirst).map(m => m.implementation).join(EOL);
const properties = this.properties.sort(sortByName).map(m => m.declaration).join(EOL);
const fields = this.fields.sort(sortByName).map(m => m.declaration).join(EOL + EOL);
const methods = this.methods.sort(sortByNamePartialFirst).map(m => m.implementation).join(EOL + EOL);
const properties = this.properties.sort(sortByName).map(m => m.declaration).join(EOL + EOL);
return `
${this.signature}
{

Просмотреть файл

@ -89,6 +89,8 @@ export const None: Namespace = new Namespace('');
const system: Namespace = new Namespace('global::System');
const threading = new Namespace('Threading', system);
const text = new Namespace('Text', system);
const rx = new Namespace('RegularExpressions', text);
const tasks = new Namespace('Tasks', threading);
const action = new ClassType(system, 'Action');
const collections = new Namespace('Collections', system);
@ -168,6 +170,9 @@ export const System = intersect(system, {
Text: intersect(text, {
Encoding: intersect(encoding, {
UTF8: new LiteralExpression(`${encoding.declaration}.UTF8`)
}),
RegularExpressions: intersect(rx, {
Regex: new ClassType(rx, "Regex")
})
}),
Net: intersect(net, {

Просмотреть файл

@ -114,12 +114,13 @@ export class Namespace extends Initializer {
for (const [key, classesWithSameName] of classes) {
const contents = classesWithSameName.map(each => each.definition);
const interfaceName = `I${key}`;
const interfacesWithSameName = interfaces.get(interfaceName);
if (interfacesWithSameName) {
contents.push(...interfacesWithSameName.map(each => each.definition));
// remove from the list.
interfaces.delete(interfaceName);
for (const interfaceName of [`I${key}`, `I${key}Internal`]) { // pick up interfaces and interfacesInternal in the same file.
const interfacesWithSameName = interfaces.get(interfaceName);
if (interfacesWithSameName) {
contents.push(...interfacesWithSameName.map(each => each.definition));
// remove from the list.
interfaces.delete(interfaceName);
}
}
await writer(`${this.outputFolder}/${key}.cs`, this.render(contents.join(EOL)));
}

Просмотреть файл

@ -6,6 +6,7 @@
import { indent } from '@microsoft.azure/codegen';
import { Expression, ExpressionOrLiteral, LiteralExpression, toExpression, valueOf } from '../expression';
import { StatementPossibilities, Statements } from './statement';
import { TypeDeclaration } from '../type-declaration';
export function If(conditional: ExpressionOrLiteral, statements: StatementPossibilities, objectInitializer?: Partial<IfStatement>) {
return new IfStatement(conditional, statements, objectInitializer);
@ -86,4 +87,8 @@ ${indent(super.implementation)}
export function Not(conditional: Expression): Expression {
return new LiteralExpression(`!(${conditional.value})`);
}
export function IsAssignableFrom(targetType: TypeDeclaration, instanceType: ExpressionOrLiteral) {
return toExpression(`typeof(${targetType.declaration}).IsAssignableFrom( ${valueOf(instanceType)})`);
}

Просмотреть файл

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { EOL, Initializer } from '@microsoft.azure/codegen';
import { EOL, Initializer, indent } from '@microsoft.azure/codegen';
import { LiteralStatement } from './literal';
export type fIterable<T> = Iterable<T> | (() => Iterable<T>);
@ -29,6 +29,7 @@ export function isStatement(object: StatementPossibilities): object is Statement
return (<any>object).implementation ? true : false;
}
export class Statements extends Initializer implements Statement {
protected statements = new Array<Statement>();
private scope = new Array<Statements>();
@ -112,3 +113,10 @@ export class Statements extends Initializer implements Statement {
return `${this.statements.joinWith(each => each.implementation, EOL)}`.trim();
}
}
export function* BlockStatement(statements: StatementPossibilities) {
yield `{`;
yield indent(new Statements(statements).implementation);
yield `}`;
}

Просмотреть файл

@ -49,6 +49,8 @@ export interface VirtualProperty {
/** the member's schema */
accessViaSchema?: Schema;
originalContainingSchema: Schema;
private?: boolean;
alias: Array<string>;
@ -123,7 +125,7 @@ export function getVirtualPropertyFromPropertyName(virtualProperties: VirtualPro
inherited: [],
inlined: []
};
return values([...props.owned, ...props.inherited, ...props.inlined]).linq.first(each => each.property.details.default.name === propertyName);
return values([...props.owned, ...props.inherited, ...props.inlined]).linq.first(each => each.property.serializedName === propertyName);
}

Просмотреть файл

@ -18,6 +18,8 @@ export enum KnownMediaType {
Stream = 'application/octet-stream',
Multipart = 'multipart/form-data',
Text = 'text/plain',
PSObject = '-PSObject-',
Hashtable = '-Hashtable-',
None = '-none-',
QueryParameter = '-query-parameter-',