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


C# TypeConverter.ConvertToString方法代码示例

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


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

示例1: CDSAttributesRetrieve

        /// <summary>
        /// This method retrieves a set of CDSAttribute from a class.
        /// </summary>
        /// <param name="data">The class to examine.</param>
        /// <param name="conv">A converter function to turn the value in to a string.</param>
        /// <returns>Returns an enumerable collection of attributes and values.</returns>
        public static IEnumerable<KeyValuePair<CDSAttributeAttribute, string>> CDSAttributesRetrieve(
            this IXimuraContent data, TypeConverter conv)
        {
            List<KeyValuePair<PropertyInfo, CDSAttributeAttribute>> attrList =
                AH.GetPropertyAttributes<CDSAttributeAttribute>(data.GetType());

            foreach (KeyValuePair<PropertyInfo, CDSAttributeAttribute> reference in attrList)
            {
                PropertyInfo pi = reference.Key;

                if (pi.PropertyType == typeof(string))
                {
                    yield return new KeyValuePair<CDSAttributeAttribute, string>(
                        reference.Value, pi.GetValue(data, null) as string);
                }
                else if (pi.PropertyType == typeof(IEnumerable<string>))
                {
                    IEnumerable<string> enumerator = pi.GetValue(data, null) as IEnumerable<string>;
                    foreach (string value in enumerator)
                        yield return new KeyValuePair<CDSAttributeAttribute, string>(
                            reference.Value, value);
                }
                else if (conv != null && conv.CanConvertFrom(pi.PropertyType))
                {
                    yield return new KeyValuePair<CDSAttributeAttribute, string>(
                        reference.Value, conv.ConvertToString(pi.GetValue(data, null)));
                }
            }
        }
开发者ID:mbmccormick,项目名称:Ximura,代码行数:35,代码来源:ContentHelper.cs

示例2: test1

        public void test1()
        {
            Rectangle rect = new Rectangle(10, 12, 14, 16);

            // Wrong
            System.ComponentModel.TypeConverter baseConverter = new System.ComponentModel.TypeConverter();
            string sample1 = baseConverter.ConvertToString(rect);

            // Right
            System.ComponentModel.TypeConverter rectSpecificConverter = TypeDescriptor.GetConverter(rect);
            string sample2 = rectSpecificConverter.ConvertToString(rect);

            log.DebugFormat("From new TypeConverter() {0}\r\n", sample1);
            log.DebugFormat("From TypeDescriptor.GetConverter() {0}\r\n", sample2);
            log.DebugFormat("From rect.ToString() {0}\r\n", rect.ToString());
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:16,代码来源:TypeConverterTest.cs

示例3: CreateToolItem

 private ListViewItem CreateToolItem(NamedShellLink tool, TypeConverter keysConverter)
 {
     ListViewItem item = new ListViewItem(tool.Name) {
         Tag = tool
     };
     ListViewItem.ListViewSubItem item2 = item.SubItems.Add(keysConverter.ConvertToString(tool.Hotkey));
     if (tool.Hotkey == Keys.None)
     {
         item.UseItemStyleForSubItems = false;
         item2.ForeColor = SystemColors.GrayText;
     }
     return item;
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:13,代码来源:ExternalToolsOptionControl.cs

示例4: ConvertObjectToTypeInternal

 private static bool ConvertObjectToTypeInternal(object o, Type type, JavaScriptSerializer serializer, bool throwOnError, out object convertedObject)
 {
     IDictionary<string, object> dictionary = o as IDictionary<string, object>;
     if (dictionary != null)
     {
         return ConvertDictionaryToObject(dictionary, type, serializer, throwOnError, out convertedObject);
     }
     IList list = o as IList;
     if (list != null)
     {
         IList list2;
         if (ConvertListToObject(list, type, serializer, throwOnError, out list2))
         {
             convertedObject = list2;
             return true;
         }
         convertedObject = null;
         return false;
     }
     if ((type == null) || (o.GetType() == type))
     {
         convertedObject = o;
         return true;
     }
     //TypeDescriptor.GetConverter(type) !!!
     TypeConverter converter = new TypeConverter();
     if (converter.CanConvertFrom(o.GetType()))
     {
         try
         {
             convertedObject = converter.ConvertFrom(null, CultureInfo.InvariantCulture, o);
             return true;
         }
         catch
         {
             if (throwOnError)
             {
                 throw;
             }
             convertedObject = null;
             return false;
         }
     }
     if (converter.CanConvertFrom(typeof(string)))
     {
         try
         {
             string str;
             if (o is DateTime)
             {
                 DateTime time = (DateTime)o;
                 str = time.ToUniversalTime().ToString("u", CultureInfo.InvariantCulture);
             }
             else
             {
                 //ConvertToInvariantString(o); !!!
                 str = converter.ConvertToString(o);
             }
             //ConvertFromInvariantString(str); !!!
             convertedObject = converter.ConvertToString(str);
             return true;
         }
         catch
         {
             if (throwOnError)
             {
                 throw;
             }
             convertedObject = null;
             return false;
         }
     }
     if (type.IsAssignableFrom(o.GetType()))
     {
         convertedObject = o;
         return true;
     }
     if (throwOnError)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, AtlasWeb.JSON_CannotConvertObjectToType, new object[] { o.GetType(), type }));
     }
     convertedObject = null;
     return false;
 }
开发者ID:hart404,项目名称:pubnub-api,代码行数:84,代码来源:ObjectConverter.cs

示例5: UpdateCommandShortcut

 private void UpdateCommandShortcut(ListViewItem item, Keys shortcutKeys, TypeConverter keysConverter)
 {
     ListViewItem.ListViewSubItem item2 = (item.SubItems.Count > 1) ? item.SubItems[1] : item.SubItems.Add("-");
     if (keysConverter == null)
     {
         keysConverter = TypeDescriptor.GetConverter(typeof(Keys));
     }
     item2.Text = keysConverter.ConvertToString(shortcutKeys);
     item2.ForeColor = SystemColors.GrayText;
     item.UseItemStyleForSubItems = shortcutKeys != Keys.None;
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:11,代码来源:KeyboardMapOptionControl.cs

示例6: CDSReferencesRetrieve

        /// <summary>
        /// This method retrieves a set of reference attributes from a class.
        /// </summary>
        /// <param name="data">The class to examine.</param>
        /// <param name="conv">A converter function to turn the value in to a string.</param>
        /// <returns>Returns an enumerable collection of attributes and values.</returns>
        public static IEnumerable<KeyValuePair<CDSReferenceAttribute, string>> CDSReferencesRetrieve(
            this IXimuraContent data, TypeConverter conv)
        {
            List<KeyValuePair<PropertyInfo, CDSReferenceAttribute>> attrList =
                AH.GetPropertyAttributes<CDSReferenceAttribute>(data.GetType());

            foreach (KeyValuePair<PropertyInfo, CDSReferenceAttribute> reference in attrList)
            {
                PropertyInfo pi = reference.Key;

                if (pi.PropertyType != typeof(string) &&
                    (conv == null || !conv.CanConvertFrom(pi.PropertyType)))
                    continue;

                string value;

                if (pi.PropertyType == typeof(string))
                    value = pi.GetValue(data, null) as string;
                else
                    value = conv.ConvertToString(pi.GetValue(data, null));

                yield return new KeyValuePair<CDSReferenceAttribute, string>(reference.Value, value);
            }
        }
开发者ID:mbmccormick,项目名称:Ximura,代码行数:30,代码来源:ContentHelper.cs


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