public TreeNode GetTreeNode(object o)
        {
            if (o == null)
            {
                return(GetNullNode());
            }

            if (o == _omittedValue)
            {
                return(new TreeNode("{ ... }"));
            }

            if (o is Exception)
            {
                return(GetExceptionNode((Exception)o));
            }

            if (o is DateTime)
            {
                return(GetDateTimeNode((DateTime)o));
            }

            if (o is String)
            {
                return(GetStringNode((string)o));
            }

            if (o is Type)
            {
                return(GetTypeNode((Type)o));
            }

            if (o is byte[])
            {
                return(GetByteArrayNode((byte[])o));
            }

            if (o is ValueType)
            {
                return(GetValueTypeNode(o));
            }

            if (_ancestors.Contains(o) || _level >= _maxLoadDepth)
            {
                return(new TreeNode("{ ... }"));
            }

            TreeNode parentNode = new TreeNode(GetNiceTypeName(o.GetType()));

            if (o is ObjectCollectionCache)
            {
                parentNode.Text = GetNiceTypeName(((ObjectCollectionCache)o).OriginalType);
            }

            _ancestors.Push(o);
            int oldLevel = _level;

            _level++;

            if (o is IEnumerable)
            {
                parentNode.SelectedImageIndex = parentNode.ImageIndex = 4;
                var members = (from object element in (o as IEnumerable)
                               select new Member {
                    Name = null, Value = element
                }).ToList();

                AttachChildren(parentNode, members);;
                parentNode.Text += " (" + members.Count + " item" + (members.Count != 1 ? "s" : "") + ")";
            }
            else if (o is DbDataRecord)
            {
                parentNode.SelectedImageIndex = parentNode.ImageIndex = 2;
                DbDataRecord rec = o as DbDataRecord;

                var members = from element in Enumerable.Range(0, rec.FieldCount)
                              select new Member {
                    Name = rec.GetName(element), Value = rec.IsDBNull(element) ? null : rec.GetValue(element)
                };

                AttachChildren(parentNode, members);;
            }
            else
            {
                parentNode.SelectedImageIndex = parentNode.ImageIndex = 1;

                var members = from element in o.GetType().GetMembers(BindingFlags.Public | BindingFlags.Instance)
                              let p                 = element as PropertyInfo
                                              let f = element as FieldInfo
                                                      where p != null || f != null
                                                      select new Member {
                    Name = element.Name, Value = p != null?p.GetValue(o, null) : f.GetValue(o)
                };

                // replace members who would lead to tree explosion with _omittedValue
                // which emits { ... }

                if (o is EntityReference)
                {
                    members = members.Select(c => new Member {
                        Name = c.Name, Value = (c.Name == "RelationshipSet" ? _omittedValue : c.Value)
                    });
                }

                AttachChildren(parentNode, members);;

                IEntityWithKey ewk = o as IEntityWithKey;
                if (ewk != null)
                {
                    parentNode.Text += " { " + GetEntityKeyText(ewk.EntityKey) + " }";
                }
            }
            if (_level <= _expandDepth)
            {
                parentNode.Expand();
            }
            _ancestors.Pop();
            _level = oldLevel;

            return(parentNode);
        }
 /// <summary>
 /// Creates a strategy object for the given entity.  Keys will be stored in the entity.
 /// </summary>
 /// <param name="entity">The entity to use</param>
 public EntityWithKeyStrategy(IEntityWithKey entity)
 {
     _entity = entity;
 }
 // <summary>
 // Creates a strategy object for the given entity.  Keys will be stored in the entity.
 // </summary>
 // <param name="entity"> The entity to use </param>
 public EntityWithKeyStrategy(IEntityWithKey entity)
 {
     _entity = entity;
 }
 /// <summary>
 /// Marker method to indicate the instances the method is called on
 /// within path expressions should not be updated.
 /// </summary>
 public static object WithoutUpdate(this IEntityWithKey entity)
 {
     throw new InvalidOperationException("The WithoutUpdate() method is a marker method in entity property paths and should not be effectively invoked.");
 }
Example #5
0
 public void Detach(IEntityWithKey tilskudd)
 {
     _container.Detach(tilskudd);
 }
Example #6
0
 public void Delete(IEntityWithKey entity)
 {
     _container.DeleteObject(entity);
 }
Example #7
0
 public void Attach(IEntityWithKey enity)
 {
     AttachIfNeeded(enity);
 }
Example #8
0
 public void Update(IEntityWithKey entity)
 {
     AttachIfNeeded(entity);
     _container.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified);
 }
Example #9
0
 public void Add(IEntityWithKey entity)
 {
     _container.AddObject(GetEntitySetName(entity), entity);
 }