當前位置: 首頁>>代碼示例>>C#>>正文


C# ComponentModel.TypeConverter類代碼示例

本文整理匯總了C#中System.ComponentModel.TypeConverter的典型用法代碼示例。如果您正苦於以下問題:C# TypeConverter類的具體用法?C# TypeConverter怎麽用?C# TypeConverter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeConverter類屬於System.ComponentModel命名空間,在下文中一共展示了TypeConverter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LocalizedPropertyDescriptor

 public LocalizedPropertyDescriptor(PropertyDescriptor basePropertyDescriptor)
     : base(basePropertyDescriptor)
 {
     this.localizedName = string.Empty;
     this.localizedDescription = string.Empty;
     this.localizedCategory = string.Empty;
     this.customTypeConverter = null;
     LocalizedPropertyAttribute attribute = null;
     foreach (Attribute attribute2 in basePropertyDescriptor.Attributes)
     {
         attribute = attribute2 as LocalizedPropertyAttribute;
         if (attribute != null)
         {
             break;
         }
     }
     if (attribute != null)
     {
         this.localizedName = attribute.Name;
         this.localizedDescription = attribute.Description;
         this.localizedCategory = attribute.Category;
     }
     else
     {
         this.localizedName = basePropertyDescriptor.Name;
         this.localizedDescription = basePropertyDescriptor.Description;
         this.localizedCategory = basePropertyDescriptor.Category;
     }
     this.basePropertyDescriptor = basePropertyDescriptor;
     if (basePropertyDescriptor.PropertyType == typeof(bool))
     {
         this.customTypeConverter = new BooleanTypeConverter();
     }
 }
開發者ID:vanloc0301,項目名稱:mychongchong,代碼行數:34,代碼來源:LocalizedPropertyDescriptor.cs

示例2: GetValue

 private object GetValue(DateTime dateTime, Type type, TypeConverter converter)
 {
     if (type.IsAssignableFrom(typeof(DateTime)))
         return dateTime;
     else
         return converter.ConvertFrom(dateTime);
 }
開發者ID:JanDeHud,項目名稱:LevelEditor,代碼行數:7,代碼來源:DateTimeEditor.cs

示例3: SetUp

		public void SetUp ()
		{
			Assembly a = typeof (LogConverter).Assembly;
			Type type = a.GetType ("System.Diagnostics.Design.StringValueConverter");
			Assert.IsNotNull (type);
			converter = (TypeConverter) Activator.CreateInstance (type);
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:7,代碼來源:StringValueConverterTest.cs

示例4: AddProperty

        public PropertyDescriptorCollection AddProperty(PropertyDescriptorCollection pdc, string propertyName, Type propertyType, TypeConverter converter,
            Attribute[] attributes)
        {
            List<PropertyDescriptor> properties = new List<PropertyDescriptor>(pdc.Count);

            for (int i = 0; i < pdc.Count; i++)
            {
                PropertyDescriptor pd = pdc[i];

                if (pd.Name != propertyName)
                {
                    properties.Add(pd);
                }
            }

            InstanceSavePropertyDescriptor ppd = new InstanceSavePropertyDescriptor(
                propertyName, propertyType, attributes);

            ppd.TypeConverter = converter;

            properties.Add(ppd);

            //PropertyDescriptor propertyDescriptor;

            return new PropertyDescriptorCollection(properties.ToArray());
        }
開發者ID:jiailiuyan,項目名稱:Gum,代碼行數:26,代碼來源:PropertyDescriptorHelper.cs

示例5: ParseFormattedValue

        public override object ParseFormattedValue(
            object formattedValue,
            DataGridViewCellStyle cellStyle,
            TypeConverter formattedValueTypeConverter,
            TypeConverter valueTypeConverter)
        {
            int result;

            if (int.TryParse(formattedValue.ToString(), NumberStyles.HexNumber, null, out result))
            {
                //Hex number
                return base.ParseFormattedValue(
                    "0x" + formattedValue,
                    cellStyle,
                    formattedValueTypeConverter,
                    valueTypeConverter
                    );
            }

            return base.ParseFormattedValue(
                formattedValue,
                cellStyle,
                formattedValueTypeConverter,
                valueTypeConverter
                );
        }
開發者ID:me-viper,項目名稱:OutputColorer,代碼行數:26,代碼來源:ColorPickerCell.cs

示例6: GetDateTime

 private DateTime GetDateTime(object value, TypeConverter converter)
 {
     if (typeof(DateTime).IsAssignableFrom(value.GetType()))
         return (DateTime) value;
     else
         return (DateTime) converter.ConvertTo(value, typeof(DateTime));
 }
開發者ID:JanDeHud,項目名稱:LevelEditor,代碼行數:7,代碼來源:DateTimeEditor.cs

示例7: IsForType

        public bool IsForType(TypeConverter converter) {
            Contract.Requires<ArgumentNullException>(converter != null);

            Type currentConverterType = this.typeConverter.GetType();
            Type paramConverterType = converter.GetType();
            return paramConverterType.IsAssignableFrom(currentConverterType);
        }
開發者ID:abc-software,項目名稱:abc.xacml,代碼行數:7,代碼來源:TypeConverterWrapper.cs

示例8: 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

示例9: LocalizedPropertyDescriptor

        public LocalizedPropertyDescriptor(PropertyDescriptor basePropertyDescriptor)
            : base(basePropertyDescriptor)
        {
            LocalizedPropertyAttribute localizedPropertyAttribute = null;

            foreach (Attribute attr in basePropertyDescriptor.Attributes) {
                localizedPropertyAttribute = attr as LocalizedPropertyAttribute;
                if (localizedPropertyAttribute != null) {
                    break;
                }
            }

            if (localizedPropertyAttribute != null) {
                localizedName        = localizedPropertyAttribute.Name;
                localizedDescription = localizedPropertyAttribute.Description;
                localizedCategory    = localizedPropertyAttribute.Category;
            } else {
                localizedName        = basePropertyDescriptor.Name;
                localizedDescription = basePropertyDescriptor.Description;
                localizedCategory    = basePropertyDescriptor.Category;
            }

            this.basePropertyDescriptor = basePropertyDescriptor;

            // "Booleans" get a localized type converter
            if (basePropertyDescriptor.PropertyType == typeof(System.Boolean)) {
                customTypeConverter = new BooleanTypeConverter();
            }
        }
開發者ID:ichengzi,項目名稱:SharpDevelop,代碼行數:29,代碼來源:LocalizedPropertyDescriptor.cs

示例10: GetFormattedValue

 protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
 {
     isVisualStyled = VisualStyleInformation.IsEnabledByUser & VisualStyleInformation.IsSupportedByOS;
     if (value == null)
     {
         return emptyImage;
     }
     float percentage = (float)((int)value);
     if (percentage == 0)
         return emptyImage;
     else
     {
         contentGraphics.Clear(Color.Transparent);
         float drawedPercentage = percentage > 100 ? 100 : percentage;
         if (isVisualStyled)
         {
             bigProgressRect.Width = (int)(66 * drawedPercentage / 100.0f);
             ProgressBarRenderer.DrawHorizontalBar(contentGraphics, bigBorderRect);
             ProgressBarRenderer.DrawHorizontalChunks(contentGraphics, bigProgressRect);
         }
         else
         {
             progressRect.Width = (int)(66 * drawedPercentage / 100.0f);
             contentGraphics.DrawRectangle(blackPen, borderRect);
             contentGraphics.FillRectangle(lightGreenBrush, progressRect);
         }
         contentGraphics.DrawString(percentage.ToString("0.00") + "%", this.DataGridView.Font, foreColor, 10, 5);
     }
     return contentImage;
 }
開發者ID:akhuang,項目名稱:NetExercise,代碼行數:30,代碼來源:DataGridViewDownloadProgressCell.cs

示例11: ConfigurationProperty

		public ConfigurationProperty (
					string name, Type type, object default_value,
					TypeConverter converter,
					ConfigurationValidatorBase validation,
					ConfigurationPropertyOptions flags)
			: this (name, type, default_value, converter, validation, flags, null)
		{ }
開發者ID:Xipas,項目名稱:Symplified.Auth,代碼行數:7,代碼來源:ConfigurationProperty.cs

示例12: GetFormattedValue

        protected override object GetFormattedValue(object value,
           int rowIndex, ref DataGridViewCellStyle cellStyle,
           TypeConverter valueTypeConverter,
           TypeConverter formattedValueTypeConverter,
           DataGridViewDataErrorContexts context)
        {
            object returnVal = String.Empty;

            if (value != null)
            {
                if (value.GetType() == typeof(byte[]))
                    returnVal = BitConverter.ToString((byte[])value);
                else if (value.GetType() == typeof(byte))
                    returnVal = BitConverter.ToString(new byte[] { (byte)value });
                else if (value.GetType() == typeof(int))
                    returnVal = BitConverter.ToString(BitConverter.GetBytes(((int)value)),0);
                else if (value.GetType() == typeof(uint))
                    returnVal = BitConverter.ToString(BitConverter.GetBytes(((uint)value)), 0);
                else if (value.GetType() == typeof(short))
                    returnVal = BitConverter.ToString(BitConverter.GetBytes(((short)value)), 0);
                else if (value.GetType() == typeof(ushort))
                    returnVal = BitConverter.ToString(BitConverter.GetBytes(((ushort)value)), 0);
            }
            return returnVal;
        }
開發者ID:AlgorithmsOfMathdestruction,項目名稱:meridian59-dotnet,代碼行數:25,代碼來源:ByteColumn.cs

示例13: GetFormattedValue

    // ========================================================================
    // Methods

    #region === Methods

    /// <summary>
    ///   Gets the formatted value of the cell's data.
    /// </summary>
    /// <returns>
    ///   The value.
    /// </returns>
    /// <param name = "value">The value to be formatted. </param>
    /// <param name = "rowIndex">The index of the cell's parent row. </param>
    /// <param name = "cellStyle">The <see cref = "T:System.Windows.Forms.DataGridViewCellStyle" /> in effect for the cell.</param>
    /// <param name = "valueTypeConverter">A <see cref = "T:System.ComponentModel.TypeConverter" /> associated with the value type that provides custom conversion to the formatted value type, or null if no such custom conversion is needed.</param>
    /// <param name = "formattedValueTypeConverter">A <see cref = "T:System.ComponentModel.TypeConverter" /> associated with the formatted value type that provides custom conversion from the value type, or null if no such custom conversion is needed.</param>
    /// <param name = "context">A bitwise combination of <see cref = "T:System.Windows.Forms.DataGridViewDataErrorContexts" /> values describing the context in which the formatted value is needed.</param>
    /// <exception cref = "T:System.Exception">Formatting failed and either there is no handler for the <see cref = "E:System.Windows.Forms.DataGridView.DataError" /> event of the <see cref = "T:System.Windows.Forms.DataGridView" /> control or the handler set the <see cref = "P:System.Windows.Forms.DataGridViewDataErrorEventArgs.ThrowException" /> property to true. The exception object can typically be cast to type <see cref = "T:System.FormatException" /> for type conversion errors or to type <see cref = "T:System.ArgumentException" /> if <paramref name = "value" /> cannot be found in the <see cref = "P:System.Windows.Forms.DataGridViewComboBoxCell.DataSource" /> or the <see cref = "P:System.Windows.Forms.DataGridViewComboBoxCell.Items" /> collection. </exception>
    protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle,
                                                TypeConverter valueTypeConverter,
                                                TypeConverter formattedValueTypeConverter,
                                                DataGridViewDataErrorContexts context)
    {
      return value;
    }
開發者ID:gbaychev,項目名稱:NClass,代碼行數:25,代碼來源:DataGridViewImageComboBoxColumnCell.cs

示例14: TestFixtureSetUp

		public void TestFixtureSetUp()
		{
			if (_dummyCulture == null)
				throw new Exception("Error setting up test - dummyCulture should not be NULL");
			if (CultureInfo.InvariantCulture.Equals(_dummyCulture))
				throw new Exception("Error setting up test - dummyCulture should not be invariant");
			if (_dummyCulture2 == null)
				throw new Exception("Error setting up test - dummyCulture2 should not be NULL");
			if (CultureInfo.InvariantCulture.Equals(_dummyCulture2))
				throw new Exception("Error setting up test - dummyCulture2 should not be invariant");
			if (_dummyCulture2.Equals(_dummyCulture))
				throw new Exception("Error setting up test - dummyCulture2 should not be the same as dummyCulture");

			// for testing purposes, set up the converter for a specific culture to have a custom mapping
			// normally, you would use TypeDescriptor.GetConverter, but we want to keep the test appdomain clean of these testing mods
			XMouseButtonsConverter converter = new XMouseButtonsConverter(_dummyCulture);
			IDictionary<XMouseButtons, string> relocalizedNames = new Dictionary<XMouseButtons, string>();
			relocalizedNames[XMouseButtons.Left] = "LMouse";
			relocalizedNames[XMouseButtons.Right] = "RMouse";
			relocalizedNames[XMouseButtons.Middle] = "Mouse3";
			relocalizedNames[XMouseButtons.XButton1] = "Mouse4";
			relocalizedNames[XMouseButtons.XButton2] = XMouseButtonsConverter.ButtonSeparator.ToString();
			converter.LocalizedNames = relocalizedNames;

			_converter = converter;
		}
開發者ID:m-berkani,項目名稱:ClearCanvas,代碼行數:26,代碼來源:XMouseButtonsConverterTest.cs

示例15: RightHandSideExpressionVisitor

        public RightHandSideExpressionVisitor(Type compareType)
        {
            _compareType = compareType;
            _toConverter = TypeDescriptor.GetConverter(_compareType);

            _value = () => { throw new InvalidOperationException("No match was found"); };
        }
開發者ID:jasonyandell,項目名稱:OdoyuleRules,代碼行數:7,代碼來源:RightHandSideExpressionVisitor.cs


注:本文中的System.ComponentModel.TypeConverter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。