當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。