コード例 #1
0
        public void AddAdapter(INakedObjectAdapter nakedObjectAdapter)
        {
            if (nakedObjectAdapter == null)
            {
                throw new NakedObjectSystemException("Cannot add null adapter to IdentityAdapterMap");
            }

            var obj = nakedObjectAdapter.Object;

            if (nakedObjectAdapterMap.ContainsObject(obj))
            {
                throw new NakedObjectSystemException("POCO Map already contains object");
            }

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

            if (nakedObjectAdapter.Spec.IsObject)
            {
                nakedObjectAdapterMap.Add(obj, nakedObjectAdapter);
            }

            // order is important - add to identity map after poco map
            identityAdapterMap.Add(nakedObjectAdapter.Oid, nakedObjectAdapter);

            nakedObjectAdapter.LoadAnyComplexTypes();
        }
コード例 #2
0
        public void AddAdapter(INakedObjectAdapter nakedObjectAdapter)
        {
            Assert.AssertNotNull("Cannot add null adapter to IdentityAdapterMap", nakedObjectAdapter);
            object obj = nakedObjectAdapter.Object;

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

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

            if (nakedObjectAdapter.Spec.IsObject)
            {
                nakedObjectAdapterMap.Add(obj, nakedObjectAdapter);
            }
            // order is important - add to identity map after poco map
            identityAdapterMap.Add(nakedObjectAdapter.Oid, nakedObjectAdapter);

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

            nakedObjectAdapter.LoadAnyComplexTypes();
        }