//, TypeAliaser aliaser
        public LeafDefaultSet getDefaultsForAllLinkedObjects(Object root, NodeExpander nodeExpander)
        {
            LeafDefaultSet result = new LeafDefaultSet();

            ObjectExplorerImpl explorer = new ObjectExplorerImpl();
            MoveAway           down     = (from, propertyName, to, isIndexed, index) =>
            {
                return(isIndexed || (to != null && !result.Type2Defaults.ContainsKey(to.GetType())));
            };
            MoveBack up = (from, propertyName, to, isIndexed) =>
            {
            };

            OnLeaf leaf = (from, propertyName, to, index) =>
            {
                Defaults4Class defaults = null;
                if (from == null)
                {
                    return;
                }
                Type fromType = from.GetType();
                if (!result.Type2Defaults.ContainsKey(fromType))
                {
                    defaults = new Defaults4Class();
                    defaults.FullClassName         = fromType.FullName;
                    result.Type2Defaults[fromType] = defaults;
                }
                else
                {
                    defaults = result.Type2Defaults[fromType];
                }
                defaults.PropertyName2DefaultValue[propertyName] = to;
            };

            explorer.NodeExpander = nodeExpander;
            explorer.explore(root, down, up, leaf);
            return(result);
        }
        //, TypeAliaser aliaser
        public LeafDefaultSet getDefaultsForAllLinkedObjects(Object root, NodeExpander nodeExpander)
        {
            LeafDefaultSet result = new LeafDefaultSet();

            ObjectExplorerImpl explorer = new ObjectExplorerImpl();
                MoveAway down = ( from,  propertyName,  to,  isIndexed, index) =>
                {
                    return (isIndexed || (to != null && !result.Type2Defaults.ContainsKey(to.GetType())));
                };
             MoveBack  up = (from, propertyName, to, isIndexed) =>
                {

                };

             OnLeaf leaf = (from, propertyName, to, index) =>
                {
                    Defaults4Class defaults = null;
                    if (from==null) {return;}
                    Type fromType = from.GetType();
                    if (!result.Type2Defaults.ContainsKey(fromType))
                    {
                        defaults = new Defaults4Class();
                        defaults.FullClassName = fromType.FullName;
                        result.Type2Defaults[fromType] = defaults;
                    }
                    else
                    {
                        defaults = result.Type2Defaults[fromType];
                    }
                    defaults.PropertyName2DefaultValue[propertyName] = to;
                };

             explorer.NodeExpander = nodeExpander;
                explorer.explore(root, down, up, leaf);
                return result;
        }
Beispiel #3
0
        static bool isDefaultLeafValueDefault(object from, string propertyName, object leafValue, LeafDefaultSet LeafDefaultSet)
        {
            if (LeafDefaultSet == null)
            {
                throw new Exception("OmitDefaultLeafValuesInJs==true but LeafDefaultSet is unspecified - unable to determine what values are default !");
            }

            Type t = from.GetType();

            if (LeafDefaultSet.Type2Defaults.ContainsKey(t))
            {
                Defaults4Class defaults = LeafDefaultSet.Type2Defaults[t];
                if (!defaults.PropertyName2DefaultValue.ContainsKey(propertyName))
                {
                    return(false);
                }
                Object defaultValue = defaults.PropertyName2DefaultValue[propertyName];
                return((leafValue == defaultValue) || leafValue != null && leafValue.Equals(defaultValue));
            }
            {
                // is this an error ?
                return(false);
            }
        }