Beispiel #1
0
		public void ConvertFrom ()
		{
			UnitConverter c = new UnitConverter ();
			Assert.IsTrue (c.CanConvertFrom (typeof (string)), "string");
			Assert.AreEqual (c.ConvertFrom ("1 px"), new Unit (1), "ConvertFrom(string)");
			Assert.IsFalse (c.CanConvertFrom (typeof (Unit)), "Unit");
		}
Beispiel #2
0
		public void ConvertTo ()
		{
			UnitConverter c = new UnitConverter ();
			Assert.IsTrue (c.CanConvertTo (typeof (string)), "string");
			Assert.AreEqual (c.ConvertTo (new Unit (1), typeof (string)), new Unit (1).ToString (), "ConvertTo(string)");
			Assert.IsFalse (c.CanConvertTo (typeof (Unit)), "Unit");
		}
Beispiel #3
0
        private static Control setProperty(Control control, string keyValuePair)
        {
            string key = keyValuePair.Split(new char[]{'='})[0];
            string value = keyValuePair.Split(new char[]{'='})[1];

            // Iterate thru all properties for this control
            PropertyInfo[] propertyList = control.GetType().GetProperties();

            foreach(PropertyInfo property in propertyList)
            {
                // Do we have a value for this property?
                if (property.Name.ToLower() == key.ToLower())
                {
                    object objValue = null;

                    switch(property.PropertyType.Name)
                    {
                        case "String":
                            objValue = (object)value;
                            break;

                        case "Int32":
                            objValue = (object)Convert.ToInt32(value);
                            break;

                        case "Boolean":
                            objValue = (object)Convert.ToBoolean(value);
                            break;

                        case "Unit":
                            UnitConverter converter = new UnitConverter();
                            objValue = converter.ConvertFromString(value);
                            break;
                    }

                    if (objValue != null)
                    {
                        property.SetValue(control, objValue, null);
                    }
                }
            }

            return control;
        }