private DependencyProperty (string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata) { this.name = name; property_type = propertyType; owner_type = ownerType; def_metadata = defaultMetadata; }
public void Constructor3 () { Attribute[] attributes = new Attribute [2]; attributes[0] = new ObsoleteAttribute (); attributes[1] = new ObsoleteAttribute (); PropertyMetadata pm = new PropertyMetadata (attributes); Assert.AreEqual (2, pm.GetAttributes().Length, "C3#1"); }
public void Constructor4 () { Attribute[] attributes = new Attribute [2]; attributes[0] = new ObsoleteAttribute (); attributes[1] = new ObsoleteAttribute (); PropertyMetadata pm = new PropertyMetadata (val, attributes); Assert.AreEqual (2, pm.GetAttributes().Length, "C4#1"); Assert.AreEqual (val, pm.DefaultValue, "C4#2"); }
public void Constructor1 () { PropertyMetadata pm = new PropertyMetadata (); Assert.AreEqual (null, pm.DefaultValue, "C1#1"); Assert.AreEqual (null, pm.GetValueOverride, "C1#2"); Assert.AreEqual (null, pm.SetValueOverride, "C1#3"); Assert.AreEqual (DependencyPropertyOptions.Default, pm.Options, "C1#4"); }
private DependencyProperty(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType, bool isRegistered) { this.name = name; this.propertyType = propertyType; this.ownerType = ownerType; this.validatorType = validatorType; this.isRegistered = isRegistered; this.defaultMetadata = defaultMetadata; this.defaultMetadata.Seal(this, propertyType); this.isEvent = typeof(Delegate).IsAssignableFrom(this.propertyType) && ((this.defaultMetadata == null) || (((byte) (this.defaultMetadata.Options & DependencyPropertyOptions.DelegateProperty)) == 0)); }
//TBD: Dharma - Get rid of this overload public static DependencyProperty RegisterAttached(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata, System.Type validatorType) { if (validatorType == null) throw new ArgumentNullException("validatorType"); else if (!typeof(Validator).IsAssignableFrom(validatorType)) throw new ArgumentException(SR.GetString(SR.Error_ValidatorTypeIsInvalid), "validatorType"); return ValidateAndRegister(name, propertyType, ownerType, defaultMetadata, validatorType, false); }
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; }
public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata) { return ValidateAndRegister(name, propertyType, ownerType, defaultMetadata, null, true); }
public static DependencyProperty RegisterAttached (string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType) { DependencyProperty property = Register (name, propertyType, ownerType, defaultMetadata); property.attached = true; property.validator_type = validatorType; return property; }
public void Attributes () { Attribute[] attributes = new Attribute [3]; Attribute[] attributes2; attributes[0] = new ObsoleteAttribute (); attributes[1] = new ObsoleteAttribute (); attributes[2] = new NonSerializedAttribute (); PropertyMetadata pm = new PropertyMetadata (attributes); attributes2 = pm.GetAttributes (); Assert.AreEqual (3, attributes2.Length, "C9#1"); Assert.AreEqual (attributes[0], attributes2[0], "C9#2"); Assert.AreEqual (attributes[1], attributes2[1], "C9#3"); Assert.AreEqual (attributes[2], attributes2[2], "C9#4"); attributes2 = pm.GetAttributes (typeof (NonSerializedAttribute)); Assert.AreEqual (1, attributes2.Length, "C9#5"); Assert.AreEqual (attributes[2], attributes2[0], "C9#6"); attributes2 = pm.GetAttributes (typeof (ObsoleteAttribute)); Assert.AreEqual (2, attributes2.Length, "C9#7"); Assert.AreEqual (attributes[0], attributes2[0], "C9#8"); Assert.AreEqual (attributes[1], attributes2[1], "C9#9"); attributes2 = pm.GetAttributes (typeof (ParamArrayAttribute)); Assert.AreEqual (0, attributes2.Length, "C9#10"); }
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; }
public void Constructor7 () { Attribute[] attributes = new Attribute [2]; attributes[0] = new ObsoleteAttribute (); attributes[1] = new ObsoleteAttribute (); PropertyMetadata pm = new PropertyMetadata (val, DependencyPropertyOptions.Readonly, attributes); Assert.AreEqual (DependencyPropertyOptions.Readonly, pm.Options, "C7#1"); Assert.AreEqual (2, pm.GetAttributes().Length, "C7#2"); Assert.AreEqual (val, pm.DefaultValue, "C7#3"); }
public void Constructor5 () { PropertyMetadata pm = new PropertyMetadata (val, DependencyPropertyOptions.Readonly); Assert.AreEqual (DependencyPropertyOptions.Readonly, pm.Options, "C5#1"); Assert.AreEqual (val, pm.DefaultValue, "C5#2"); }
public void Constructor2 () { PropertyMetadata pm = new PropertyMetadata (DependencyPropertyOptions.Readonly); Assert.AreEqual (DependencyPropertyOptions.Readonly, pm.Options, "C2#1"); }
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; }
public static DependencyProperty RegisterAttached (string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata) { return RegisterAttached (name, propertyType, ownerType, defaultMetadata, null); }
public static DependencyProperty RegisterAttached(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata defaultMetadata) { return ValidateAndRegister(name, propertyType, ownerType, defaultMetadata, null, false); }
public void Accessors () { PropertyMetadata pm = new PropertyMetadata (); pm.Options = DependencyPropertyOptions.Readonly | DependencyPropertyOptions.NonSerialized; pm.DefaultValue = val; Assert.AreEqual (val, pm.DefaultValue, "C8#1"); Assert.AreEqual (true, pm.IsNonSerialized, "C8#2"); Assert.AreEqual (false, pm.IsMetaProperty, "C8#3"); Assert.AreEqual (true, pm.IsReadOnly, "C8#4"); pm.Options = DependencyPropertyOptions.Metadata; Assert.AreEqual (true, pm.IsMetaProperty, "C8#5"); Assert.AreEqual (false, pm.IsNonSerialized, "C8#6"); Assert.AreEqual (false, pm.IsReadOnly, "C8#7"); }