/// <summary>
 /// Formats a function
 /// </summary>
 /// <param name="function">The function</param>
 /// <returns>The string representation of the function</returns>
 public virtual string Format(TsFunction function)
 {
     using (var sbc = new StringBuilderContext(this))
     {
         Write("{0}{1}({2}){3};",
               Format(function.Name),
               Format(function.TypeParameters),
               Format(function.Parameters),
               function.ReturnType == TsPrimitive.Any ? string.Empty : string.Format(": {0}", FormatReturnType(function.ReturnType))
               );
         return(sbc.ToString());
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Resolves a method
        /// </summary>
        /// <param name="method">The method to resolve</param>
        /// <returns>The TypeScript function definition</returns>
        protected virtual TsFunction Resolve(MethodInfo method)
        {
            var returnType = Resolve(method.ReturnType);
            var parameters = this.Reader.GetParameters(method);
            var tsFunction = new TsFunction(GetName(method));

            tsFunction.ReturnType = returnType;
            if (method.IsGenericMethod)
            {
                foreach (var genericArgument in method.GetGenericArguments())
                {
                    var tsTypeParameter = new TsTypeParameter(new TsName(genericArgument.Name));
                    tsFunction.TypeParameters.Add(tsTypeParameter);
                }
            }

            foreach (var param in parameters.Select(x => new TsParameter(GetName(x), Resolve(x.ParameterType))))
            {
                tsFunction.Parameters.Add(param);
            }

            return(tsFunction);
        }