コード例 #1
0
        public virtual void AddAdapter(INakedObject nakedObject)
        {
            Assert.AssertNotNull("Cannot add null adapter to IdentityAdapterMap", nakedObject);
            object obj = nakedObject.Object;

            Assert.AssertFalse("POCO Map already contains object", obj, pocoAdapterMap.ContainsObject(obj));

            if (unloadedObjects.ContainsKey(obj))
            {
                string msg = string.Format(Resources.NakedObjects.TransientReferenceMessage, obj);
                throw new TransientReferenceException(msg);
            }

            // TODO we should be ignoring immutable values object as well
            if (nakedObject.Spec.IsObject)
            {
                pocoAdapterMap.Add(obj, nakedObject);
            }
            // order is important - add to identity map after poco map
            identityAdapterMap.Add(nakedObject.Oid, nakedObject);

            // log at end so that if ToString needs adapters they're in maps.
            Log.DebugFormat("Adding identity for {0}", nakedObject);

            nakedObject.LoadAnyComplexTypes();
        }