public object GetPropertyOwner(PropertyDescriptor pd) { LocaleValue loc; IEnumerable <AmbientValueAttribute> col = pd.Attributes.OfType <AmbientValueAttribute>(); Strings.InitializeResource(); if (col.Count() > 0) { AmbientValueAttribute ambient = col.ElementAt(0); string[] tab = ((string)ambient.Value).Split(','); if (tab.Length > 0) { loc = new LocaleValue(tab[0], Strings._resources.GetString(tab[0])); loc.Parameters.AddRange(tab.TakeWhile((s, i) => i > 0)); } else { loc = new LocaleValue(pd.Name, pd.Name); } } else { loc = new LocaleValue(pd.Name, pd.Name); } return(loc); }
public void Ctor_Char() { char value = 'a'; var args = new AmbientValueAttribute(value); Assert.Equal(value, args.Value); }
private object GetPropertyValue(IDesignerSerializationManager manager, PropertyDescriptor property, object value, out bool validValue) { object obj2 = null; validValue = true; try { if (!property.ShouldSerializeValue(value)) { AmbientValueAttribute attribute = (AmbientValueAttribute)property.Attributes[typeof(AmbientValueAttribute)]; if (attribute != null) { return(attribute.Value); } DefaultValueAttribute attribute2 = (DefaultValueAttribute)property.Attributes[typeof(DefaultValueAttribute)]; if (attribute2 != null) { return(attribute2.Value); } validValue = false; } obj2 = property.GetValue(value); } catch (Exception exception) { validValue = false; manager.ReportError(System.Design.SR.GetString("SerializerPropertyGenFailed", new object[] { property.Name, exception.Message })); } return(obj2); }
public void Ctor_Bool() { bool value = true; var args = new AmbientValueAttribute(value); Assert.Equal(value, args.Value); }
public void Ctor_Float() { float value = 123; var args = new AmbientValueAttribute(value); Assert.Equal(value, args.Value); }
public void Ctor_Double() { double value = 123; var args = new AmbientValueAttribute(value); Assert.Equal(value, args.Value); }
public void Ctor_Long() { long value = 123; var args = new AmbientValueAttribute(value); Assert.Equal(value, args.Value); }
private string ConfigTypeValue() { string id = Request["id"]; foreach (var item in Enum.GetValues(typeof(EnumConfig))) { object[] objAttrs = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true); object[] objAmbients = item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(AmbientValueAttribute), true); if (objAttrs != null && objAttrs.Length > 0) { if ((int)item == int.Parse(id)) { DescriptionAttribute desc = objAttrs[0] as DescriptionAttribute; AmbientValueAttribute am = objAmbients[0] as AmbientValueAttribute; return(ReturnString.JsonToString(Prompt.win, desc.Description, am.Value.ToString())); } } } return(ReturnString.JsonToString(Prompt.error, "未知类型", null)); }
// Determine if two ambient attribute values are equal. public override bool Equals(Object value) { AmbientValueAttribute other = (value as AmbientValueAttribute); if (other != null) { if (obj == null) { return(other.obj == null); } else { return(obj.Equals(other.obj)); } } else { return(false); } }
public static IEnumerable <object[]> Equals_TestData() { var attribute = new AmbientValueAttribute(true); yield return(new object[] { attribute, attribute, true }); yield return(new object[] { new AmbientValueAttribute(true), new AmbientValueAttribute(true), true }); yield return(new object[] { new AmbientValueAttribute(true), new AmbientValueAttribute(false), false }); yield return(new object[] { new AmbientValueAttribute(true), new AmbientValueAttribute(null), false }); yield return(new object[] { new AmbientValueAttribute(null), new AmbientValueAttribute(false), false }); yield return(new object[] { new AmbientValueAttribute(null), new AmbientValueAttribute(null), true }); yield return(new object[] { new AmbientValueAttribute(true), new object(), false }); yield return(new object[] { new AmbientValueAttribute(true), null, false }); }
/// <summary> /// This retrieves the value of this property. If the property returns false /// from ShouldSerializeValue (indicating the ambient value for this property) /// This will look for an AmbientValueAttribute and use it if it can. /// </summary> private object GetPropertyValue(IDesignerSerializationManager manager, PropertyDescriptor property, object value, out bool validValue) { object propertyValue = null; validValue = true; try { if (!property.ShouldSerializeValue(value)) { // We aren't supposed to be serializing this property, but we decided to do // it anyway. Check the property for an AmbientValue attribute and if we // find one, use it's value to serialize. AmbientValueAttribute attr = (AmbientValueAttribute)property.Attributes[typeof(AmbientValueAttribute)]; if (attr != null) { return(attr.Value); } else { DefaultValueAttribute defAttr = (DefaultValueAttribute)property.Attributes[typeof(DefaultValueAttribute)]; if (defAttr != null) { return(defAttr.Value); } else { // nope, we're not valid... // validValue = false; } } } propertyValue = property.GetValue(value); } catch (Exception e) { // something failed -- we don't have a valid value validValue = false; manager.ReportError(new CodeDomSerializerException(string.Format(SR.SerializerPropertyGenFailed, property.Name, e.Message), manager)); } if ((propertyValue != null) && (!propertyValue.GetType().IsValueType) && !(propertyValue is Type)) { // DevDiv2 (Dev11) bug 187766 : property whose type implements ISupportInitialize is not // serialized with Begin/EndInit. Type type = TypeDescriptor.GetProvider(propertyValue).GetReflectionType(typeof(object)); if (!type.IsDefined(typeof(ProjectTargetFrameworkAttribute), false)) { // TargetFrameworkProvider is not attached TypeDescriptionProvider typeProvider = CodeDomSerializerBase.GetTargetFrameworkProvider(manager, propertyValue); if (typeProvider != null) { TypeDescriptor.AddProvider(typeProvider, propertyValue); } } } return(propertyValue); }
public override object EditValue( ITypeDescriptorContext context, IServiceProvider provider, object value) { //use IWindowsFormsEditorService object to display a control in the dropdown area IWindowsFormsEditorService frmsvr = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (frmsvr == null) { return(null); } SliderPropertyEditor slider = new SliderPropertyEditor(); slider.editorService = frmsvr; slider.contextDescriptor = context; slider.isDecimalValue = false; slider.trackLimits = new Point(0, 100); PropertyDescriptor propertydesc = null; if (context.PropertyDescriptor.Attributes.Count == 0) { System.Type propertyType = context.PropertyDescriptor.GetType(); System.Reflection.FieldInfo fieldInfo = propertyType.GetField( "descriptors", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ); PropertyDescriptor[] descriptors = (PropertyDescriptor[])(fieldInfo.GetValue(context.PropertyDescriptor)); propertydesc = descriptors[0]; } else { propertydesc = context.PropertyDescriptor; } foreach (Attribute att in propertydesc.Attributes) { if (att is AmbientValueAttribute) { AmbientValueAttribute tempAmbiantAttribute = att as AmbientValueAttribute; if (tempAmbiantAttribute.Value is string) { string paramStr = tempAmbiantAttribute.Value as string; string[] splittedParams = paramStr.Split('/'); //Treat Type if (splittedParams[0].Equals("float")) { slider.isFloatValue = true; } else if (splittedParams[0].Equals("decimal")) { slider.isDecimalValue = true; } //Treat Limits string strMin = splittedParams[1].Split(',')[0]; int min = 0; int.TryParse(strMin, out min); string strMax = splittedParams[1].Split(',')[1]; int max = 0; int.TryParse(strMax, out max); slider.trackLimits = new Point(min, max); break; } } } slider.trackBar.Minimum = slider.trackLimits.X; slider.trackBar.Maximum = slider.trackLimits.Y; if (context.PropertyDescriptor.Attributes.Count == 0) { if (slider.isDecimalValue == true || slider.isFloatValue == true) { int defaultValue = (slider.trackBar.Minimum + slider.trackBar.Maximum) / 2; defaultValue = Convert.ToInt32(Convert.ToDouble(defaultValue) * 100); slider.trackBar.Value = defaultValue; slider.trackBar.TickFrequency = 10; } else { int defaultValue = (slider.trackBar.Minimum + slider.trackBar.Maximum) / 2; slider.trackBar.Value = defaultValue; } } else { if (slider.isDecimalValue == true || slider.isFloatValue == true) { int currentValue = Convert.ToInt32(Convert.ToDouble(value) * 100); slider.trackBar.Value = currentValue; slider.trackBar.TickFrequency = 10; } else { int currentValue = Convert.ToInt32(value); slider.trackBar.Value = currentValue; } } frmsvr.DropDownControl(slider); if (slider.isDecimalValue == true) { decimal finalValue = (decimal)((float)slider.trackBar.Value / 100.0f); slider.Dispose(); return(finalValue); } else if (slider.isFloatValue == true) { float finalValue = (float)slider.trackBar.Value / 100.0f; slider.Dispose(); return(finalValue); } else { int finalValue = slider.trackBar.Value; slider.Dispose(); return(finalValue); } }
public void Ctor_String(string value) { var args = new AmbientValueAttribute(value); Assert.Same(value, args.Value); }
public void Ctor_Type_Value(Type type, string value, object expectedValue) { var attribute = new AmbientValueAttribute(type, value); Assert.Equal(expectedValue, attribute.Value); }
public void GetHashCode_Invoke_ReturnsConsistentValue() { var attribute = new AmbientValueAttribute(null); Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode()); }
public void Equals_Object_ReturnsExpected(AmbientValueAttribute attribute, object other, bool expected) { Assert.Equal(expected, attribute.Equals(other)); }
public void Ctor_Object(object value) { var args = new AmbientValueAttribute(value); Assert.Same(value, args.Value); }