Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ private static void RegisterParameterValidation(string name, Type propertyType,

private static DependencyProperty RegisterCommon(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
{
FromNameKey key = new FromNameKey(name, ownerType);
FromNameKey key = new(name, ownerType);
lock (Synchronized)
{
if (PropertyFromName.Contains(key))
if (PropertyFromName.ContainsKey(key))
{
throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, name, ownerType.Name));
}
Expand Down Expand Up @@ -761,11 +761,11 @@ public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata

// Map owner type to this property
// Build key
FromNameKey key = new FromNameKey(Name, ownerType);
FromNameKey key = new(Name, ownerType);

lock (Synchronized)
{
if (PropertyFromName.Contains(key))
if (PropertyFromName.ContainsKey(key))
{
throw new ArgumentException(SR.Format(SR.PropertyAlreadyRegistered, Name, ownerType.Name));
}
Expand All @@ -776,13 +776,11 @@ public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata
OverrideMetadata(ownerType, typeMetadata);
}


lock (Synchronized)
{
PropertyFromName[key] = this;
}


return this;
}

Expand Down Expand Up @@ -979,19 +977,17 @@ internal static DependencyProperty FromName(string name, Type ownerType)
ArgumentNullException.ThrowIfNull(name);
ArgumentNullException.ThrowIfNull(ownerType);

FromNameKey key = new FromNameKey(name, ownerType);

while ((dp == null) && (ownerType != null))
while (ownerType != null)
{
// Ensure static constructor of type has run
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(ownerType);
SecurityHelper.RunClassConstructor(ownerType);

// Locate property
key.UpdateNameKey(ownerType);

FromNameKey key = new(name, ownerType);
lock (Synchronized)
{
dp = (DependencyProperty)PropertyFromName[key];
if (PropertyFromName.TryGetValue(key, out dp))
return dp;
}

ownerType = ownerType.BaseType;
Expand Down Expand Up @@ -1033,7 +1029,7 @@ internal static bool IsValidType(object value, Type propertyType)
return true;
}

private class FromNameKey
private readonly struct FromNameKey : IEquatable<FromNameKey>
{
public FromNameKey(string name, Type ownerType)
{
Expand All @@ -1043,39 +1039,25 @@ public FromNameKey(string name, Type ownerType)
_hashCode = _name.GetHashCode() ^ _ownerType.GetHashCode();
}

public void UpdateNameKey(Type ownerType)
{
_ownerType = ownerType;

_hashCode = _name.GetHashCode() ^ _ownerType.GetHashCode();
}

public override int GetHashCode()
{
return _hashCode;
}

public override bool Equals(object o)
{
if ((o != null) && (o is FromNameKey))
{
return Equals((FromNameKey)o);
}
else
{
return false;
}
return o is FromNameKey key && Equals(key);
}

public bool Equals(FromNameKey key)
{
return (_name.Equals(key._name) && (_ownerType == key._ownerType));
return _name.Equals(key._name) && _ownerType == key._ownerType;
}

private string _name;
private Type _ownerType;
private readonly string _name;
private readonly Type _ownerType;

private int _hashCode;
private readonly int _hashCode;
}


Expand Down Expand Up @@ -1198,13 +1180,13 @@ private enum Flags : int
/* property */ internal static ItemStructList<DependencyProperty> RegisteredPropertyList = new ItemStructList<DependencyProperty>(768);

// Synchronized: Covered by DependencyProperty.Synchronized
private static Hashtable PropertyFromName = new Hashtable();
private static readonly Dictionary<FromNameKey, DependencyProperty> PropertyFromName = new();

// Synchronized: Covered by DependencyProperty.Synchronized
private static int GlobalIndexCount;

// Global, cross-object synchronization
internal static object Synchronized = new object();
internal static readonly Lock Synchronized = new();

// Nullable Type
private static Type NullableType = typeof(Nullable<>);
Expand Down