Exemplo n.º 1
0
        private object FormatArg(object arg, KhronosLogCommandParameterFlags flags)
        {
            Type argType = arg.GetType();

            if (argType == typeof(string[]))
            {
                return(FormatArg((string[])arg, flags));
            }
            if (argType.IsArray)
            {
                return(FormatArg((Array)arg, flags));
            }

            if (argType == typeof(string))
            {
                return(FormatArg((string)arg, flags));
            }
            if (argType == typeof(IntPtr))
            {
                return(FormatArg((IntPtr)arg, flags));
            }
            if (argType == typeof(int))
            {
                return(FormatArg((int)arg, flags));
            }

            return(arg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Express using a string the GL command with its arguments.
        /// </summary>
        /// <param name="name">
        /// A <see cref="string"/> that specifies the command name.
        /// </param>
        /// <param name="returnValue">
        /// A <see cref="object"/> that specifies the command returned value. It is null in case the command
        /// returns void.
        /// </param>
        /// <param name="args">
        /// A <see cref="T:object[]"/> that specifies the command arguments. It can be null in case command
        /// has no arguments.
        /// </param>
        /// <returns></returns>
        public string ToString(string name, object returnValue, object[] args)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            // Format string: '{0}({1}, {2}, ...) = {N}'
            StringBuilder sbFormat  = new StringBuilder();
            int           formatIdx = 1;

            sbFormat.Append("{0}(");
            if (args != null && args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    sbFormat.AppendFormat("{{{0}}}, ", formatIdx++);
                }
                sbFormat.Remove(sbFormat.Length - 2, 2);
            }
            sbFormat.Append(")");
            if (returnValue != null)
            {
                sbFormat.AppendFormat(" = {{{0}}}", formatIdx++);
            }

            // Format arguments
            List <object> formatArgs = new List <object> {
                name
            };

            if (args != null)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    KhronosLogCommandParameterFlags flags = KhronosLogCommandParameterFlags.None;
#if HAVE_SYSTEM_XML
                    if (_LogMap != null)
                    {
                        flags = _LogMap.GetCommandParameterFlag(name, i);
                    }
#endif
                    formatArgs.Add(FormatArg(args[i], flags));
                }
            }
            if (returnValue != null)
            {
                formatArgs.Add(FormatArg(returnValue, KhronosLogCommandParameterFlags.None));
            }

            // Returns formatted string
            return(string.Format(sbFormat.ToString(), formatArgs.ToArray()));
        }
Exemplo n.º 3
0
        public string ToString(string name, object returnValue, object[] args)
        {
            if (name == null)
            {
                throw new ArgumentException("name");
            }

            // Format string
            StringBuilder sbFormat  = new StringBuilder();
            int           formatIdx = 1;

            sbFormat.Append("{0}(");
            if (args != null && args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    sbFormat.AppendFormat("{{{0}}}, ", formatIdx++);
                }
                sbFormat.Remove(sbFormat.Length - 2, 2);
            }
            sbFormat.Append(")");
            if (returnValue != null)
            {
                sbFormat.AppendFormat(" = {{{0}}}", formatIdx++);
            }

            // Format arguments
            List <object> formatArgs = new List <object>();

            formatArgs.Add(name);
            if (args != null)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    KhronosLogCommandParameterFlags flags = KhronosLogCommandParameterFlags.None;
#if !NETCORE && !NETSTANDARD1_4
                    if (_LogMap != null)
                    {
                        flags = _LogMap.GetCommandParameterFlag(name, i);
                    }
#endif

                    formatArgs.Add(FormatArg(args[i], flags));
                }
            }
            if (returnValue != null)
            {
                formatArgs.Add(FormatArg(returnValue, KhronosLogCommandParameterFlags.None));
            }

            // Returns formatted string
            return(String.Format(sbFormat.ToString(), formatArgs.ToArray()));
        }
Exemplo n.º 4
0
        private object FormatArg(int arg, KhronosLogCommandParameterFlags flags)
        {
            if ((flags & KhronosLogCommandParameterFlags.Enum) != 0)
            {
                string enumName = GetEnumName(arg);

                if (enumName != null)
                {
                    return(enumName);
                }
            }

            return(arg);
        }
Exemplo n.º 5
0
        private object FormatArg(Array arg, KhronosLogCommandParameterFlags flags)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (object arrayItem in arg)
            {
                sb.AppendFormat("{0},", FormatArg(arrayItem, flags).ToString());
            }
            if (arg.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }
            sb.Append("}");

            return(sb.ToString());
        }
Exemplo n.º 6
0
        private object FormatArg(string[] arg, KhronosLogCommandParameterFlags flags)
        {
            if (arg != null)
            {
                StringBuilder sb = new StringBuilder();

                sb.Append("{");
                foreach (string arrayItem in arg)
                {
                    sb.AppendFormat("{0},", arrayItem.Replace("\n", "\\n"));
                }
                if (arg.Length > 0)
                {
                    sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("}");

                return(sb.ToString());
            }
            else
            {
                return("{ null }");
            }
        }
Exemplo n.º 7
0
 private object FormatArg(string arg, KhronosLogCommandParameterFlags flags)
 {
     return("\"" + arg + "\"");
 }
Exemplo n.º 8
0
 private object FormatArg(IntPtr arg, KhronosLogCommandParameterFlags flags)
 {
     return("0x" + arg.ToString("X8"));
 }