internal Control CreateControl() { Debug.Assert(FieldTemplate == null); FieldTemplate = (Control)IMetaColumn.Model.FieldTemplateFactory.CreateFieldTemplate(Column, Mode, UIHint); if (FieldTemplate != null) { ((IFieldTemplate)FieldTemplate).SetHost(this); // If we got some extra attributes declared on the tag, assign them to the user control if it has matching properties if (_attributes != null) { var ucType = FieldTemplate.GetType(); foreach (var entry in _attributes) { // Look for a public property by that name on th user control var propInfo = ucType.GetProperty(entry.Key, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (propInfo != null) { // Convert the value to the type of the property and set it var value = PropertyConverter.ObjectFromString(propInfo.PropertyType, propInfo, entry.Value); propInfo.SetValue(FieldTemplate, value, null); } } } // Give it the column name as its ID, unless there is already a control by that name string id = GetControlIDFromColumnName(IMetaColumn.Name); if (FindControl(id) == null) { FieldTemplate.ID = id; } } return(FieldTemplate); }
public void TestObjectFromStringCantConvert() { MemberInfo mi = this.GetType().GetProperty("NotAllowedConverterProperty"); PropertyConverter.ObjectFromString(typeof(int), // can't be string mi, "foobar"); }
public void TestObjectFromString() { Assert.AreEqual(PropertyConverter.ObjectFromString( typeof(string), null, "value"), "value", "String Type"); MemberInfo mi = this.GetType().GetProperty("AllowedConverterProperty"); Assert.AreEqual(PropertyConverter.ObjectFromString( typeof(int), mi, "ConverterValue"), "ConverterValue", "Converter Value"); }
public void StaticMethods_Deny_Unrestricted() { Assert.AreEqual(SecurityAction.Demand, PropertyConverter.EnumFromString(typeof(SecurityAction), "Demand"), "EnumFromString"); Assert.AreEqual("Demand", PropertyConverter.EnumToString(typeof(SecurityAction), SecurityAction.Demand), "EnumToString"); Assert.AreEqual(String.Empty, PropertyConverter.ObjectFromString(typeof(string), null, String.Empty), "ObjectFromString"); }
public void TestObjectFromStringNullRef() { PropertyConverter.ObjectFromString(typeof(int), // can't be string null, "foobar"); }