Ejemplo n.º 1
0
        public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
        {
            DependencyProperty property = new DependencyProperty(name, propertyType, ownerType, defaultMetadata);

            if (ownerType.GetField(name + "Event", BindingFlags.Public | BindingFlags.Static) != null)
            {
                property.IsEventSet = true;
            }

            if (properties.ContainsKey(property.GetHashCode()))
            {
                throw new InvalidOperationException("A property with the same name already exists");
            }

            properties.Add(property.GetHashCode(), property);
            return(property);
        }
        private static DependencyProperty ValidateAndRegister(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata, System.Type validatorType, bool isRegistered)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            if (name.Length == 0)
                throw new ArgumentException(SR.GetString(SR.Error_EmptyArgument), "name");

            if (propertyType == null)
                throw new ArgumentNullException("propertyType");

            if (ownerType == null)
                throw new ArgumentNullException("ownerType");

            FieldInfo fieldInfo = null;
            bool isEvent = (typeof(System.Delegate).IsAssignableFrom(propertyType) && (defaultMetadata == null || (defaultMetadata.Options & DependencyPropertyOptions.DelegateProperty) == 0));

            // WinOE Bug 13807: events can not be meta properties.
            if (isEvent && defaultMetadata != null && defaultMetadata.IsMetaProperty)
                throw new ArgumentException(SR.GetString(SR.Error_DPAddHandlerMetaProperty), "defaultMetadata");

            //Field must exists
            if (isEvent)
                fieldInfo = ownerType.GetField(name + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.GetProperty);
            else
                fieldInfo = ownerType.GetField(name + "Property", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.GetProperty);

            if (fieldInfo == null)
            {
                string error = SR.GetString((isEvent) ? SR.Error_DynamicEventNotSupported : SR.Error_DynamicPropertyNotSupported, new object[] { ownerType.FullName, name });
                throw new ArgumentException(error, "ownerType");
            }


            PropertyMetadata metadata = null;
            object defaultValue = null;

            // Establish default metadata for all types, if none is provided
            if (defaultMetadata == null)
            {
                defaultValue = GetDefaultValue(name, propertyType, ownerType);
                metadata = new PropertyMetadata(defaultValue);
            }
            else
            {
                metadata = defaultMetadata;
                if (metadata.DefaultValue == null)
                    metadata.DefaultValue = GetDefaultValue(name, propertyType, ownerType);
            }

            DependencyProperty dependencyProperty = new DependencyProperty(name, propertyType, ownerType, metadata, validatorType, isRegistered);
            lock (((ICollection)DependencyProperty.dependencyProperties).SyncRoot)
            {
                if (DependencyProperty.dependencyProperties.ContainsKey(dependencyProperty.GetHashCode()))
                    throw new InvalidOperationException(SR.GetString(SR.Error_DPAlreadyExist, new object[] { name, ownerType.FullName }));

                DependencyProperty.dependencyProperties.Add(dependencyProperty.GetHashCode(), dependencyProperty);
            }

            return dependencyProperty;
        }
Ejemplo n.º 3
0
        private static DependencyProperty ValidateAndRegister(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType, bool isRegistered)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(SR.GetString("Error_EmptyArgument"), "name");
            }
            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }
            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }
            FieldInfo field = null;
            bool      flag  = typeof(Delegate).IsAssignableFrom(propertyType) && ((defaultMetadata == null) || (((byte)(defaultMetadata.Options & DependencyPropertyOptions.DelegateProperty)) == 0));

            if ((flag && (defaultMetadata != null)) && defaultMetadata.IsMetaProperty)
            {
                throw new ArgumentException(SR.GetString("Error_DPAddHandlerMetaProperty"), "defaultMetadata");
            }
            if (flag)
            {
                field = ownerType.GetField(name + "Event", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
            }
            else
            {
                field = ownerType.GetField(name + "Property", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
            }
            if (field == null)
            {
                throw new ArgumentException(SR.GetString(flag ? "Error_DynamicEventNotSupported" : "Error_DynamicPropertyNotSupported", new object[] { ownerType.FullName, name }), "ownerType");
            }
            PropertyMetadata metadata = null;

            if (defaultMetadata == null)
            {
                metadata = new PropertyMetadata(GetDefaultValue(name, propertyType, ownerType));
            }
            else
            {
                metadata = defaultMetadata;
                if (metadata.DefaultValue == null)
                {
                    metadata.DefaultValue = GetDefaultValue(name, propertyType, ownerType);
                }
            }
            DependencyProperty property = new DependencyProperty(name, propertyType, ownerType, metadata, validatorType, isRegistered);

            lock (((ICollection)dependencyProperties).SyncRoot)
            {
                if (dependencyProperties.ContainsKey(property.GetHashCode()))
                {
                    throw new InvalidOperationException(SR.GetString("Error_DPAlreadyExist", new object[] { name, ownerType.FullName }));
                }
                dependencyProperties.Add(property.GetHashCode(), property);
            }
            return(property);
        }
 private static DependencyProperty ValidateAndRegister(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType, bool isRegistered)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(SR.GetString("Error_EmptyArgument"), "name");
     }
     if (propertyType == null)
     {
         throw new ArgumentNullException("propertyType");
     }
     if (ownerType == null)
     {
         throw new ArgumentNullException("ownerType");
     }
     FieldInfo field = null;
     bool flag = typeof(Delegate).IsAssignableFrom(propertyType) && ((defaultMetadata == null) || (((byte) (defaultMetadata.Options & DependencyPropertyOptions.DelegateProperty)) == 0));
     if ((flag && (defaultMetadata != null)) && defaultMetadata.IsMetaProperty)
     {
         throw new ArgumentException(SR.GetString("Error_DPAddHandlerMetaProperty"), "defaultMetadata");
     }
     if (flag)
     {
         field = ownerType.GetField(name + "Event", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
     }
     else
     {
         field = ownerType.GetField(name + "Property", BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
     }
     if (field == null)
     {
         throw new ArgumentException(SR.GetString(flag ? "Error_DynamicEventNotSupported" : "Error_DynamicPropertyNotSupported", new object[] { ownerType.FullName, name }), "ownerType");
     }
     PropertyMetadata metadata = null;
     if (defaultMetadata == null)
     {
         metadata = new PropertyMetadata(GetDefaultValue(name, propertyType, ownerType));
     }
     else
     {
         metadata = defaultMetadata;
         if (metadata.DefaultValue == null)
         {
             metadata.DefaultValue = GetDefaultValue(name, propertyType, ownerType);
         }
     }
     DependencyProperty property = new DependencyProperty(name, propertyType, ownerType, metadata, validatorType, isRegistered);
     lock (((ICollection) dependencyProperties).SyncRoot)
     {
         if (dependencyProperties.ContainsKey(property.GetHashCode()))
         {
             throw new InvalidOperationException(SR.GetString("Error_DPAlreadyExist", new object[] { name, ownerType.FullName }));
         }
         dependencyProperties.Add(property.GetHashCode(), property);
     }
     return property;
 }
Ejemplo n.º 5
0
        private static DependencyProperty ValidateAndRegister(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata, System.Type validatorType, bool isRegistered)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (name.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Error_EmptyArgument), "name");
            }

            if (propertyType == null)
            {
                throw new ArgumentNullException("propertyType");
            }

            if (ownerType == null)
            {
                throw new ArgumentNullException("ownerType");
            }

            FieldInfo fieldInfo = null;
            bool      isEvent   = (typeof(System.Delegate).IsAssignableFrom(propertyType) && (defaultMetadata == null || (defaultMetadata.Options & DependencyPropertyOptions.DelegateProperty) == 0));

            // WinOE Bug 13807: events can not be meta properties.
            if (isEvent && defaultMetadata != null && defaultMetadata.IsMetaProperty)
            {
                throw new ArgumentException(SR.GetString(SR.Error_DPAddHandlerMetaProperty), "defaultMetadata");
            }

            //Field must exists
            if (isEvent)
            {
                fieldInfo = ownerType.GetField(name + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.GetProperty);
            }
            else
            {
                fieldInfo = ownerType.GetField(name + "Property", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.GetProperty);
            }

            if (fieldInfo == null)
            {
                string error = SR.GetString((isEvent) ? SR.Error_DynamicEventNotSupported : SR.Error_DynamicPropertyNotSupported, new object[] { ownerType.FullName, name });
                throw new ArgumentException(error, "ownerType");
            }


            PropertyMetadata metadata     = null;
            object           defaultValue = null;

            // Establish default metadata for all types, if none is provided
            if (defaultMetadata == null)
            {
                defaultValue = GetDefaultValue(name, propertyType, ownerType);
                metadata     = new PropertyMetadata(defaultValue);
            }
            else
            {
                metadata = defaultMetadata;
                if (metadata.DefaultValue == null)
                {
                    metadata.DefaultValue = GetDefaultValue(name, propertyType, ownerType);
                }
            }

            DependencyProperty dependencyProperty = new DependencyProperty(name, propertyType, ownerType, metadata, validatorType, isRegistered);

            lock (((ICollection)DependencyProperty.dependencyProperties).SyncRoot)
            {
                if (DependencyProperty.dependencyProperties.ContainsKey(dependencyProperty.GetHashCode()))
                {
                    throw new InvalidOperationException(SR.GetString(SR.Error_DPAlreadyExist, new object[] { name, ownerType.FullName }));
                }

                DependencyProperty.dependencyProperties.Add(dependencyProperty.GetHashCode(), dependencyProperty);
            }

            return(dependencyProperty);
        }
Ejemplo n.º 6
0
		public static DependencyProperty Register (string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
		{
			DependencyProperty property = new DependencyProperty (name, propertyType, ownerType, defaultMetadata);

			if (ownerType.GetField (name + "Event", BindingFlags.Public | BindingFlags.Static) != null) {
				property.IsEventSet = true;
			}

			if (properties.ContainsKey (property.GetHashCode ())) {
				throw new InvalidOperationException ("A property with the same name already exists");
			}

			properties.Add (property.GetHashCode (), property);
			return property;
		}