@microsoft.azure/autorest.incubator
Version:
AutoRest incubator project
199 lines • 10.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const intersect_1 = require("../../common/intersect");
const expression_1 = require("../../csharp/code-dom/expression");
const namespace_1 = require("../../csharp/code-dom/namespace");
const parameter_1 = require("../../csharp/code-dom/parameter");
const property_1 = require("../../csharp/code-dom/property");
class LibraryType {
constructor(namespace, name) {
this.name = name;
this.namespace = typeof (namespace) === 'string' ? new namespace_1.Namespace(namespace) : namespace;
}
get fullName() {
return this.namespace.fullName ? `${this.namespace.fullName}.${this.name}` : this.name;
}
get declaration() {
return `${this.fullName}`;
}
toString() {
return this.declaration;
}
newInstance(...parameters) {
return { value: `new ${this.fullName}(${parameters.joinWith(each => expression_1.valueOf(each))})` };
}
}
exports.LibraryType = LibraryType;
class EnumType {
constructor(namespace, name) {
this.namespace = namespace;
this.name = name;
}
get declaration() {
return `${this.namespace}.${this.name}`;
}
member(enumMember) {
return new expression_1.LiteralExpression(`${this.declaration}.${enumMember}`);
}
get definition() {
return ``;
}
toString() {
return this.declaration;
}
newProperty(name, objectInitializer) {
return new property_1.Property(name, this, objectInitializer);
}
newParameter(name, objectInitializer) {
return new parameter_1.Parameter(name, this, objectInitializer);
}
withMembers() {
const $this = this;
return new Proxy($this, {
get(target, prop, receiver) {
// return a property if there is one for this.
if (target[prop]) {
return target[prop];
}
return $this.member(prop.toString());
}
});
}
}
exports.EnumType = EnumType;
exports.None = new namespace_1.Namespace('');
const system = new namespace_1.Namespace('System');
const threading = new namespace_1.Namespace('Threading', system);
const tasks = new namespace_1.Namespace('Tasks', threading);
const action = new LibraryType(system, 'Action');
const collections = new namespace_1.Namespace('Collections', system);
const generic = new namespace_1.Namespace('Generic', collections);
const net = new namespace_1.Namespace('Net', system);
const http = new namespace_1.Namespace('Http', net);
const headers = new namespace_1.Namespace('Headers', http);
const task = new LibraryType(tasks, 'Task');
const xml = new namespace_1.Namespace('Xml', system);
const xmllinq = new namespace_1.Namespace('Linq', xml);
const stringClass = new LibraryType(system, 'String');
exports.System = intersect_1.intersect(system, {
Threading: intersect_1.intersect(threading, {
CancellationToken: new LibraryType(threading, 'CancellationToken'),
CancellationTokenSource: new LibraryType(threading, 'CancellationTokenSource'),
Tasks: intersect_1.intersect(tasks, {
Task(taskType) {
return taskType ? new LibraryType(tasks, `Task<${taskType.declaration}>`) : task;
}
})
}),
String: intersect_1.intersect(stringClass, {
Empty: new expression_1.LiteralExpression("System.String.Empty"),
}),
DateTime: new LibraryType(system, 'DateTimeOffset'),
EventArgs: new LibraryType(system, 'EventArgs'),
Exception: new LibraryType(system, 'Exception'),
AggregateException: new LibraryType(system, 'AggregateException'),
TimeSpan: new LibraryType(system, 'TimeSpan'),
Type: new LibraryType(system, 'Type'),
Uri: new LibraryType(system, 'Uri'),
IFormatProvider: new LibraryType(system, 'IFormatProvider'),
Xml: intersect_1.intersect(xml, {
Linq: intersect_1.intersect(xmllinq, {
XElement: new LibraryType(xmllinq, 'XElement'),
XAttribute: new LibraryType(xmllinq, 'XAttribute')
})
}),
Net: intersect_1.intersect(net, {
Http: intersect_1.intersect(http, {
HttpRequestMessage: new LibraryType(http, 'HttpRequestMessage'),
HttpResponseMessage: new LibraryType(http, 'HttpResponseMessage'),
Headers: intersect_1.intersect(headers, {
HttpHeaders: new LibraryType(headers, 'HttpHeaders'),
HttpResponseHeaders: new LibraryType(headers, 'HttpResponseHeaders'),
})
}),
HttpStatusCode: intersect_1.intersect(new LibraryType(net, 'HttpStatusCode'), {
default: new expression_1.LiteralExpression(''),
100: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Continue'),
101: new expression_1.LiteralExpression('System.Net.HttpStatusCode.SwitchingProtocols'),
200: new expression_1.LiteralExpression('System.Net.HttpStatusCode.OK'),
201: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Created'),
202: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Accepted'),
203: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NonAuthoritativeInformation'),
204: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NoContent'),
205: new expression_1.LiteralExpression('System.Net.HttpStatusCode.ResetContent'),
206: new expression_1.LiteralExpression('System.Net.HttpStatusCode.PartialContent'),
300: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Ambiguous'),
301: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Moved'),
302: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Redirect'),
303: new expression_1.LiteralExpression('System.Net.HttpStatusCode.SeeOther'),
304: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NotModified'),
305: new expression_1.LiteralExpression('System.Net.HttpStatusCode.UseProxy'),
306: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Unused'),
307: new expression_1.LiteralExpression('System.Net.HttpStatusCode.TemporaryRedirect'),
400: new expression_1.LiteralExpression('System.Net.HttpStatusCode.BadRequest'),
401: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Unauthorized'),
402: new expression_1.LiteralExpression('System.Net.HttpStatusCode.PaymentRequired'),
403: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Forbidden'),
404: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NotFound'),
405: new expression_1.LiteralExpression('System.Net.HttpStatusCode.MethodNotAllowed'),
406: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NotAcceptable'),
407: new expression_1.LiteralExpression('System.Net.HttpStatusCode.ProxyAuthenticationRequired'),
408: new expression_1.LiteralExpression('System.Net.HttpStatusCode.RequestTimeout'),
409: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Conflict'),
410: new expression_1.LiteralExpression('System.Net.HttpStatusCode.Gone'),
411: new expression_1.LiteralExpression('System.Net.HttpStatusCode.LengthRequired'),
412: new expression_1.LiteralExpression('System.Net.HttpStatusCode.PreconditionFailed'),
413: new expression_1.LiteralExpression('System.Net.HttpStatusCode.RequestEntityTooLarge'),
414: new expression_1.LiteralExpression('System.Net.HttpStatusCode.RequestUriTooLong'),
415: new expression_1.LiteralExpression('System.Net.HttpStatusCode.UnsupportedMediaType'),
416: new expression_1.LiteralExpression('System.Net.HttpStatusCode.RequestedRangeNotSatisfiable'),
417: new expression_1.LiteralExpression('System.Net.HttpStatusCode.ExpectationFailed'),
426: new expression_1.LiteralExpression('System.Net.HttpStatusCode.UpgradeRequired'),
500: new expression_1.LiteralExpression('System.Net.HttpStatusCode.InternalServerError'),
501: new expression_1.LiteralExpression('System.Net.HttpStatusCode.NotImplemented'),
502: new expression_1.LiteralExpression('System.Net.HttpStatusCode.BadGateway'),
503: new expression_1.LiteralExpression('System.Net.HttpStatusCode.ServiceUnavailable'),
504: new expression_1.LiteralExpression('System.Net.HttpStatusCode.GatewayTimeout'),
505: new expression_1.LiteralExpression('System.Net.HttpStatusCode.HttpVersionNotSupported')
}),
}),
Collections: intersect_1.intersect(collections, {
Hashtable: new LibraryType(collections, "Hashtable"),
Generic: intersect_1.intersect(generic, {
Dictionary(keyType, valueType) {
return new LibraryType(generic, `Dictionary<${keyType.declaration},${valueType.declaration}>`);
},
KeyValuePair(keyType, valueType) {
return new LibraryType(generic, `KeyValuePair<${keyType.declaration},${valueType.declaration}>`);
},
IEnumerable(type) {
return new LibraryType(generic, `IEnumerable<${type.declaration}>`);
}
})
}),
Action(...actionParameters) {
return actionParameters.length === 0 ? action : new LibraryType(system, `Action<${actionParameters.filter(each => each.declaration).joinWith(each => each.declaration)}>`);
},
Func(...funcParameters) {
return new LibraryType(system, `Func<${funcParameters.joinWith(each => each.declaration)}>`);
}
});
exports.Unknown = new LibraryType(exports.None, 'null');
exports.ToDo = new LibraryType(exports.None, 'null');
exports.Void = new LibraryType(exports.None, 'void');
exports.String = new LibraryType(exports.None, 'string');
exports.Int = new LibraryType(exports.None, 'int');
exports.Long = new LibraryType(exports.None, 'long');
exports.Double = new LibraryType(exports.None, 'double');
exports.Float = new LibraryType(exports.None, 'float');
exports.Binary = new LibraryType(exports.None, 'byte[]');
exports.Bool = new LibraryType(exports.None, 'bool');
exports.Object = new LibraryType(exports.None, 'object');
exports.Dynamic = new LibraryType(exports.None, 'dynamic');
exports.ThisObject = new LibraryType(exports.None, 'this object');
exports.Var = new LibraryType(exports.None, 'var');
exports.True = new expression_1.LiteralExpression('true');
exports.False = new expression_1.LiteralExpression('false');
exports.Null = new expression_1.LiteralExpression('null');
exports.This = new expression_1.LiteralExpression('this');
//# sourceMappingURL=mscorlib.js.map