Example #1
0
        public override bool Equals(object obj)
        {
            PropertyPathElement other = obj as PropertyPathElement;

            return(Object.ReferenceEquals(this, other) || !Object.ReferenceEquals(other, null) &&
                   this.PropertyName == other.PropertyName);
        }
Example #2
0
        public bool TryGetValue(object target, out object value)
        {
            Type   containingType = PropertyName.ResolveContainingType(target.GetType());
            string propertyName   = PropertyName.MemberName;

            bool isDefaultIndexProperty = propertyName.IsNullOrEmpty();

            object indexPropertyValue;

            // an index property that has a name (such as "Values[0]"), might be a regular property with the same name ("Values"), and a default index property ("[0]" or "Item[0]")
            if (!isDefaultIndexProperty && PropertyPathElement.TryGetValue(target, PropertyName, out indexPropertyValue))
            {
                if (indexPropertyValue == null)
                {
                    value = null;
                    return(false);
                }

                target                 = indexPropertyValue;
                containingType         = indexPropertyValue.GetType();
                isDefaultIndexProperty = true;
            }

            PropertyInfo indexPropertyInfo = isDefaultIndexProperty ? containingType.GetDefaultIndexProperty() : containingType.GetInstanceProperty(propertyName);

            if (indexPropertyInfo == null)
            {
                value = null;
                return(false);
            }

            value = indexPropertyInfo.GetValue(target, ParseIndexValues(indexPropertyInfo).ToArray());
            return(true);
        }