Beispiel #1
0
        private static object GetAttachedObject(string propertyName, object attachedTo)
        {
            // This function assumes that the propertyName is not a path (no '.' in it)

            int    index = propertyName.IndexOf('[');
            string nonIndexedProperty = (index < 0) ? propertyName : propertyName.Substring(0, index);

            TrustedType         trustedType = PT.Trust(attachedTo.GetType());
            TrustedPropertyInfo property    = trustedType.GetProperty(nonIndexedProperty);
            object returnValue = property.GetValue(attachedTo, null);

            if (index < 0)
            {
                // This isn't a collection, just return what we got.
                return(returnValue);
            }
            else
            {
                // This is a collection. Parse the index string and return the value at that index.
                int    indexLength = propertyName.Length - nonIndexedProperty.Length - 2;
                string s           = propertyName.Substring(index + 1, indexLength).Trim();
                int    i           = StringConverter.ToInt(s);

                // Visual3DCollection does not implement IList like the other collections do :(
                if (returnValue is Visual3DCollection)
                {
                    return(((Visual3DCollection)returnValue)[i]);
                }
                else
                {
                    return(((IList)returnValue)[i]);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the object that owns the property specified.
        /// </summary>
        /// <param name="complexPropertyPath">A "dot-down" path to a property</param>
        /// <param name="attachedTo">The object to start the search from</param>
        /// <returns>The object that owns the property specified</returns>
        /// <exception cref="ArgumentException">Thrown when the path does not lead to a valid object</exception>
        public static object GetPropertyOwner(string complexPropertyPath, object attachedTo)
        {
            // complexProperty will come in like this:
            //
            //  path == Thickness                   attachedTo == ScreenSpaceLines3D    return: ScreenSpaceLines3D
            //  path == Material[0].Brush.Color     attachedTo == GeometryModel3D       return: Brush
            //  path == Brush.Color                 attachedTo == Material              return: Brush
            //  path == Color                       attachedTo == Brush                 return: Brush
            //  path == Children[0]                 attachedTo == Viewport3D            return: Visual3DCollection

            int dotIndex = complexPropertyPath.IndexOf('.');

            if (dotIndex < 0)
            {
                int bracketIndex = complexPropertyPath.IndexOf('[');
                if (bracketIndex < 0)
                {
                    // The property should be on the object we're looking at right now.
                    // Throw an exception if the property does not exist on this object.
                    TrustedType         trustedType = PT.Trust(attachedTo.GetType());
                    TrustedPropertyInfo property    = trustedType.GetProperty(complexPropertyPath);
                    if (property == null)
                    {
                        throw new ArgumentException(complexPropertyPath + " does not exist on " + trustedType.Name);
                    }

                    return(attachedTo);
                }
                else
                {
                    // Trim the index from the property (the collection is the owner)
                    string nonIndexedProperty = complexPropertyPath.Substring(0, bracketIndex);
                    return(GetAttachedObject(nonIndexedProperty, attachedTo));
                }
            }

            // The property is not on the current object

            string localPropertyName   = complexPropertyPath.Substring(0, dotIndex);
            string remainingProperties = complexPropertyPath.Substring(dotIndex + 1);

            object next = GetAttachedObject(localPropertyName, attachedTo);

            return(GetPropertyOwner(remainingProperties, next));
        }
Beispiel #3
0
        private static bool IsPropertyProblematic(TrustedPropertyInfo property)
        {
            // These properties cause exceptions, infinite loops, or are useless info
            switch (property.Name)
            {
            case "Empty":
            case "Resources":
            case "SyncRoot":
            case "CultureInfo":
            case "TargetType":
            case "RenderedGeometry":
            case "Parent":
            case "Metadata":
            case "Inverse":
            case "BackBuffer":
                return(true);

            default:
                return(false);
            }
        }
Beispiel #4
0
 public PropertyGenerator(TrustedPropertyInfo property)
     : base(null)
 {
     get = property.GetGetMethod();
     set = property.GetSetMethod();
 }