public string GetIdentity(MarshalObject marshalObject)
        {
            IClassMap     classMap = Context.DomainMap.MustGetClassMap(marshalObject.Type);
            StringBuilder id       = new StringBuilder();
            string        sep      = classMap.IdentitySeparator;

            if (sep == "")
            {
                sep = "|";
            }
            foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps())
            {
                if (propertyMap.ReferenceType == ReferenceType.None)
                {
                    MarshalProperty mp = marshalObject.GetProperty(propertyMap.Name);
                    id.Append(mp.Value + sep);
                }
                else
                {
                    MarshalReference mr = marshalObject.GetReference(propertyMap.Name);
                    id.Append(GetIdentity(mr, mr.Value) + sep);
                }
            }
            if (id.Length > 0)
            {
                id.Length -= sep.Length;
            }
            return(id.ToString());
        }
        //pass 0 = get all properties (for ToObject overload) , pass 1 = get only primitive props, pass 2 = get only ref props
        public virtual void ToObject(MarshalObject marshalObject, ref object targetObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap    classMap = Context.DomainMap.MustGetClassMap(targetObject.GetType());
            IPropertyMap propertyMap;

            //PropertyStatus propStatus;
            if (pass == 0 || pass == 1)
            {
                foreach (MarshalProperty mp in marshalObject.Properties)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mp.Name);
                    ToProperty(targetObject, mp, propertyMap, refreshBehavior);
                }
            }

            if (pass == 0 || pass == 2)
            {
                foreach (MarshalReference mr in marshalObject.References)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mr.Name);
                    ToReference(targetObject, mr, propertyMap, refreshBehavior);
                }
            }

            if (targetObject != null)
            {
                if (pass == 0 || pass == 1)
                {
                    this.Context.IdentityMap.RegisterLoadedObject(targetObject);
                }
            }
        }
        protected virtual object GetObjectListObject(MarshalObject marshalObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap classMap     = Context.DomainMap.MustGetClassMap(marshalObject.Type);
            Type      realType     = Context.AssemblyManager.MustGetTypeFromClassMap(classMap);
            string    id           = GetIdentity(marshalObject);
            object    targetObject = this.Context.GetObjectById(id, realType, true);

            ToObject(marshalObject, ref targetObject, pass, refreshBehavior);
            return(targetObject);
        }
        public virtual MarshalObjectList FromObjectList(IList sourceObjects)
        {
            MarshalObjectList mol = new MarshalObjectList();

            foreach (object obj in sourceObjects)
            {
                MarshalObject mo = FromObject(obj);
                mol.Objects.Add(mo);
            }

            return(mol);
        }
        public virtual MarshalObject FromObject(object sourceObject, bool upForCreation)
        {
            IClassMap classMap = Context.DomainMap.MustGetClassMap(sourceObject.GetType());
            MarshalObject mo = new MarshalObject();
            mo.Type = classMap.GetName();
            if (upForCreation)
            {
                if (classMap.HasIdAssignedBySource())
                {
                    mo.TempId = Context.ObjectManager.GetObjectIdentity(sourceObject);
                }
            }
            PropertyStatus propStatus;
            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                propStatus = Context.GetPropertyStatus(sourceObject, propertyMap.Name);
                if (propStatus != PropertyStatus.NotLoaded || upForCreation)
                {
                    if (propertyMap.ReferenceType == ReferenceType.None)
                    {
                        if (propertyMap.IsCollection)
                        {

                        }
                        else
                        {
                            if (upForCreation && propertyMap.GetIsAssignedBySource())
                            {

                            }
                            else
                            {
                                mo.Properties.Add(FromProperty(sourceObject, propertyMap));
                            }
                        }
                    }
                    else
                    {
                        if (propertyMap.IsCollection)
                        {
                            //mo.ReferenceLists.Add(FromReferenceList(sourceObject, propertyMap));
                        }
                        else
                        {
                            mo.References.Add(FromReference(sourceObject, propertyMap));
                        }
                    }
                }
            }

            return mo;
        }
        public virtual MarshalObject FromObject(object sourceObject, bool upForCreation)
        {
            IClassMap     classMap = Context.DomainMap.MustGetClassMap(sourceObject.GetType());
            MarshalObject mo       = new MarshalObject();

            mo.Type = classMap.GetName();
            if (upForCreation)
            {
                if (classMap.HasIdAssignedBySource())
                {
                    mo.TempId = Context.ObjectManager.GetObjectIdentity(sourceObject);
                }
            }
            PropertyStatus propStatus;

            foreach (IPropertyMap propertyMap in classMap.GetAllPropertyMaps())
            {
                propStatus = Context.GetPropertyStatus(sourceObject, propertyMap.Name);
                if (propStatus != PropertyStatus.NotLoaded || upForCreation)
                {
                    if (propertyMap.ReferenceType == ReferenceType.None)
                    {
                        if (propertyMap.IsCollection)
                        {
                        }
                        else
                        {
                            if (upForCreation && propertyMap.GetIsAssignedBySource())
                            {
                            }
                            else
                            {
                                mo.Properties.Add(FromProperty(sourceObject, propertyMap));
                            }
                        }
                    }
                    else
                    {
                        if (propertyMap.IsCollection)
                        {
                            //mo.ReferenceLists.Add(FromReferenceList(sourceObject, propertyMap));
                        }
                        else
                        {
                            mo.References.Add(FromReference(sourceObject, propertyMap));
                        }
                    }
                }
            }

            return(mo);
        }
 protected virtual object GetObjectListObject(MarshalObject marshalObject, int pass, RefreshBehaviorType refreshBehavior)
 {
     IClassMap classMap = Context.DomainMap.MustGetClassMap(marshalObject.Type);
     Type realType = Context.AssemblyManager.MustGetTypeFromClassMap(classMap);
     string id = GetIdentity(marshalObject);
     object targetObject = this.Context.GetObjectById(id, realType, true);
     ToObject(marshalObject, ref targetObject, pass, refreshBehavior);
     return targetObject;
 }
        //pass 0 = get all properties (for ToObject overload) , pass 1 = get only primitive props, pass 2 = get only ref props
        public virtual void ToObject(MarshalObject marshalObject, ref object targetObject, int pass, RefreshBehaviorType refreshBehavior)
        {
            IClassMap classMap = Context.DomainMap.MustGetClassMap(targetObject.GetType());
            IPropertyMap propertyMap;
            //PropertyStatus propStatus;
            if (pass == 0 || pass == 1)
            {
                foreach (MarshalProperty mp in marshalObject.Properties)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mp.Name);
                    ToProperty(targetObject, mp, propertyMap, refreshBehavior);
                }
            }

            if (pass == 0 || pass == 2)
            {
                foreach (MarshalReference mr in marshalObject.References)
                {
                    //propStatus = ctx.GetPropertyStatus(targetObject, mp.Name);
                    propertyMap = classMap.MustGetPropertyMap(mr.Name);
                    ToReference(targetObject, mr, propertyMap, refreshBehavior);
                }
            }

            if (targetObject != null)
                if (pass == 0 || pass == 1)
                    this.Context.IdentityMap.RegisterLoadedObject(targetObject);
        }
 public virtual void ToObject(MarshalObject marshalObject, ref object targetObject)
 {
     ToObject(marshalObject, ref targetObject, 0, RefreshBehaviorType.DefaultBehavior);
 }
 public string GetIdentity(MarshalObject marshalObject)
 {
     IClassMap classMap = Context.DomainMap.MustGetClassMap(marshalObject.Type);
     StringBuilder id = new StringBuilder() ;
     string sep = classMap.IdentitySeparator;
     if (sep == "") { sep = "|"; }
     foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps())
     {
         if (propertyMap.ReferenceType == ReferenceType.None)
         {
             MarshalProperty mp = marshalObject.GetProperty(propertyMap.Name);
             id.Append(mp.Value + sep);
         }
         else
         {
             MarshalReference mr = marshalObject.GetReference(propertyMap.Name);
             id.Append(GetIdentity(mr, mr.Value) + sep);
         }
     }
     if (id.Length > 0) { id.Length -= sep.Length; }
     return id.ToString();
 }
 public virtual void ToObject(MarshalObject marshalObject, ref object targetObject)
 {
     ToObject(marshalObject, ref targetObject, 0, RefreshBehaviorType.DefaultBehavior);
 }
		private object GetObjectByMarshalObject(IMarshalingTransformer transformer, MarshalObject mo, IClassMap classMap)
		{
			Type type = this.Context.AssemblyManager.MustGetTypeFromClassMap(classMap);
			return this.Context.GetObjectById(transformer.GetIdentity(mo), type, true);
		}