public static void AddGraphicProperties(List<PropertyDescriptor> allProperties, PropertyDescriptorCollection props) { PropertyDescriptor prop = null; prop = props.Find("ForeColor",true); allProperties.Add(prop); prop = props.Find("DashStyle",true); allProperties.Add(prop); prop = props.Find("Thickness",true); allProperties.Add(prop); }
public static void AddTextBasedProperties(List<PropertyDescriptor> allProperties, PropertyDescriptorCollection props) { PropertyDescriptor prop = props.Find("Font",true); allProperties.Add(prop); prop = props.Find("FormatString",true); allProperties.Add(prop); prop = props.Find("StringTrimming",true); allProperties.Add(prop); prop = props.Find("ContentAlignment",true); allProperties.Add(prop); prop = props.Find("TextAlignment",true); allProperties.Add(prop); prop = props.Find("CanGrow",true); allProperties.Add(prop); prop = props.Find("CanShrink",true); allProperties.Add(prop); prop = props.Find("DataType",true); allProperties.Add(prop); }
/* * Does the property filtering... */ private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc) { ArrayList toRemove = new ArrayList(); PropertyDescriptor pd = pdc.Find("fileAction", true); if (pd != null) { object val = pd.GetValue(this); if (val != null) { if ((PGPFileAction)val == PGPFileAction.Decrypt) foreach (string s in invalidDecrypt) toRemove.Add(s); else if ((PGPFileAction)val == PGPFileAction.Encrypt) foreach (string s in invalidEncrypt) toRemove.Add(s); } } PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { }); foreach (PropertyDescriptor p in pdc) if (!toRemove.Contains(p.Name)) adjustedProps.Add(p); return adjustedProps; }
public static void AddDefaultProperties (List<PropertyDescriptor> allProperties, PropertyDescriptorCollection props ) { PropertyDescriptor prop = props.Find("Location",true); allProperties.Add(prop); prop = props.Find("Size",true); allProperties.Add(prop); prop = props.Find("BackColor",true); allProperties.Add(prop); // need this for Contextmenu's prop = props.Find("ContextMenu",true); allProperties.Add(prop); }
private IEnumerable<AbstractField> ExtractIndexDataFromDocument(PropertyDescriptorCollection properties, object doc, out string newDocId) { if (properties == null) { properties = TypeDescriptor.GetProperties(doc); } newDocId = properties.Find("__document_id", false).GetValue(doc) as string; return AnonymousObjectToLuceneDocumentConverter.Index(doc, properties, indexDefinition, Field.Store.NO); }
/// <summary> /// Retrieves a property descriptor from its name. /// </summary> /// <param name="propertyName">the name of a property</param> /// <param name="collection">the property collection to search</param> /// <returns>the corresponding property descriptor</returns> /// <exception cref="InvalidPropertyException"> if the property does not exist</exception> private PropertyDescriptor GetPropertyDescriptor(string propertyName, PropertyDescriptorCollection collection) { var property = collection.Find(propertyName, true); if (property == null) { throw new InvalidPropertyException(string.Format("Invalid property {0} on type {1}", propertyName, _wrappedInstance.GetType()), _wrappedInstance.GetType(), propertyName); } return property; }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptor pd; var pdc = new PropertyDescriptorCollection(base.GetProperties(attributes).Cast<PropertyDescriptor>().ToArray()); if ((pd = pdc.Find("Source", false)) != null) { pdc.Add(TypeDescriptor.CreateProperty(typeof(Binding), pd, new Attribute[] { new DefaultValueAttribute("null") })); pdc.Remove(pd); } return pdc; }
public void Find_Name_Null () { PropertyDescriptorCollection descriptors; descriptors = new PropertyDescriptorCollection ( new PropertyDescriptor[] { new MockPropertyDescriptor ("A", 1), new MockPropertyDescriptor ("b", 2)}); try { descriptors.Find (null, false); Assert.Fail ("#A1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2"); Assert.IsNull (ex.InnerException, "#A3"); Assert.IsNotNull (ex.Message, "#A4"); Assert.IsNotNull (ex.ParamName, "#A5"); } try { descriptors.Find (null, true); Assert.Fail ("#B1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2"); Assert.IsNull (ex.InnerException, "#B3"); Assert.IsNotNull (ex.Message, "#B4"); Assert.IsNotNull (ex.ParamName, "#B5"); } descriptors = PropertyDescriptorCollection.Empty; try { descriptors.Find (null, false); Assert.Fail ("#C1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2"); Assert.IsNull (ex.InnerException, "#C3"); Assert.IsNotNull (ex.Message, "#C4"); Assert.IsNotNull (ex.ParamName, "#C5"); } try { descriptors.Find (null, true); Assert.Fail ("#D1"); } catch (ArgumentNullException ex) { Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#D2"); Assert.IsNull (ex.InnerException, "#D3"); Assert.IsNotNull (ex.Message, "#D4"); Assert.IsNotNull (ex.ParamName, "#D5"); } }
private PropertyDescriptorCollection ConvertPropertys(PropertyDescriptorCollection pdc) { PropertyDescriptor pd = pdc.Find("ItemsSource", false); if (pd != null) { PropertyDescriptor pdNew = TypeDescriptor.CreateProperty(typeof(ItemsControl), pd, new Attribute[] { new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible), new DefaultValueAttribute("") }); pdc.Add(pdNew); pdc.Remove(pd); } return pdc; }
private object GetAttributeValue(object obj, string attributeName) { Check.Require(obj != null, string.Format(CommonStrings.XMustNotBeNull, "obj")); System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(obj); System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(attributeName, true); if (property == null) { return(null); } object attributeObj = property.GetValue(obj); return(attributeObj); }
/* * Does the property filtering... */ private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc) { ArrayList toRemove = new ArrayList(); /* Hide invalid File Actions */ PropertyDescriptor pd = pdc.Find("fileAction", true); if (pd != null) { object val = pd.GetValue(this); if (val != null) { if((ZipFileAction)val == ZipFileAction.Decompress) foreach (string s in invalidDeCompress) toRemove.Add(s); } } /* Hide Compression types */ PropertyDescriptor cTypePD = pdc.Find("compressionType", true); if (cTypePD != null) { object val = cTypePD.GetValue(this); if (val != null) { if ((CompressionType)val == CompressionType.Zip) foreach (string s in invalidZip) toRemove.Add(s); else if ((CompressionType)val == CompressionType.Tar) foreach (string s in invalidTar) toRemove.Add(s); } } PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { }); foreach (PropertyDescriptor p in pdc) if (!toRemove.Contains(p.Name)) adjustedProps.Add(p); return adjustedProps; }
private IndexingResult ExtractIndexDataFromDocument(AnonymousObjectToLuceneDocumentConverter anonymousObjectToLuceneDocumentConverter, PropertyDescriptorCollection properties, object doc) { if (properties == null) { properties = TypeDescriptor.GetProperties(doc); } var abstractFields = anonymousObjectToLuceneDocumentConverter.Index(doc, properties, indexDefinition, Field.Store.NO).ToList(); return new IndexingResult() { Fields = abstractFields, NewDocId = properties.Find(Constants.DocumentIdFieldName, false).GetValue(doc) as string, ShouldSkip = properties.Count > 1 // we always have at least __document_id && abstractFields.Count == 0 }; }
public override bool ValidValue(object dataValue) { Check.Require(dataValue != null, string.Format(CommonStrings.XMustNotBeNull, "dataValue")); IRmType rmType = dataValue as IRmType; Check.Require(rmType != null, string.Format(AmValidationStrings.ValueMustImplementIRmType, dataValue.GetType().ToString())); bool result = true; rmType.Constraint = this; if (!IsSameRmType(rmType)) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectRmType, RmTypeName, rmType.GetRmTypeName())); } if (!result || !AnyAllowed()) { OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable = dataValue as OpenEhr.RM.Common.Archetyped.Impl.Locatable; if (locatable != null) { ValidationUtility.PopulateLocatableAttributes(this, locatable); if (Parent != null && ArchetypeNodeId != locatable.ArchetypeNodeId) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectNodeId, ArchetypeNodeId, locatable.ArchetypeNodeId)); } } System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(dataValue); if (Attributes != null) { foreach (CAttribute cAttribute in Attributes) { object attributeObject = null; string attributeName = RmFactory.GetOpenEhrV1RmName(cAttribute.RmAttributeName); System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(attributeName, true); // if the attributeName is not a class property, it must be a class function. if (property == null) { System.Reflection.MethodInfo method = dataValue.GetType().GetMethod(attributeName); if (method == null) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.UnexpectedAttributeX, attributeName)); continue; } else { attributeObject = method.Invoke(dataValue, null); } } else { attributeObject = property.GetValue(dataValue); } if (attributeObject == null) { if (cAttribute.Existence.Lower > 0) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmExpectedConstraintMissing, cAttribute.RmAttributeName)); } } else if (cAttribute.Existence.Upper == 0) { result = false; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmForbiddenConstraint, cAttribute.RmAttributeName)); } else if (!cAttribute.ValidValue(attributeObject)) { result = false; } else { DvCodedText codedText = dataValue as DvCodedText; if (codedText != null && cAttribute.RmAttributeName == "defining_code") { // validate the code string before validating the coded value if (codedText.DefiningCode.TerminologyId.Value == "local") { CObject parentObject = cAttribute.parent; CArchetypeRoot cArchetypeRoot = ValidationUtility.GetCArchetypeRoot(parentObject); if (!cArchetypeRoot.TermDefinitions.HasKey(codedText.DefiningCode.CodeString)) { result = false; string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString; ValidationContext.AcceptValidationError(this, string.Format("code {0} is not existing archetype term", code)); } } if (result && !ValidationUtility.ValidValueTermDef(codedText, cAttribute, ValidationContext.TerminologyService)) { result = false; string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString; ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TextValueXInvalidForCodeY, codedText.Value, code)); } } } } } } return(result); }
/// <summary> /// Updates object from command-line arguments where /// <paramref name="properties" /> describes the target object. /// </summary> public static string[] ParseTo(IEnumerable<string> args, object target, PropertyDescriptorCollection properties) { if (target == null) throw new ArgumentNullException("target"); if (args == null) throw new ArgumentNullException("args"); var tails = new List<string>(); var e = args.GetEnumerator(); while (e.MoveNext()) { var arg = e.Current; if (arg.Length == 0) // empty arg? { tails.Add(arg); continue; } // Get argument name, Unix or DOS style. string name; if (arg[0] == '/') // DOS style { name = arg.Substring(1); } else if (arg.Length > 1 && arg[0] == '-' && arg[1] == '-') // Unix style { if (arg.Length == 2) // comment break; name = arg.Substring(2); } else { tails.Add(arg); // anonymous argument continue; } // Is the argument name and value paired in one? // Allows `arg=value` or `arg:value` style. var paired = name.IndexOfAny(_argSeparators) > 0; var pair = name.Split(_argSeparators, (n, v) => new { Name = n, Value = v }); if (paired) name = pair.Name; // Break the name out of the pair // Get setting property from name. var propertyName = name.Replace("-", " ") .ToTitleCaseInvariant() .Replace(" ", string.Empty); if (properties == null) properties = TypeDescriptor.GetProperties(target); var property = properties.Find(propertyName, true); if (property == null) throw new FormatException(string.Format("Unknown command-line argument: " + name)); // Process argument based on property type. var type = property.PropertyType; object value; if (type == typeof(bool)) // Boolean? { value = true; // flag-style } else { // If value was paired with name then break out the value // from the pair other read it from the next argument. if (paired) { value = pair.Value; } else { if (!e.MoveNext()) throw new FormatException("Missing value for command-line argument: " + name); value = e.Current; } // If property is of another type than string and it // support conversion then do that now. if (type != typeof(string)) { var converter = property.Converter ?? TypeDescriptor.GetConverter(type); if (!converter.CanConvertFrom(typeof(string))) throw new FormatException("Unsupported command-line argument:" + name); value = converter.ConvertFromString(value.ToString()); } } property.SetValue(target, value); } return tails.ToArray(); }
public ServerObjectParsingObject(Type type, Hashtable attributes, string tagid, ParsingObject parent) : base (tagid, parent) { //create the object if (type.GetInterface ("System.ComponentModel.IComponent") != null) //note: this automatically adds to parent's container, as some controls //need to be sited e.g. if they use site dictionaries //TODO: should this action be passed up the tree so controls can intercept? obj = ((AspNetEdit.Editor.ComponentModel.DesignerHost) base.DesignerHost).CreateComponent (type, attributes["ID"] as string, false); else obj = Activator.CreateInstance (type); //and populate it from the attributes pdc = TypeDescriptor.GetProperties (obj); foreach (DictionaryEntry de in attributes) { if (0 == string.Compare((string)de.Key, "runat")) continue; if (0 == string.Compare((string)de.Key, "ID")) continue; //use the dash subproperty syntax string[] str = ((string)de.Key).Split ('-'); PropertyDescriptor pd = pdc.Find (str[0], true); //if property not found, try events if (str.Length == 1 && pd == null && CultureInfo.InvariantCulture.CompareInfo.IsPrefix (str[0].ToLower(), "on")) { IEventBindingService iebs = (IEventBindingService) DesignerHost.GetService (typeof (IEventBindingService)); if (iebs == null) throw new Exception ("Could not obtain IEventBindingService from host"); EventDescriptorCollection edc = TypeDescriptor.GetEvents (obj); EventDescriptor e = edc.Find (str[0].Remove(0,2), true); if (e != null) pd = iebs.GetEventProperty(e); else throw new Exception ("Could not find event " + str[0].Remove(0,2)); } object loopObj = obj; for (int i = 0; i < str.Length; i++ ) { if (pd == null) throw new Exception ("Could not find property " + (string)de.Key); if (i == str.Length - 1) { pd.SetValue (obj, pd.Converter.ConvertFromString ((string) de.Value)); break; } loopObj = pd.GetValue (loopObj); pd = TypeDescriptor.GetProperties (loopObj).Find (str[0], true); } } parseAtt = TypeDescriptor.GetAttributes (obj)[typeof(ParseChildrenAttribute )] as ParseChildrenAttribute; //FIXME: fix this in MCS classlib if (parseAtt.DefaultProperty.Length == 0) parseAtt = null; //work out how we're trying to parse the children if (parseAtt != null) { if (parseAtt.DefaultProperty != null) { PropertyDescriptor pd = pdc[parseAtt.DefaultProperty]; if (pd == null) throw new Exception ("Default property does not exist"); if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList))) mode = ParseChildrenMode.DefaultCollectionProperty; else mode = ParseChildrenMode.DefaultProperty; } else if (parseAtt.ChildrenAsProperties) mode = ParseChildrenMode.Properties; else mode = ParseChildrenMode.Controls; } else { //FIXME: these are actually persistence hints, but ParseChildrenAttribute doesn't always exist. //FIXME: logic would be dodgy with bad input parseAtt = ParseChildrenAttribute.Default; mode = ParseChildrenMode.Controls; foreach (PropertyDescriptor pd in pdc) { PersistenceModeAttribute modeAttrib = pd.Attributes[typeof(PersistenceModeAttribute)] as PersistenceModeAttribute; if (modeAttrib == null) return; switch (modeAttrib.Mode) { case PersistenceMode.Attribute: continue; case PersistenceMode.EncodedInnerDefaultProperty: parseAtt.DefaultProperty = pd.Name; mode = ParseChildrenMode.DefaultEncodedProperty; break; case PersistenceMode.InnerDefaultProperty: parseAtt.DefaultProperty = pd.Name; if (pd.PropertyType.GetInterface("System.Collections.IList") == (typeof(IList))) mode = ParseChildrenMode.DefaultCollectionProperty; else mode = ParseChildrenMode.DefaultProperty; break; case PersistenceMode.InnerProperty: mode = ParseChildrenMode.Properties; break; } } } }
/// <summary> /// This is a callback function for DynamicTypeDescriptionProvider. /// You can modify the collection in this method. /// Things you can do in this method: /// Hide a property /// Show a property /// Add/Remove attributes of a property /// Create a new property on the fly /// /// More info: http://www.codeproject.com/KB/grid/PropertyGridDynamicProp.aspx /// </summary> /// <param name="pdc"></param> public void ModifyDynamicProperties(PropertyDescriptorCollection pdc) { PropertyDescriptor pd = pdc.Find("SourcePath", false); pdc.Remove(pd); switch (DecodingMode) { case JobDecodingMode.SingleDecoding: pdc.Add(TypeDescriptor.CreateProperty( this.GetType(), pd, new EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(UITypeEditor)) )); break; case JobDecodingMode.BatchDecoding: pdc.Add(TypeDescriptor.CreateProperty( this.GetType(), pd, new EditorAttribute(typeof(FolderEditor), typeof(UITypeEditor)) )); break; } pd = pdc.Find("FilterText", false); pdc.Remove(pd); pdc.Add(TypeDescriptor.CreateProperty(this.GetType(), pd, new ReadOnlyAttribute(!IsFilterActive))); pd = pdc.Find("FormatterSettings", false); pdc.Remove(pd); pdc.Add(TypeDescriptor.CreateProperty(this.GetType(), pd, new ReadOnlyAttribute(!IsFormatterActive))); }
private static object GetPropertyDescriptorValue(object value, string name, PropertyDescriptorCollection props) { PropertyDescriptor propertyDescriptor = props.Find(name, ignoreCase: true); Debug.Assert(propertyDescriptor != null, "Property descriptor shouldn't be null"); return propertyDescriptor.GetValue(value); }
private void Child_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (RaiseListChangedEvents) { if (sender == null || e == null || string.IsNullOrEmpty(e.PropertyName)) { // Fire reset event (per INotifyPropertyChanged spec) ResetBindings(); } else { // The change event is broken should someone pass an item to us that is not // of type T. Still, if they do so, detect it and ignore. It is an incorrect // and rare enough occurrence that we do not want to slow the mainline path // with "is" checks. T item; try { item = (T)sender; } catch (InvalidCastException) { ResetBindings(); return; } // Find the position of the item. This should never be -1. If it is, // somehow the item has been removed from our list without our knowledge. int pos = _lastChangeIndex; if (pos < 0 || pos >= Count || !this[pos].Equals(item)) { pos = IndexOf(item); _lastChangeIndex = pos; } if (pos == -1) { Debug.Fail("Item is no longer in our list but we are still getting change notifications."); UnhookPropertyChanged(item); ResetBindings(); } else { // Get the property descriptor if (null == _itemTypeProperties) { // Get Shape _itemTypeProperties = TypeDescriptor.GetProperties(typeof(T)); Debug.Assert(_itemTypeProperties != null); } PropertyDescriptor pd = _itemTypeProperties.Find(e.PropertyName, true); // Create event args. If there was no matching property descriptor, // we raise the list changed anyway. ListChangedEventArgs args = new ListChangedEventArgs(ListChangedType.ItemChanged, pos, pd); // Fire the ItemChanged event OnListChanged(args); } } } }
public ImageIndexConverterTest () { button = new ToolBarButton (); pdc = TypeDescriptor.GetProperties (button); ic = (ImageIndexConverter) pdc.Find ("ImageIndex", true).Converter; }
/// <summary> /// Does the property filtering... /// </summary> /// <param name="pdc">The PDC.</param> /// <returns></returns> private PropertyDescriptorCollection FilterProperties(PropertyDescriptorCollection pdc) { ArrayList validOptions = new ArrayList(); PropertyDescriptor pd = pdc.Find("fileAction", true); if (pd != null) { object val = pd.GetValue(this); if (val != null) { if ((SFTPFileAction)val == SFTPFileAction.Send) foreach (string s in validSend) validOptions.Add(s); else if ((SFTPFileAction)val == SFTPFileAction.Receive) foreach (string s in validReceive) validOptions.Add(s); else if ((SFTPFileAction)val == SFTPFileAction.List) foreach (string s in validList) validOptions.Add(s); else if ((SFTPFileAction)val == SFTPFileAction.SendMultiple) foreach (string s in validSendMultiple) validOptions.Add(s); else if ((SFTPFileAction)val == SFTPFileAction.ReceiveMultiple) foreach (string s in validReceiveMultiple) validOptions.Add(s); } } PropertyDescriptorCollection adjustedProps = new PropertyDescriptorCollection(new PropertyDescriptor[] { }); foreach (PropertyDescriptor p in pdc) if (validOptions.Contains(p.Name)) adjustedProps.Add(p); return adjustedProps; }
private string GetDocumentIdByReflection(object doc, out PropertyDescriptorCollection properties) { Type type = doc.GetType(); properties = propertyDescriptorCache.GetOrAdd(type, TypeDescriptor.GetProperties); return properties.Find(Constants.DocumentIdFieldName, false).GetValue(doc) as string; }
private void ModifyProperties(PropertyDescriptorCollection col) { if (!ShowB) { col.Remove(col.Find("InputB", true)); } if (!ShowA) { col.Remove(col.Find("InputA", true)); } }
public void Find () { PropertyDescriptor descA = new MockPropertyDescriptor ("hehe_\u0061\u030a", 2); PropertyDescriptor descB = new MockPropertyDescriptor ("heh_\u00e5", 3); PropertyDescriptor descC = new MockPropertyDescriptor ("Foo", 5); PropertyDescriptor descD = new MockPropertyDescriptor ("FOo", 6); PropertyDescriptor descE = new MockPropertyDescriptor ("Aim", 1); PropertyDescriptor descF = new MockPropertyDescriptor ("Bar", 4); PropertyDescriptorCollection col = new PropertyDescriptorCollection ( new PropertyDescriptor [] { descA, descB, descC, descD, descE, descF }); Assert.IsNull (col.Find ("heh_\u0061\u030a", false), "#1"); Assert.IsNull (col.Find ("hehe_\u00e5", false), "#2"); Assert.AreSame (descA, col.Find ("hehe_\u0061\u030a", false), "#3"); Assert.AreSame (descB, col.Find ("heh_\u00e5", false), "#4"); Assert.IsNull (col.Find ("foo", false), "#5"); Assert.AreSame (descC, col.Find ("foo", true), "#6"); Assert.AreSame (descD, col.Find ("FOo", false), "#7"); Assert.AreSame (descC, col.Find ("FOo", true), "#8"); Assert.IsNull (col.Find ("fOo", false), "#9"); Assert.AreSame (descC, col.Find ("fOo", true), "#10"); Assert.IsNull (col.Find ("AIm", false), "#11"); Assert.AreSame (descE, col.Find ("AIm", true), "#12"); Assert.IsNull (col.Find ("AiM", false), "#13"); Assert.AreSame (descE, col.Find ("AiM", true), "#14"); Assert.AreSame (descE, col.Find ("Aim", false), "#15"); Assert.AreSame (descE, col.Find ("Aim", true), "#16"); }
private object GetFieldValue(PropertyDescriptorCollection props, object item, ModelField field) { if (field != null && field.ServerMapping.IsNotEmpty()) { string[] mapping = field.ServerMapping.Split('.'); if (mapping.Length > 1) { for (int i = 0; i < mapping.Length; i++) { PropertyInfo p = item.GetType().GetProperty(mapping[i]); item = p.GetValue(item, null); if (item == null) { return null; } } return item; } } var fieldName = string.IsNullOrEmpty(field.Mapping) ? field.Name : field.Mapping; var desc = props.Find(fieldName, true); return desc != null ? desc.GetValue(item) : null; }
public static PropertyDescriptor GetValidProperty(PropertyDescriptorCollection properties, string propertyName) { Guard.ArgumentNotNull(properties, "properties"); PropertyDescriptor property = properties.Find(propertyName, false); Guard.PropertyNotNull(property, propertyName); return property; }