Ejemplo n.º 1
0
        static PropertyDescriptorCollection GetDynamicPropertyDescriptors(DynamicExtensionContainer Container)
        {
            var Result = new List <PropertyDescriptor>();

            var OriginalProperties = TypeDescriptor.GetProperties(Container, true);

            Result.AddRange(OriginalProperties.Cast <PropertyDescriptor>());

            var AllProperties = Container.dynamicExtensions.SelectMany(x => x.MemberNames).Distinct();

            foreach (var PropName in AllProperties)
            {
                var Ex       = Container.getDynamicExtension(PropName);
                var PropDesc = new TypedProperty(Container.GetType(), PropName, Ex, Container.raisePropertyChanged);
                Result.Add(PropDesc);
            }
            return(new PropertyDescriptorCollection(Result.ToArray()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if a the dynamic extension succesfully solved and setted a property, else, returns falase
        /// </summary>
        /// <param name="PropertyName">The property to set</param>
        /// <param name="value">The value to set</param>
        /// <returns>True if success</returns>
        protected bool TrySetProperty(string PropertyName, object value)
        {
            var D = getDynamicExtension(PropertyName);

            //If there isn't any dynamic extension that matches that property, return false
            if (D == null)
            {
                return(false);
            }
            var CanWrite = D.CanWrite(PropertyName);

            //If the property can't be written, return false
            if (!CanWrite)
            {
                return(false);
            }

            TypedProperty.SetValue(D.GetPropertyType(PropertyName), PropertyName, value, this, raisePropertyChanged, D.CanRead(PropertyName), () => D.Get(PropertyName), () => D.Set(PropertyName, value));
            return(true);
        }