private void WriteConstructorToBlock(TypeScriptBlock classBlock, WebApiAction action, WebApiHttpVerb verb) { var actionName = action.GetActionNameForVerb(verb); var constructorParameterMappings = action.GetConstructorParameterMappings(); var areAllParametersOptional = constructorParameterMappings .All(m => m.IsOptional); var optionalString = areAllParametersOptional ? "?" : string.Empty; var constructorBlock = classBlock .AddAndUseBlock($"constructor(args{optionalString}: I{actionName})"); foreach (var mapping in constructorParameterMappings) { constructorBlock .AddStatement($"this.{mapping.Name} = args != null ? args.{mapping.Name} : null;"); if (mapping.TypeMapping?.AutoInitialize ?? false) { constructorBlock .AddAndUseBlock($"if (this.{mapping.Name} == null)") .AddStatement($"this.{mapping.Name} = new {mapping.TypeMapping.TypeScriptTypeName}();"); } } }
private void WriteInterfaceWithCallToBlock(TypeScriptBlock interfaceWithCallBlock, WebApiAction action, WebApiHttpVerb verb) { var callArguments = action.BodyParameters; var callArgument = callArguments .Select(a => a.GetParameterString(withOptionals: false, interfaceName: true)) .SingleOrDefault(); var callArgumentsList = string.IsNullOrWhiteSpace(callArgument) ? "httpConfig?: angular.IRequestShortcutConfig" : $"{callArgument}, httpConfig?: angular.IRequestShortcutConfig"; string typeScriptReturnType, typeScriptTypeForCall; action.GetReturnTypes(out typeScriptReturnType, out typeScriptTypeForCall); interfaceWithCallBlock .AddStatement($"call{typeScriptTypeForCall}({callArgumentsList}): ng.IPromise{typeScriptReturnType};"); if (Config.EndpointsSupportCaching && verb == WebApiHttpVerb.Get) { interfaceWithCallBlock .AddStatement($"callCached{typeScriptTypeForCall}({callArgumentsList}): ng.IPromise{typeScriptReturnType};"); } }