本文整理匯總了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();
}
}
示例2: GetValue
private object GetValue(DateTime dateTime, Type type, TypeConverter converter)
{
if (type.IsAssignableFrom(typeof(DateTime)))
return dateTime;
else
return converter.ConvertFrom(dateTime);
}
示例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);
}
示例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());
}
示例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
);
}
示例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));
}
示例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);
}
示例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)));
}
}
}
示例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();
}
}
示例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;
}
示例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)
{ }
示例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;
}
示例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;
}
示例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;
}
示例15: RightHandSideExpressionVisitor
public RightHandSideExpressionVisitor(Type compareType)
{
_compareType = compareType;
_toConverter = TypeDescriptor.GetConverter(_compareType);
_value = () => { throw new InvalidOperationException("No match was found"); };
}