Ejemplo n.º 1
0
        /// <summary> Extract a component property value. </summary>
        /// <param name="type">The component property types. </param>
        /// <param name="component">The component instance itself. </param>
        /// <param name="propertyPath">The property path for the property to be extracted. </param>
        /// <returns> The property value extracted. </returns>
        protected virtual object GetComponentValue(ComponentType type, object component, string propertyPath)
        {
            int    loc = propertyPath.IndexOf('.');
            string basePropertyName = loc > 0 ? propertyPath.Substring(0, (loc) - (0)) : propertyPath;

            string[] propertyNames = type.PropertyNames;
            int      index         = 0;

            for (; index < propertyNames.Length; index++)
            {
                if (basePropertyName.Equals(propertyNames[index]))
                {
                    break;
                }
            }
            if (index == propertyNames.Length)
            {
                throw new MappingException("component property not found: " + basePropertyName);
            }

            object baseValue = type.GetPropertyValue(component, index);

            if (loc > 0)
            {
                ComponentType subtype = (ComponentType)type.Subtypes[index];
                return(GetComponentValue(subtype, baseValue, propertyPath.Substring(loc + 1)));
            }
            else
            {
                return(baseValue);
            }
        }