Exemplo 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());
        }
Exemplo 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());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates JavaScript code including JsDoc comments from the provided class or interface type.
        /// <para>The XML assembly definition is taken form the executing assembly if available.</para>
        /// </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 GenerateCallerWithDoc <T>(RPCJsSettings <T> settings = null)
        {
            var xmlDocPath = Path.ChangeExtension(typeof(T).Assembly.Location, ".xml");

            if (!File.Exists(xmlDocPath))
            {
                return(GenerateCaller(settings));
            }
            else
            {
                return(GenerateCallerWithDoc(xmlDocPath, settings));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Generates JavaScript code including JsDoc comments from the provided class or interface type.
        /// <para>The XML assembly definition is taken form the executing assembly if available.</para>
        /// </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 GenerateCallerWithDoc <T>(RPCJsSettings <T> settings = null)
        {
            var assembly = Assembly.GetEntryAssembly();
            var fInfo    = new FileInfo(assembly.Location);

            var xmlDocPath = Path.ChangeExtension(assembly.Location, ".xml");

            if (!File.Exists(xmlDocPath))
            {
                return(GenerateCaller(settings));
            }
            else
            {
                return(GenerateCallerWithDoc(xmlDocPath, settings));
            }
        }