Esempio n. 1
0
        /// <summary>
        /// Generates JavaScript code including JsDoc comments from the provided class or interface type.
        /// </summary>
        /// <typeparam name="T">Class or interface type.</typeparam>
        /// <param name="xmlDocPath">XML assembly definition file.</param>
        /// <param name="settings">RPC-Js settings used for Javascript code generation.</param>
        /// <returns>Javascript API.</returns>
        public static string GenerateCallerWithDoc <T>(string xmlDocPath, RPCJsSettings <T> settings = null)
        {
            settings           = settings ?? new RPCJsSettings <T>();
            var(tName, mInfos) = JsCallerGenerator.GetMethods(settings.OmittedMethods);
            tName = settings.NameOverwrite ?? tName;

            var xmlMemberNodes = JsDocGenerator.GetMemberNodes(xmlDocPath);

            var sb = new StringBuilder();

            if (settings.WithRequireSupport)
            {
                sb.Append(JsCallerGenerator.GenerateRequireJsHeader(tName));
            }
            sb.Append(JsDocGenerator.GetClassDoc(xmlMemberNodes, tName));
            sb.Append(JsCallerGenerator.GenerateHeader(tName));

            foreach (var m in mInfos)
            {
                var mName  = m.Name;
                var pTypes = m.GetParameters().Select(x => x.ParameterType).ToArray();
                var pNames = m.GetParameters().Select(x => x.Name).ToArray();

                sb.Append(JsDocGenerator.GetMethodDoc(xmlMemberNodes, mName, pNames, pTypes, m.ReturnType));
                sb.Append(JsCallerGenerator.GenerateMethod(mName, pNames));
            }

            sb.Append(JsCallerGenerator.GenerateFooter());
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Generates JavaScript code from the provided class or interface type.
        /// </summary>
        /// <typeparam name="T">Class or interface type.</typeparam>
        /// <param name="settings">RPC-Js settings used for Javascript code generation.</param>
        /// <returns>Javascript API.</returns>
        public static string GenerateCaller <T>(RPCJsSettings <T> settings = null)
        {
            settings           = settings ?? new RPCJsSettings <T>();
            var(tName, mInfos) = JsCallerGenerator.GetMethods(settings.OmittedMethods);
            tName = settings.NameOverwrite ?? tName;

            var sb = new StringBuilder();

            if (settings.WithRequireSupport)
            {
                sb.Append(JsCallerGenerator.GenerateRequireJsHeader(tName));
            }
            sb.Append(JsCallerGenerator.GenerateHeader(tName));

            foreach (var m in mInfos)
            {
                var mName  = m.Name;
                var pNames = m.GetParameters().Select(x => x.Name).ToArray();

                sb.Append(JsCallerGenerator.GenerateMethod(mName, pNames));
            }

            sb.Append(JsCallerGenerator.GenerateFooter());
            return(sb.ToString());
        }