/// <summary> /// Sets an association between an object and a symbol. /// </summary> /// <param name="associatable">The associated object; or <see langword="null"/>.</param> /// <param name="symbol">The associated symbol; or <see langword="null"/>.</param> public static void SetAssociation(IAssociatable associatable, Symbol symbol) { if (symbol != null && associatable != null) { // Remove the associations between the specified symbol and its associatable, // and the specified associatable and its symbol. SetAssociation(symbol.association, null); SetAssociation(associatable, null); symbol.association = associatable; associatable.SetAssociatedSymbol(symbol); } else if (symbol != null) { if (symbol.association != null) { symbol.association.SetAssociatedSymbol(null); } symbol.association = null; } else if (associatable != null) { if (associatable.AssociatedSymbol != null) { associatable.AssociatedSymbol.association = null; } associatable.SetAssociatedSymbol(null); } // Else: both are null. We don't have to associate a null object with a null Symbol. }
/// <summary> /// Initializes a new instance of the <see cref="Reference"/> class that references an associatable object. /// </summary> /// <param name="associatable">The <see cref="IAssociatable"/> being referenced.</param> /// <remarks> /// When the <see cref="IAssociatable"/> changes its <see cref="IAssociatable.AssociatedSymbol"/>, /// this reference is <em>not</em> updated or changed to reflect that, and will still be pointing at the /// previous, obsolete symbol. /// </remarks> public Reference(IAssociatable associatable) { #region Contract Contract.Requires<ArgumentNullException>(associatable != null); #endregion this.symbol = associatable.AssociatedSymbol; }
/// <summary> /// Initializes a new instance of the <see cref="Reference"/> class that references an associatable object. /// </summary> /// <param name="associatable">The <see cref="IAssociatable"/> being referenced.</param> /// <remarks> /// When the <see cref="IAssociatable"/> changes its <see cref="IAssociatable.AssociatedSymbol"/>, /// this reference is <em>not</em> updated or changed to reflect that, and will still be pointing at the /// previous, obsolete symbol. /// </remarks> public Reference(IAssociatable associatable) { #region Contract Contract.Requires <ArgumentNullException>(associatable != null); #endregion this.symbol = associatable.AssociatedSymbol; }
/// <summary> /// Sets an association between an object and a symbol. /// </summary> /// <param name="symbol">The associated symbol; or <see langword="null"/>.</param> /// <param name="associatable">The associated object; or <see langword="null"/>.</param> public static void SetAssociation(Symbol symbol, IAssociatable associatable) { SetAssociation(associatable, symbol); }
/// <summary> /// Sets an association between an object and a symbol. /// </summary> /// <param name="associatable">The associated object; or <see langword="null"/>.</param> /// <param name="symbol">The associated symbol; or <see langword="null"/>.</param> public static void SetAssociation(IAssociatable associatable, Symbol symbol) { if (symbol != null && associatable != null) { // Remove the associations between the specified symbol and its associatable, // and the specified associatable and its symbol. SetAssociation(symbol.association, null); SetAssociation(associatable, null); symbol.association = associatable; associatable.SetAssociatedSymbol(symbol); } else if (symbol != null) { if (symbol.association != null) symbol.association.SetAssociatedSymbol(null); symbol.association = null; } else if (associatable != null) { if (associatable.AssociatedSymbol != null) associatable.AssociatedSymbol.association = null; associatable.SetAssociatedSymbol(null); } // Else: both are null. We don't have to associate a null object with a null Symbol. }
/// <summary> /// Initializes a new instance of the <see cref="Reference"/> class that references an associatable object. /// </summary> /// <param name="associatable">The <see cref="IAssociatable"/> being referenced.</param> /// <remarks> /// When the <see cref="IAssociatable"/> changes its <see cref="IAssociatable.AssociatedSymbol"/>, /// this reference is <em>not</em> updated or changed to reflect that, and will still be pointing at the /// previous, obsolete symbol. /// </remarks> public Reference(IAssociatable associatable) { Symbol = associatable.AssociatedSymbol; }