internal static DependencyProperty FromName(string name, Type ownerType) { DependencyProperty dependencyProperty = null; if (name == null) { throw new ArgumentNullException("name"); } if (!(ownerType != null)) { throw new ArgumentNullException("ownerType"); } FromNameKey fromNameKey = new FromNameKey(name, ownerType); while (dependencyProperty == null && ownerType != null) { SecurityHelper.RunClassConstructor(ownerType); fromNameKey.UpdateNameKey(ownerType); lock (Synchronized) { dependencyProperty = (DependencyProperty)PropertyFromName[fromNameKey]; } ownerType = ownerType.BaseType; } return(dependencyProperty); }
/// <summary> /// Associate another owner type with this property /// </summary> /// <remarks> /// The owner type is used when resolving a property by name (<see cref="FromName"/>) /// </remarks> /// <param name="ownerType">Additional owner type</param> /// <param name="typeMetadata">Optional type metadata to override on owner's behalf</param> /// <returns>This property</returns> public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata) { if (ownerType == null) { throw new ArgumentNullException("ownerType"); } // Map owner type to this property // Build key FromNameKey key = new FromNameKey(Name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name)); } } if (typeMetadata != null) { OverrideMetadata(ownerType, typeMetadata); } lock (Synchronized) { PropertyFromName[key] = this; } return(this); }
public bool Equals(FromNameKey key) { if (_name.Equals(key._name)) { return(_ownerType == key._ownerType); } return(false); }
private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { FromNameKey key = new FromNameKey(name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Get("PropertyAlreadyRegistered", name, ownerType.Name)); } } if (defaultMetadata == null) { defaultMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType); } else { if (!defaultMetadata.DefaultValueWasSet()) { defaultMetadata.DefaultValue = AutoGenerateDefaultValue(propertyType); } ValidateMetadataDefaultValue(defaultMetadata, propertyType, name, validateValueCallback); } DependencyProperty dependencyProperty = new DependencyProperty(name, propertyType, ownerType, defaultMetadata, validateValueCallback); defaultMetadata.Seal(dependencyProperty, null); if (defaultMetadata.IsInherited) { dependencyProperty._packedData |= Flags.IsPotentiallyInherited; } if (defaultMetadata.UsingDefaultValueFactory) { dependencyProperty._packedData |= Flags.IsPotentiallyUsingDefaultValueFactory; } lock (Synchronized) { PropertyFromName[key] = dependencyProperty; } if (TraceDependencyProperty.IsEnabled) { TraceDependencyProperty.TraceActivityItem(TraceDependencyProperty.Register, dependencyProperty, dependencyProperty.OwnerType); } return(dependencyProperty); }
[FriendAccessAllowed] // Built into Base, also used by Framework. internal static DependencyProperty FromName(string name, Type ownerType) { DependencyProperty dp = null; if (name != null) { if (ownerType != null) { FromNameKey key = new FromNameKey(name, ownerType); while ((dp == null) && (ownerType != null)) { // Ensure static constructor of type has run MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(ownerType); // Locate property key.UpdateNameKey(ownerType); lock (Synchronized) { dp = (DependencyProperty)PropertyFromName[key]; } ownerType = ownerType.BaseType; } } else { throw new ArgumentNullException("ownerType"); } } else { throw new ArgumentNullException("name"); } return(dp); }
public bool Equals(FromNameKey key) { return (_name.Equals(key._name) && (_ownerType == key._ownerType)); }
private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback) { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name"); if (propertyType == null) throw new ArgumentNullException("propertyType"); if (ownerType == null) throw new ArgumentNullException("ownerType"); FromNameKey key = new FromNameKey(name, ownerType); if (_PropertyFromName.Contains(key)) throw new ArgumentException("The property \"" + name + "\" is exists for \"" + ownerType.FullName + "\""); if (typeMetadata == null) typeMetadata = new PropertyMetadata(); DependencyProperty dp = new DependencyProperty(); dp.Name = name; dp.PropertyType = propertyType; dp.OwnerType = ownerType; dp.DefaultMetadata = typeMetadata; dp.ValidateValueCallback = validateValueCallback; _PropertyFromName.Add(key, dp); return dp; }
internal static DependencyProperty FromName(string name, Type ownerType) { FromNameKey key = new FromNameKey(name, ownerType); DependencyProperty dp = (DependencyProperty)_PropertyFromName[key]; return dp; }
/// <summary> /// Associate another owner type with this property /// </summary> /// <remarks> /// The owner type is used when resolving a property by name (<see cref="FromName"/>) /// </remarks> /// <param name="ownerType">Additional owner type</param> /// <param name="typeMetadata">Optional type metadata to override on owner's behalf</param> /// <returns>This property</returns> public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata) { if (ownerType == null) { throw new ArgumentNullException("ownerType"); } // Map owner type to this property // Build key FromNameKey key = new FromNameKey(Name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Get(SRID.PropertyAlreadyRegistered, Name, ownerType.Name)); } } if (typeMetadata != null) { OverrideMetadata(ownerType, typeMetadata); } lock (Synchronized) { PropertyFromName[key] = this; } return this; }
private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { FromNameKey key = new FromNameKey(name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Get(SRID.PropertyAlreadyRegistered, name, ownerType.Name)); } } // Establish default metadata for all types, if none is provided if (defaultMetadata == null) { defaultMetadata = AutoGeneratePropertyMetadata( propertyType, validateValueCallback, name, ownerType ); } else // Metadata object is provided. { // If the defaultValue wasn't specified auto generate one if (!defaultMetadata.DefaultValueWasSet()) { defaultMetadata.DefaultValue = AutoGenerateDefaultValue(propertyType); } ValidateMetadataDefaultValue( defaultMetadata, propertyType, name, validateValueCallback ); } // Create property DependencyProperty dp = new DependencyProperty(name, propertyType, ownerType, defaultMetadata, validateValueCallback); // Seal (null means being used for default metadata, calls OnApply) defaultMetadata.Seal(dp, null); if (defaultMetadata.IsInherited) { dp._packedData |= Flags.IsPotentiallyInherited; } if (defaultMetadata.UsingDefaultValueFactory) { dp._packedData |= Flags.IsPotentiallyUsingDefaultValueFactory; } // Map owner type to this property // Build key lock (Synchronized) { PropertyFromName[key] = dp; } if( TraceDependencyProperty.IsEnabled ) { TraceDependencyProperty.TraceActivityItem( TraceDependencyProperty.Register, dp, dp.OwnerType ); } return dp; }
[FriendAccessAllowed] // Built into Base, also used by Framework. internal static DependencyProperty FromName(string name, Type ownerType) { DependencyProperty dp = null; if (name != null) { if (ownerType != null) { FromNameKey key = new FromNameKey(name, ownerType); while ((dp == null) && (ownerType != null)) { // Ensure static constructor of type has run MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(ownerType); // Locate property key.UpdateNameKey(ownerType); lock (Synchronized) { dp = (DependencyProperty)PropertyFromName[key]; } ownerType = ownerType.BaseType; } } else { throw new ArgumentNullException("ownerType"); } } else { throw new ArgumentNullException("name"); } return dp; }
private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback) { FromNameKey key = new FromNameKey(name, ownerType); lock (Synchronized) { if (PropertyFromName.Contains(key)) { throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, name, ownerType.Name)); } } // Establish default metadata for all types, if none is provided if (defaultMetadata == null) { defaultMetadata = AutoGeneratePropertyMetadata(propertyType, validateValueCallback, name, ownerType); } else // Metadata object is provided. { // If the defaultValue wasn't specified auto generate one if (!defaultMetadata.DefaultValueWasSet()) { defaultMetadata.DefaultValue = AutoGenerateDefaultValue(propertyType); } ValidateMetadataDefaultValue(defaultMetadata, propertyType, name, validateValueCallback); } // Create property DependencyProperty dp = new DependencyProperty(name, propertyType, ownerType, defaultMetadata, validateValueCallback); // Seal (null means being used for default metadata, calls OnApply) defaultMetadata.Seal(dp, null); if (defaultMetadata.IsInherited) { dp._packedData |= Flags.IsPotentiallyInherited; } if (defaultMetadata.UsingDefaultValueFactory) { dp._packedData |= Flags.IsPotentiallyUsingDefaultValueFactory; } // Map owner type to this property // Build key lock (Synchronized) { PropertyFromName[key] = dp; } if (TraceDependencyProperty.IsEnabled) { TraceDependencyProperty.TraceActivityItem( TraceDependencyProperty.Register, dp, dp.OwnerType); } return(dp); }
public bool Equals(FromNameKey key) { return(_name.Equals(key._name) && (_ownerType == key._ownerType)); }