当前位置: 首页>>代码示例>>C#>>正文


C# Format.ToString方法代码示例

本文整理汇总了C#中Format.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Format.ToString方法的具体用法?C# Format.ToString怎么用?C# Format.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Format的用法示例。


在下文中一共展示了Format.ToString方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Consumer

        public Consumer(string host, string groupName, string instanceId, Format format, string offset = "smallest")
        {
            this.host = host;
            this.groupName = groupName;
            this.instanceId = instanceId;
            this.format = format;

            var contentType = "application/vnd.kafka.v1+json";
            var data = new Dictionary<string, string>
            {
                {"name", instanceId},
                {"format", format.ToString().ToLower()},
                {"auto.offset.reset", offset}
            };
            try
            {
                var responseString = WebRequestHelper.Post(host, $"consumers/{groupName}", JsonConvert.SerializeObject(data),
                    contentType);
                dynamic response = JsonConvert.DeserializeObject<dynamic>(responseString);
                this.instanceId = response.instance_id.ToObject<string>();
                baseUri = response.base_uri.ToObject<string>();
            }
            catch (Exception e)
            {
                // it means, that consumer with this name already exists
                log.Warn(e.Message);
                baseUri = $"{host}/consumers/{groupName}/instances/{instanceId}";
            }
        }
开发者ID:fakefeik,项目名称:KafkaClient,代码行数:29,代码来源:Consumer.cs

示例2: DisplayPixelFormatInfo

        public static IFormatInfo DisplayPixelFormatInfo(Format d3dFormat)
        {
            var formatInfo = new FormatInfo
                                 {
                ID = (int)d3dFormat,
                NumColors = 3,
                ColorFormatType = FormatElementType.UNORM,
                Description = d3dFormat.ToString(),
                Flags = ColorAlphaFormatFlags.None
            };

            switch (d3dFormat)
            {
                case Format.A2R10G10B10:
                    {
                        formatInfo.ColorBits = 30;
                        formatInfo.AlphaBits = 2;
                        formatInfo.AlphaFormatType = FormatElementType.UNORM;
                        formatInfo.TotalBits = 32;
                    }
                    break;
                case Format.X8R8G8B8:
                    {
                        formatInfo.ColorBits = 24;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 32;
                    }
                    break;
                case Format.R5G6B5:
                    {
                        formatInfo.ColorBits = 16;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 16;
                        formatInfo.ExplicitFormat = ExplicitFormat.B5G6R5_UNORM;
                    }
                    break;
                case Format.X1R5G5B5:
                    {
                        formatInfo.ColorBits = 15;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 16;
                    }
                    break;
                default: throw new ArgumentOutOfRangeException("d3dFormat");
            }

            return formatInfo;
        }
开发者ID:Zulkir,项目名称:Beholder,代码行数:51,代码来源:CtBeholder.cs

示例3: GetContentFormat

 public static string GetContentFormat(Format format)
 {
     var formatStr = format.ToString().ToLower();
     return format == Format.MsgPack || format == Format.ProtoBuf
         ? "x-" + formatStr
         : formatStr;
 }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:7,代码来源:ContentFormat.cs

示例4: Develop

        public void Develop(string path, Format format, int width = 0, int height = 0)
        {
            if(width != height)
            {
                double ratio = width >= height ?  (double)_image.Height / _image.Width : (double)_image.Width / _image.Height;
                if(width == 0)
                    width = (int)(height * ratio);
                if(height == 0)
                    height = (int)(width * ratio);
            }
            var imageFormat = (ImageFormat)typeof(ImageFormat).GetProperty(format.ToString()).GetValue(null, null);

            if (width == 0 && height == 0)
                _image.Save(path, imageFormat);
            else _image.GetThumbnailImage(width, height, null, IntPtr.Zero).Save(path, imageFormat);
        }
开发者ID:vladjerca,项目名称:DarkRoom,代码行数:16,代码来源:Negative.cs

示例5: GetContentFormat

 public static string GetContentFormat(Format format)
 {
     return format.ToString().ToLower();
 }
开发者ID:robertgreen,项目名称:ServiceStack,代码行数:4,代码来源:ContentType.cs

示例6: DisplayModeName

 public static string DisplayModeName(Format modeFormat)
 {
     return modeFormat.ToString();
 }
开发者ID:timdetering,项目名称:BeginningNetGameProgramming,代码行数:4,代码来源:DirectXLists.cs

示例7: GetRawSettings

        private static string GetRawSettings(Format.ExportFormats format)
        {
            //"Инициализируем"
            if (settings_list == null)
            {
                lock (locker_set)
                {
                    settings_list = new List<string>();
                    for (int i = 0; i < Enum.GetValues(typeof(Format.ExportFormats)).Length; i++)
                        settings_list.Add(null);
                }
            }

            //Считываем настройки для требуемого формата
            if (settings_list[(int)format] == null)
            {
                lock (locker_set)
                {
                    try
                    {
                        string file = Calculate.StartupPath + "\\presets\\formats\\" + format.ToString() + ".ini";
                        if (File.Exists(file))
                        {
                            using (StreamReader sr = new StreamReader(file, System.Text.Encoding.Default))
                                settings_list[(int)format] = sr.ReadToEnd();
                        }
                        else
                        {
                            settings_list[(int)format] = "";
                        }
                    }
                    catch (Exception)
                    {
                        settings_list[(int)format] = "";
                    }
                }
            }

            //Выдаём настройки по индексу
            return settings_list[(int)format];
        }
开发者ID:BrunoReX,项目名称:xvid4psp,代码行数:41,代码来源:Formats.cs

示例8: SetSettings

        //Изменение настроек формата
        public static void SetSettings(Format.ExportFormats format, string key, string value)
        {
            string output = "";
            string input = GetRawSettings(format);
            string path = Calculate.StartupPath + "\\presets\\formats\\" + format.ToString() + ".ini";

            if (key != null && input.Length > 0)
            {
                bool ok = false;
                using (StringReader str = new StringReader(input))
                {
                    while (true)
                    {
                        string line = str.ReadLine();
                        if (line == null) break;
                        if (!ok && line == "[" + key + "]") //Ключ
                        {
                            ok = true;
                            output += line + "\r\n" + value + "\r\n\r\n";
                            line = str.ReadLine(); //Старое значение (пропускаем)
                            if (line == null) break;
                            line = str.ReadLine(); //Пустая строка после него (пропускаем..)
                            if (line == null) break;
                            if (line.Length > 0)   //(..если она действительно пустая)
                                output += line + "\r\n";
                        }
                        else
                            output += line + "\r\n";
                    }
                }

                //Если дошли до конца, а строки так и не было - вставляем её
                if (!ok) output += "[" + key + "]\r\n" + value + "\r\n\r\n";
            }
            else if (key != null)
            {
                //Новый файл
                output = "!!!DO NOT MODIFY THIS FILE!!!\r\n\r\n[FormatName]\r\n" + Format.EnumToString(format) + "\r\n\r\n[" + key + "]\r\n" + value + "\r\n\r\n";
            }
            else
            {
                //"Сброс"
                output = "!!!DO NOT MODIFY THIS FILE!!!\r\n\r\n[FormatName]\r\n" + Format.EnumToString(format) + "\r\n\r\n";
            }

            try
            {
                //Сохраняем
                File.WriteAllText(path, output, System.Text.Encoding.Default);
                settings_list[(int)format] = output;
            }
            catch (DirectoryNotFoundException ex)
            {
                //Если папки нет, создаем её и пробуем снова
                if (!Directory.Exists(Calculate.StartupPath + "\\presets\\formats"))
                {
                    try
                    {
                        Directory.CreateDirectory(Calculate.StartupPath + "\\presets\\formats");
                    }
                    catch (Exception ex2)
                    {
                        throw new Exception("Can`t create directory: " + ex2.Message, ex2);
                    }

                    File.WriteAllText(path, output, System.Text.Encoding.Default);
                    settings_list[(int)format] = output;
                }
                else
                    throw new Exception("SetSettings: " + ex.Message, ex);
            }
        }
开发者ID:BrunoReX,项目名称:xvid4psp,代码行数:73,代码来源:Formats.cs

示例9: EvaluateFormat

        /// <summary>
        /// Do the default formatting, same logic as "String.Format".
        /// </summary>
        public void EvaluateFormat(object current, Format format, ref bool handled, IOutput output, FormatDetails formatDetails)
        {
            // This function always handles the method:
            handled = true;

            // If the format has nested placeholders, we process those first 
            // instead of formatting the item:
            if (format != null && format.HasNested)
            {
                formatDetails.Formatter.Format(output, format, current, formatDetails);
                return;
            }

            // If the object is null, we shouldn't write anything
            if (current == null)
            {
                return;
            }


            //  (The following code was adapted from the built-in String.Format code)

            //  We will try using IFormatProvider, IFormattable, and if all else fails, ToString.
            var formatter = formatDetails.Formatter;
			if (formatter == null) {} // Force the compiler not to complain about unused variable
            string result = null;
            ICustomFormatter cFormatter;
            IFormattable formattable;
            // Use the provider to see if a CustomFormatter is available:
            if (formatDetails.Provider != null && (cFormatter = formatDetails.Provider.GetFormat(typeof(ICustomFormatter)) as ICustomFormatter) != null)
            {
                var formatText = format == null ? null : format.GetText();
                result = cFormatter.Format(formatText, current, formatDetails.Provider);
            }
            // IFormattable:
            else if ((formattable = current as IFormattable) != null)
            {
                var formatText = format == null ? null : format.ToString();
                result = formattable.ToString(formatText, formatDetails.Provider);
            }
            // ToString:
            else
            {
                result = current.ToString();
            }


            // Now that we have the result, let's output it (and consider alignment):
            
            
            // See if there's a pre-alignment to consider:
            if (formatDetails.Placeholder.Alignment > 0)
            {
                var spaces = formatDetails.Placeholder.Alignment - result.Length;
                if (spaces > 0)
                {
                    output.Write(new String(' ', spaces), formatDetails);
                }
            }

            // Output the result:
            output.Write(result, formatDetails);


            // See if there's a post-alignment to consider:
            if (formatDetails.Placeholder.Alignment < 0)
            {
                var spaces = -formatDetails.Placeholder.Alignment - result.Length;
                if (spaces > 0)
                {
                    output.Write(new String(' ', spaces), formatDetails);
                }
            }
        }
开发者ID:Avatarchik,项目名称:AnimatorAccess,代码行数:77,代码来源:DefaultFormatter.cs

示例10: ExplicitTexelFormatInfo

        static FormatInfo ExplicitTexelFormatInfo(Format glFormat, ExplicitFormat bFormat)
        {
            int numColors;
            int colorBits;
            FormatElementType colorFormatType;
            int alphaBits;
            FormatElementType alphaFormatType;
            int totalBits;
            ColorAlphaFormatFlags flags;

            Utility.Helpers.FormatHelper.GetExplicitColorAlphaFormatInfo(bFormat,
                out numColors, out colorBits, out colorFormatType, out alphaBits, out alphaFormatType, out totalBits, out flags);

            return new FormatInfo
            {
                ID = (int)glFormat,
                Description = glFormat.ToString(),
                ExplicitFormat = bFormat,
                NumColors = numColors,
                ColorBits = colorBits,
                ColorFormatType = colorFormatType,
                AlphaBits = alphaBits,
                AlphaFormatType = alphaFormatType,
                TotalBits = totalBits,
                Flags = flags
            };
        }
开发者ID:Zulkir,项目名称:Beholder,代码行数:27,代码来源:CtBeholder.cs

示例11: SourceParseException

 public SourceParseException(XmlException exception, Format format)
     : base(exception.Message, "Unable to parse {0}: {1}".ToFormat(format.ToString().ToLower(), exception.Message), exception)
 {
 }
开发者ID:ChrisMissal,项目名称:Bender,代码行数:4,代码来源:DeserializeExceptions.cs

示例12: SetVEncodingPreset

 public static void SetVEncodingPreset(Format.ExportFormats format, string value)
 {
     {
         RegistryKey myHive = Registry.CurrentUser.CreateSubKey("Software\\Winnydows\\XviD4PSP5\\videopreset");
         myHive.SetValue(format.ToString(), value, RegistryValueKind.String);
         myHive.Close();
     }
 }
开发者ID:BrunoReX,项目名称:xvid4psp,代码行数:8,代码来源:Settings.cs

示例13: GetVEncodingPreset

        public static string GetVEncodingPreset(Format.ExportFormats format)
        {
            object value;

            using (RegistryKey myHive =
                Registry.CurrentUser.OpenSubKey("Software\\Winnydows\\XviD4PSP5\\videopreset", true))
            {
                if (myHive != null)
                    value = myHive.GetValue(format.ToString());
                else
                    value = null;
            }

            if (value == null)
            {
                //значение по умолчанию
                return Format.GetValidVPreset(format);
            }
            else
            {
                return Convert.ToString(value);
            }
        }
开发者ID:BrunoReX,项目名称:xvid4psp,代码行数:23,代码来源:Settings.cs

示例14: TexelFormatInfo

        public static IFormatInfo TexelFormatInfo(Format d3dFormat)
        {
            switch (d3dFormat)
            {
                case Format.A32B32G32R32F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R32G32B32A32_FLOAT);
                case Format.A16B16G16R16F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R16G16B16A16_FLOAT);
                case Format.A16B16G16R16: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R16G16B16A16_UNORM);
                case Format.G32R32F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R32G32_FLOAT);
                case Format.A2B10G10R10: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R10G10B10A2_UNORM);
                case Format.A8B8G8R8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R8G8B8A8_UNORM);
                case Format.G16R16F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R16G16_FLOAT);
                case Format.G16R16: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R16G16_UNORM);
                case Format.D32SingleLockable: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.D32_FLOAT);
                case Format.R32F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R32_FLOAT);
                case Format.D24S8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.D24_UNORM_S8_UINT);
                case Format.D16: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.D16_UNORM);
                case Format.R16F: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R16_FLOAT);
                case Format.A8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.A8_UNORM);
                case Format.G8R8_G8B8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.R8G8_B8G8_UNORM);
                case Format.R8G8_B8G8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.G8R8_G8B8_UNORM);
                case Format.Dxt1: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.BC1_UNORM);
                case Format.Dxt3: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.BC2_UNORM);
                case Format.Dxt5: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.BC3_UNORM);
                case Format.R5G6B5: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.B5G6R5_UNORM);
                case Format.A1R5G5B5: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.B5G5R5A1_UNORM);
                case Format.A8R8G8B8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.B8G8R8A8_UNORM);
                case Format.X8R8G8B8: return ExplicitFormatInfo(d3dFormat, ExplicitFormat.B8G8R8X8_UNORM);
            }

            var formatInfo = new FormatInfo
            {
                ID = (int)d3dFormat,
                Description = d3dFormat.ToString()
            };

            switch (d3dFormat)
            {
                case Format.R8G8B8:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 24;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 24;
                        formatInfo.Flags = ColorAlphaFormatFlags.Bgra;
                    }
                    break;
                case Format.X1R5G5B5:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 15;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 16;
                        formatInfo.Flags = ColorAlphaFormatFlags.Bgra;
                    }
                    break;
                case Format.A4R4G4B4:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 12;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 4;
                        formatInfo.AlphaFormatType = FormatElementType.UNORM;
                        formatInfo.TotalBits = 16;
                        formatInfo.Flags = ColorAlphaFormatFlags.Bgra;
                    }
                    break;
                case Format.R3G3B2:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 8;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 8;
                        formatInfo.Flags = ColorAlphaFormatFlags.Bgra;
                    }
                    break;
                case Format.A8R3G3B2:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 8;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 8;
                        formatInfo.AlphaFormatType = FormatElementType.UNORM;
                        formatInfo.TotalBits = 8;
                        formatInfo.Flags = ColorAlphaFormatFlags.Bgra;
                    }
                    break;
                case Format.X4R4G4B4:
                    {
                        formatInfo.NumColors = 3;
                        formatInfo.ColorBits = 12;
                        formatInfo.ColorFormatType = FormatElementType.UNORM;
                        formatInfo.AlphaBits = 0;
                        formatInfo.AlphaFormatType = FormatElementType.UNKNOWN;
                        formatInfo.TotalBits = 16;
//.........这里部分代码省略.........
开发者ID:Zulkir,项目名称:Beholder,代码行数:101,代码来源:CtBeholder.cs


注:本文中的Format.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。