public static void CreateAssociation(object primary, object secondary)
{
if (primary == null)
{
throw new ArgumentNullException(nameof(primary));
}
if (secondary == null)
{
throw new ArgumentNullException(nameof(secondary));
}
if (primary == secondary)
{
throw new ArgumentException(SR.TypeDescriptorSameAssociation);
}
if (s_associationTable == null)
{
lock (s_internalSyncObject)
{
if (s_associationTable == null)
{
s_associationTable = new WeakHashtable();
}
}
}
IList associations = (IList)s_associationTable[primary];
if (associations == null)
{
lock (s_associationTable)
{
associations = (IList)s_associationTable[primary];
if (associations == null)
{
associations = new ArrayList(4);
s_associationTable.SetWeak(primary, associations);
}
}
}
else
{
for (int idx = associations.Count - 1; idx >= 0; idx--)
{
WeakReference r = (WeakReference)associations[idx];
if (r.IsAlive && r.Target == secondary)
{
throw new ArgumentException(SR.TypeDescriptorAlreadyAssociated);
}
}
}
lock (associations)
{
associations.Add(new WeakReference(secondary));
}
}