public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(actualTypeConverter.CanConvertFrom(wrappedContext, sourceType)); }
public override bool IsValid(ITypeDescriptorContext context, object value) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(actualTypeConverter.IsValid(wrappedContext, value)); }
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(actualTypeConverter.CanConvertTo(wrappedContext, destinationType)); }
private static bool TryEvaluateExpression(string expressionString, Type locationValueType, LocationReferenceEnvironment locationReferenceEnvironment, ActivityContext context, out object result) { Type type; expressionString = string.Format(CultureInfo.InvariantCulture, "[{0}]", new object[] { expressionString }); if (locationValueType != null) { type = typeof(Activity <>).MakeGenericType(new Type[] { typeof(Location <>).MakeGenericType(new Type[] { locationValueType }) }); } else { type = typeof(Activity <object>); } ActivityWithResultConverter converter = new ActivityWithResultConverter(type); TypeDescriptorContext context2 = new TypeDescriptorContext { LocationReferenceEnvironment = locationReferenceEnvironment }; ActivityWithResult expression = converter.ConvertFromString(context2, expressionString) as ActivityWithResult; if (locationValueType != null) { LocationHelper helper = (LocationHelper)Activator.CreateInstance(typeof(LocationHelper).MakeGenericType(new Type[] { locationValueType })); return(helper.TryGetValue(expression, locationReferenceEnvironment, context, out result)); } return(TryEvaluateExpression <object>(expression, locationReferenceEnvironment, context, out result)); }
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e) { Point cellLocation = DataGridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Location; cellLocation.Offset(e.Location); if (buttonBounds.Contains(cellLocation)) { UITypeEditor editor = OwningDesignerColumn.GetBoundPropertyEditor(); if (editor != null && editor.GetEditStyle() == UITypeEditorEditStyle.Modal) { ITypeDescriptorContext context = new TypeDescriptorContext(DataGridView.Site, OwningDesignerColumn.GetBoundProperty(), this); object value = GetValue(e.RowIndex); value = editor.EditValue(context, DataGridView.Site, value); SetValue(e.RowIndex, value); } // Notify the grid the cell was modified DataGridView.NotifyCurrentCellDirty(true); DataGridView.NotifyCurrentCellDirty(false); } else { base.OnMouseClick(e); } }
public void ConvertFrom_GivenEmptyString_ThrowsNotSupportedException() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Throws <NotSupportedException>(() => converter.ConvertFrom(context, culture, "")); }
/// <summary> /// Put the values from the iniProperties to the proxied object /// </summary> /// <param name="iniSections"></param> /// <param name="iniSection"></param> private void FillSection(IDictionary <string, IDictionary <string, string> > iniSections, IIniSection iniSection) { var sectionName = iniSection.GetSectionName(); // Might be null iniSections.TryGetValue(sectionName, out var iniProperties); var iniValues = from iniValue in iniSection.GetIniValues().Values.ToList() where iniValue.Behavior.Read select iniValue; foreach (var iniValue in iniValues) { ITypeDescriptorContext context = null; try { var propertyDescription = TypeDescriptor.GetProperties(iniSection.GetType()).Find(iniValue.PropertyName, true); context = new TypeDescriptorContext(iniSection, propertyDescription); } catch (Exception ex) { Log.Warn().WriteLine(ex.Message); } // Test if there is a separate section for this inivalue, this is used for Dictionaries if (iniSections.TryGetValue($"{sectionName}-{iniValue.IniPropertyName}", out var value)) { try { iniValue.Value = iniValue.ValueType.ConvertOrCastValueToType(value, iniValue.Converter, context); continue; } catch (Exception ex) { Log.Warn().WriteLine(ex.Message); } } // Skip if the iniProperties doesn't have anything if (iniProperties is null || iniProperties.Count == 0) { continue; } // Skip values that don't have a property if (!iniProperties.TryGetValue(iniValue.IniPropertyName, out var stringValue)) { continue; } // convert try { iniValue.Value = iniValue.ValueType.ConvertOrCastValueToType(stringValue, iniValue.Converter, context); } catch (Exception ex) { Log.Warn().WriteLine(ex.Message); } } }
public void ConvertFrom_GivenWrongQuantity_ThrowsArgumentException() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Throws <ArgumentException>(() => converter.ConvertFrom(context, culture, "1m^2")); }
private TypeConverter GetTypeConversionInfoForPropertySegment(WorkflowMarkupSerializationManager serializationManager, Type propertyType, out ITypeDescriptorContext context) { TypeConverter converter = null; context = null; PropertySegmentPropertyInfo propertyInfo = serializationManager.Context[typeof(PropertySegmentPropertyInfo)] as PropertySegmentPropertyInfo; if (propertyInfo.PropertySegment != null) { if (propertyInfo.PropertySegment.PropertyDescriptor != null) { context = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyInfo.PropertySegment.PropertyDescriptor, propertyInfo.PropertySegment.Object); converter = propertyInfo.PropertySegment.PropertyDescriptor.Converter; } else if (propertyInfo.PropertySegment.Object != null) { PropertyDescriptor propertyDescriptor = TypeDescriptor.GetProperties(propertyInfo.PropertySegment.Object)[propertyInfo.Name]; if (propertyDescriptor != null) { context = new TypeDescriptorContext(propertyInfo.PropertySegment.ServiceProvider, propertyDescriptor, propertyInfo.PropertySegment.Object); converter = propertyDescriptor.Converter; } } } if (propertyType != null && converter == null) { converter = TypeDescriptor.GetConverter(propertyType); } return(converter); }
/// <summary> /// Load the Combobox value in Localization on checkbox basis /// </summary> void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) { var el = e.TableCellIdentity; var item = el.DisplayElement != null?el.DisplayElement.GetData() : null; if (item is Employee && el.Column != null && el.Column.FieldDescriptor != null && el.Column.FieldDescriptor.FieldPropertyType.IsEnum && (el.DisplayElement.Kind == DisplayElementKind.Record || el.DisplayElement.Kind == DisplayElementKind.AddNewRecord)) { var context = new TypeDescriptorContext(item, e.Style.PropertyDescriptor); var converter = e.Style.PropertyDescriptor.Converter; if (converter != null) { var contextualValues = converter.GetStandardValues(context).OfType <object>().ToArray(); e.Style.CellType = "ComboBox"; if (!checkBox1.Checked) { e.Style.DataSource = contextualValues; } } } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(uiTypeEditor.EditValue(wrappedContext, provider, value)); }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return(actualTypeConverter.ConvertFrom(wrappedContext, culture, value)); }
public void ConvertTo_GivenWrongType_ThrowsNotSupportedException(Type value) { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Length length = Length.FromMeters(1); Assert.Throws <NotSupportedException>(() => converter.ConvertTo(length, value)); }
public void ConvertFrom_GivenStringWithPower_minus1() { var converter = new QuantityTypeConverter <CoefficientOfThermalExpansion>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(CoefficientOfThermalExpansion.FromInverseKelvin(1), converter.ConvertFrom(context, culture, "1K⁻¹")); Assert.Equal(CoefficientOfThermalExpansion.FromInverseKelvin(1), converter.ConvertFrom(context, culture, "1K^-1")); }
public void ConvertFrom_GivenStringWithPower_1() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(Length.FromMeters(1), converter.ConvertFrom(context, culture, "1m")); Assert.Equal(Length.FromMeters(1), converter.ConvertFrom(context, culture, "1m^1")); }
public void ConvertFrom_GivenStringWithPower_2() { var converter = new QuantityTypeConverter <Area>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(Area.FromSquareMeters(1), converter.ConvertFrom(context, culture, "1m²")); Assert.Equal(Area.FromSquareMeters(1), converter.ConvertFrom(context, culture, "1m^2")); }
public void ConvertFrom_GivenStringWithPower_3() { var converter = new QuantityTypeConverter <Volume>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(Volume.FromCubicMeters(1), converter.ConvertFrom(context, culture, "1m³")); Assert.Equal(Volume.FromCubicMeters(1), converter.ConvertFrom(context, culture, "1m^3")); }
public void ConvertFrom_GivenStringWithPower_4() { var converter = new QuantityTypeConverter <AreaMomentOfInertia>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(AreaMomentOfInertia.FromMetersToTheFourth(1), converter.ConvertFrom(context, culture, "1m⁴")); Assert.Equal(AreaMomentOfInertia.FromMetersToTheFourth(1), converter.ConvertFrom(context, culture, "1m^4")); }
public void ConvertFrom_GivenStringWithPower_minus2() { var converter = new QuantityTypeConverter <MassFlux>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMeter(1), converter.ConvertFrom(context, culture, "1kg·s⁻¹·m⁻²")); Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMeter(1), converter.ConvertFrom(context, culture, "1kg·s^-1·m^-2")); Assert.Equal(MassFlux.FromKilogramsPerSecondPerSquareMeter(1), converter.ConvertFrom(context, culture, "1kg*s^-1*m^-2")); }
public void ConvertFrom_GivenQuantityStringAndContextWithNoAttributes_ReturnsQuantityWithBaseUnitIfNotSpecified(string str, double expectedValue, Enum expectedUnit) { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); var convertedValue = (Length)converter.ConvertFrom(context, culture, str); Assert.Equal(expectedValue, convertedValue.Value); Assert.Equal(expectedUnit, convertedValue.Unit); }
public void ConvertTo_GivenStringType_ReturnsQuantityString() { var converter = new QuantityTypeConverter <Length>(Length.Zero); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Length length = Length.FromMeters(1); string convertedQuantity = (string)converter.ConvertTo(length, typeof(string)); Assert.Equal("1 m", convertedQuantity); }
public void ConvertTo_GivenSomeQuantityAndContextWithoutProperty_ReturnsQuantityStringInUnitOfQuantity() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext(); Length length = Length.FromMeters(1); string convertedQuantity = (string)converter.ConvertTo(context, culture, length, typeof(string)); Assert.Equal("1 m", convertedQuantity); }
public void ConvertFrom_GivenDefaultUnitAttributeWithWrongUnitType_ThrowsArgumentException() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { new DefaultUnitAttribute(Units.VolumeUnit.CubicMeter) }); Assert.Throws <ArgumentException>(() => converter.ConvertFrom(context, culture, "1")); }
public void ConvertTo_GivenSomeQuantitysAndContextWithNoAttributes_ReturnsQuantityStringInUnitOfQuantity() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { }); Length length = Length.FromMeters(1); string convertedQuantity = (string)converter.ConvertTo(context, culture, length, typeof(string)); Assert.Equal("1 m", convertedQuantity); }
public void ConvertFrom_GivenQuantityStringAndContextWithDefaultUnitAttribute_ReturnsQuantityWithGivenDefaultUnitIfNotSpecified(string str, double expectedValue, Enum expectedUnit) { var converter = new QuantityTypeConverter <Length>(Length.Zero); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { new DefaultUnitAttribute(Units.LengthUnit.Centimeter) }); var convertedValue = (Length)converter.ConvertFrom(context, culture, str); Assert.Equal(expectedValue, convertedValue.Value); Assert.Equal(expectedUnit, convertedValue.Unit); }
public void CanConvertFrom () { var tc = XamlLanguage.Type.TypeConverter.ConverterInstance; Assert.IsFalse (tc.CanConvertFrom (null, typeof (string)), "#1"); Assert.IsFalse (tc.CanConvertFrom (null, typeof (Type)), "#2"); Assert.IsFalse (tc.CanConvertFrom (null, typeof (Type)), "#3"); Assert.IsTrue (tc.CanConvertFrom (null, typeof (InstanceDescriptor)), "#4"); var idc = new TypeDescriptorContext () {Instance = "x:Int32", Service = new XamlTypeResolver ()}; // gives no difference ... Assert.IsFalse (tc.CanConvertFrom (idc, typeof (string)), "#5"); Assert.IsFalse (tc.CanConvertFrom (idc, typeof (Type)), "#6"); Assert.IsFalse (tc.CanConvertFrom (idc, typeof (TypeExtension)), "#7"); }
public void ConvertTo_TestDisplayAsFormatting_ReturnsQuantityStringWithDisplayUnitFormateAsValueOnly() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { new DisplayAsUnitAttribute(Units.LengthUnit.Decimeter, "v") }); Length length = Length.FromMeters(1); string convertedQuantity = (string)converter.ConvertTo(context, culture, length, typeof(string)); Assert.Equal("10", convertedQuantity); }
private bool EditItemsCallback(object context) { ListItemsCollectionEditor itemsEditor = new ListItemsCollectionEditor(typeof(ListItemCollection)); IDesignerHost designerHost = (IDesignerHost)this.GetService(typeof(IDesignerHost)); PropertyDescriptor editedProperty = (PropertyDescriptor)context; ITypeDescriptorContext typeDescriptorContext = new TypeDescriptorContext(designerHost, editedProperty, base.Component); IServiceProvider serviceProvider = new WindowsFormsEditorService(this); itemsEditor.EditValue(typeDescriptorContext, serviceProvider, editedProperty.GetValue(base.Component)); return(true); }
public void ConvertTo_TestDisplayAsFormattingWithoutDefinedUnit_ReturnsQuantityStringWithQuantetiesUnitAndFormatedAsValueOnly() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { new DisplayAsUnitAttribute(null, "v") }); Length length = Length.FromMeters(1); string convertedQuantity = (string)converter.ConvertTo(context, culture, length, typeof(string)); Assert.Equal("1", convertedQuantity); }
public void ConvertTo_GivenCurrentCulture_ReturnValueFormattedAccordingToGivenCulture(bool useDisplayAsAttribute) { QuantityTypeConverter <Length> converter = new(); var attributes = useDisplayAsAttribute ? new Attribute[] { new DisplayAsUnitAttribute(Units.LengthUnit.Meter) } : Array.Empty <Attribute>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", attributes); CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-AT"); // uses comma as decimal separator CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; // uses dot as decimal separator Length length = Length.FromMeters(1.5); string expectedResult = length.ToString(CultureInfo.CurrentCulture); string convertedQuantity = (string)converter.ConvertTo(context, CultureInfo.CurrentCulture, length, typeof(string)); Assert.Equal(expectedResult, convertedQuantity); }
public void ConvertTo_GivenSomeQuantitysAndContextWithDisplayAsUnitAttributes_ReturnsQuantityStringInSpecifiedDisplayUnit() { var converter = new QuantityTypeConverter <Length>(); ITypeDescriptorContext context = new TypeDescriptorContext("SomeMemberName", new Attribute[] { new DisplayAsUnitAttribute(Units.LengthUnit.Decimeter) }); Length length = Length.FromMeters(1); string convertedQuantityDefaultCulture = (string)converter.ConvertTo(length, typeof(string)); string convertedQuantitySpecificCulture = (string)converter.ConvertTo(context, culture, length, typeof(string)); Assert.Equal("1 m", convertedQuantityDefaultCulture); Assert.Equal("10 dm", convertedQuantitySpecificCulture); }
public override bool GetPaintValueSupported(ITypeDescriptorContext context) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return uiTypeEditor.GetPaintValueSupported(wrappedContext); }
private void SetupControl() { var editorType = EditorType.Default; this.context = GetTypeDescriptorContext(ValueProperty); if (this.context != null) { this.typeEditor = (UITypeEditor)this.context.PropertyDescriptor.GetEditor(typeof(UITypeEditor)); if (this.typeEditor != null && this.typeEditor.GetEditStyle(null) != UITypeEditorEditStyle.DropDown) { editorType = EditorType.TypeEditor; } else if (this.context.PropertyDescriptor.Converter.GetStandardValuesSupported()) { editorType = EditorType.StandardValues; } } this.SetValue(EditorTypePropertyKey, editorType); }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.CanConvertFrom(wrappedContext, sourceType); }
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.CanConvertTo(wrappedContext, destinationType); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.ConvertTo(wrappedContext, culture, value, destinationType); }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.GetStandardValues(wrappedContext); }
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.GetStandardValuesSupported(wrappedContext); }
public override bool IsValid(ITypeDescriptorContext context, object value) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return actualTypeConverter.IsValid(wrappedContext, value); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return uiTypeEditor.EditValue(wrappedContext, provider, value); }
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { ITypeDescriptorContext wrappedContext = new TypeDescriptorContext(context, actualInstance); return uiTypeEditor.GetEditStyle(wrappedContext); }
private LineInfo ProcessTaskItem(DesignerActionList list, DesignerActionItem item) { Line line = null; if (item is DesignerActionMethodItem) { line = new MethodLine(this._serviceProvider, this); } else if (item is DesignerActionPropertyItem) { DesignerActionPropertyItem item2 = (DesignerActionPropertyItem) item; PropertyDescriptor propDesc = TypeDescriptor.GetProperties(list)[item2.MemberName]; if (propDesc == null) { throw new InvalidOperationException(System.Design.SR.GetString("DesignerActionPanel_CouldNotFindProperty", new object[] { item2.MemberName, list.GetType().FullName })); } TypeDescriptorContext context = new TypeDescriptorContext(this._serviceProvider, propDesc, list); UITypeEditor editor = (UITypeEditor) propDesc.GetEditor(typeof(UITypeEditor)); bool standardValuesSupported = propDesc.Converter.GetStandardValuesSupported(context); if (editor == null) { if (propDesc.PropertyType == typeof(bool)) { if (IsReadOnlyProperty(propDesc)) { line = new TextBoxPropertyLine(this._serviceProvider, this); } else { line = new CheckBoxPropertyLine(this._serviceProvider, this); } } else if (standardValuesSupported) { line = new EditorPropertyLine(this._serviceProvider, this); } else { line = new TextBoxPropertyLine(this._serviceProvider, this); } } else { line = new EditorPropertyLine(this._serviceProvider, this); } } else { if (!(item is DesignerActionTextItem)) { return null; } if (item is DesignerActionHeaderItem) { line = new HeaderLine(this._serviceProvider, this); } else { line = new TextLine(this._serviceProvider, this); } } return new LineInfo(list, item, line); }