• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ComponentModel.TypeConverter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



TypeConverter类属于System.ComponentModel命名空间,在下文中一共展示了TypeConverter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: OptionConfigurationPropertyAttribute

		public OptionConfigurationPropertyAttribute(string name, Type type, object defaultValue, OptionConfigurationPropertyBehavior behavior, TypeConverter converter)
		{
			_name = name == null ? string.Empty : name.Trim();
			_type = type;
			_defaultValue = defaultValue;
			_behavior = behavior;
			_converter = converter;
		}
开发者ID:Flagwind,项目名称:Zongsoft.CoreLibrary,代码行数:8,代码来源:OptionConfigurationPropertyAttribute.cs


示例15: ConfigurationProperty

 public ConfigurationProperty(String name,
                              Type type,
                              Object defaultValue,
                              TypeConverter typeConverter,
                              ConfigurationValidatorBase validator,
                              ConfigurationPropertyOptions options)
     : this(name, type, defaultValue, typeConverter, validator, options, null) {
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:8,代码来源:ConfigurationProperty.cs


示例16: StringConvertibleType

        public StringConvertibleType(TypeConverter converter, Type sourceType)
        {
            if (converter == null) throw new ArgumentNullException(nameof(converter));
            if (sourceType == null) throw new ArgumentNullException(nameof(sourceType));

            this.converter = converter;
            this.sourceType = sourceType;
        }
开发者ID:NMFCode,项目名称:NMF,代码行数:8,代码来源:StringConvertibleType.cs


示例17: DefaultValueConverter

 protected DefaultValueConverter(TypeConverter typeConverter, Type sourceType, Type targetType, bool shouldConvertFrom, bool shouldConvertTo)
 {
     this.typeConverter = typeConverter;
     this.sourceType = sourceType;
     this.targetType = targetType;
     this.shouldConvertFrom = shouldConvertFrom;
     this.shouldConvertTo = shouldConvertTo;
 }
开发者ID:evnik,项目名称:UIFramework,代码行数:8,代码来源:DefaultValueConverter.cs


示例18: GetFormattedValue

 protected override object GetFormattedValue(object value, int rowIndex, ref System.Windows.Forms.DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, System.Windows.Forms.DataGridViewDataErrorContexts context)
 {
     if (value != null)
     {
         return TypeDescriptor.GetConverter(value).ConvertToString(value);
     }
     return "";
 }
开发者ID:u4097,项目名称:SQLScript,代码行数:8,代码来源:DataGridViewNumericCell.cs


示例19: NameableConverter

 /// <summary>
 /// Initializes a new instance of the <see cref="NameableConverter"/> class.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <exception cref="System.ArgumentException">NameableConverterBadCtorArg;type</exception>
 public NameableConverter(Type type)
 {
     _nameableType = type;
     _simpleType = Nullable.GetUnderlyingType(type);
     if (_simpleType == null)
         throw new ArgumentException("NameableConverterBadCtorArg", "type");
     _simpleTypeConverter = TypeDescriptor.GetConverter(_simpleType);
 }
开发者ID:BclEx,项目名称:BclEx-Abstract,代码行数:13,代码来源:NameableConverter.cs


示例20: GetFormattedValue

        protected override object GetFormattedValue(object value,
            int rowIndex, ref DataGridViewCellStyle cellStyle,
            TypeConverter valueTypeConverter,
            TypeConverter formattedValueTypeConverter,
            DataGridViewDataErrorContexts context)
        {
            if (value == null)
                value = 0;

            int progressVal = (int)value;

            if (progressVal > maxVal)
                progressVal = maxVal;
            if (progressVal < minVal)
                progressVal = minVal;

            Bitmap bmp = new Bitmap(OwningColumn.Width - margin, OwningRow.Height - margin);
            Bitmap bmptxt = new Bitmap(OwningColumn.Width, OwningRow.Height);

            pb.Height = bmp.Height;
            pb.Width = bmp.Width;

            pb.BackColor = System.Drawing.Color.Transparent;
            pb.BackgroundColor = System.Drawing.Color.FromArgb(((System.Byte)(100)), ((System.Byte)(201)), ((System.Byte)(201)), ((System.Byte)(201)));
            pb.StartColor = this.startColor;
            pb.EndColor = this.endColor;
            //pb.HighlightColor = System.Drawing.Color.Orange;
            pb.TabIndex = 0;

            pb.Value = progressVal;
            pb.Update();
            pb.Invalidate();

            lbl.AutoSize = false;
            lbl.TextAlign = ContentAlignment.MiddleCenter;
            lbl.Height = bmptxt.Height;
            lbl.Width = bmptxt.Width;

            if (!this.Selected)
            {
                lbl.ForeColor = cellStyle.ForeColor;
                lbl.BackColor = cellStyle.BackColor;
            }
            else
            {
                lbl.ForeColor = cellStyle.SelectionForeColor;
                lbl.BackColor = cellStyle.SelectionBackColor;
            }

            pb.DrawToBitmap(bmp, pb.ClientRectangle);

            lbl.Text = String.Format("{0}%", progressVal);
            lbl.Image = bmp;
            lbl.ImageAlign = ContentAlignment.MiddleCenter;
            lbl.DrawToBitmap(bmptxt, lbl.ClientRectangle);

            return bmptxt;
        }
开发者ID:samysilva,项目名称:WUManager,代码行数:58,代码来源:DataGridViewProgressCell.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ComponentModel.TypeDescriptionProvider类代码示例发布时间:2022-05-26
下一篇:
C# ComponentModel.SortDescription类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap