public int GetNextReference( IReferenceConsumer requester, Type targettype, IReplicated targetobject ) { HashableWeakReference targetobjectweakreference = new HashableWeakReference( targetobject ); if( referencebyobject.Contains( targetobjectweakreference ) ) { return (int)referencebyobject[ targetobjectweakreference ]; } if( ismaster ) { int nextreference = _GetNextReferenceForType( targettype ); objectbyreference.Add( nextreference, targetobjectweakreference ); referencebyobject.Add( targetobjectweakreference, nextreference ); return nextreference; } else { return null; } }
static int GetNextReference(Type targettype, object targetobject) { HashableWeakReference targetobjectweakreference = new HashableWeakReference(targetobject); if (referencebyobject.Contains(targetobjectweakreference)) { return((int)referencebyobject[targetobjectweakreference]); } if (!nextreferencebytype.Contains(targettype)) { nextreferencebytype.Add(targettype, 1); } int nextreference = (int)nextreferencebytype[targettype]; nextreferencebytype[targettype] = nextreference + 1; objectbyreference.Add(nextreference, targetobjectweakreference); referencebyobject.Add(targetobjectweakreference, nextreference); return(nextreference); }
/// <summary> /// Initializes the <paramref name="target"/> with the given <paramref name="source"/> instance. /// </summary> /// <param name="target">The target to initialize.</param> /// <param name="source">The instance that will be introduced to the <see cref="IInitialize{T}"/> instance.</param> private static void Initialize(IInitialize <T> target, T source) { if (target == null) { return; } if ((_initializeCallCount = ++_initializeCallCount % 100) == 0) { _instances.RemoveWhere(w => !w.IsAlive); } // Make sure that the target is initialized only once var weakReference = new HashableWeakReference(target); if (_instances.Contains(weakReference)) { return; } // Initialize the target target.Initialize(source); _instances.Add(weakReference); }
static int GetNextReference( Type targettype, object targetobject ) { HashableWeakReference targetobjectweakreference = new HashableWeakReference( targetobject ); if( referencebyobject.Contains( targetobjectweakreference ) ) { return (int)referencebyobject[ targetobjectweakreference ]; } if( !nextreferencebytype.Contains( targettype ) ) { nextreferencebytype.Add( targettype, 1 ); } int nextreference = (int)nextreferencebytype[ targettype ]; nextreferencebytype[ targettype ] = nextreference + 1; objectbyreference.Add( nextreference, targetobjectweakreference ); referencebyobject.Add( targetobjectweakreference, nextreference ); return nextreference; }