Пример #1
0
        protected virtual void TraverseDictionary <TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor <TContext> visitor, int currentDepth, Type keyType, Type valueType, TContext context)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);
            bool flag = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            IDictionaryEnumerator enumerator = ((IDictionary)dictionary.Value).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    DictionaryEntry   dictionaryEntry   = (DictionaryEntry)enumerator.Current;
                    object            value             = (!flag) ? dictionaryEntry.Key : namingConvention.Apply(dictionaryEntry.Key.ToString());
                    IObjectDescriptor objectDescriptor  = GetObjectDescriptor(value, keyType);
                    IObjectDescriptor objectDescriptor2 = GetObjectDescriptor(dictionaryEntry.Value, valueType);
                    if (visitor.EnterMapping(objectDescriptor, objectDescriptor2, context))
                    {
                        Traverse(objectDescriptor, visitor, currentDepth, context);
                        Traverse(objectDescriptor2, visitor, currentDepth, context);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            visitor.VisitMappingEnd(dictionary, context);
        }
Пример #2
0
        protected virtual void TraverseDictionary(IObjectDescriptor dictionary, IObjectGraphVisitor visitor, int currentDepth, Type keyType, Type valueType)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType);
            bool flag = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            IDictionaryEnumerator enumerator = ((IDictionary)dictionary.Value).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    DictionaryEntry current = (DictionaryEntry)enumerator.Current;
                    string          str     = !flag?current.Key.ToString() : this.namingConvention.Apply(current.Key.ToString());

                    IObjectDescriptor objectDescriptor = this.GetObjectDescriptor(str, keyType);
                    IObjectDescriptor descriptor2      = this.GetObjectDescriptor(current.Value, valueType);
                    if (visitor.EnterMapping(objectDescriptor, descriptor2))
                    {
                        this.Traverse(objectDescriptor, visitor, currentDepth);
                        this.Traverse(descriptor2, visitor, currentDepth);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            visitor.VisitMappingEnd(dictionary);
        }
 private void TraverseGenericDictionaryHelper <TKey, TValue>(
     IDictionary <TKey, TValue> value,
     IObjectGraphVisitor visitor, int currentDepth)
 {
     foreach (var entry in value)
     {
         if (visitor.EnterMapping(entry.Key, typeof(TKey), entry.Value, typeof(TValue)))
         {
             Traverse(entry.Key, typeof(TKey), visitor, currentDepth);
             Traverse(entry.Value, typeof(TValue), visitor, currentDepth);
         }
     }
 }
Пример #4
0
 protected virtual void TraverseProperties <TContext>(IObjectDescriptor value, IObjectGraphVisitor <TContext> visitor, int currentDepth, TContext context)
 {
     visitor.VisitMappingStart(value, typeof(string), typeof(object), context);
     foreach (IPropertyDescriptor property in typeDescriptor.GetProperties(value.Type, value.Value))
     {
         IObjectDescriptor value2 = property.Read(value.Value);
         if (visitor.EnterMapping(property, value2, context))
         {
             Traverse(new ObjectDescriptor(property.Name, typeof(string), typeof(string)), visitor, currentDepth, context);
             Traverse(value2, visitor, currentDepth, context);
         }
     }
     visitor.VisitMappingEnd(value, context);
 }
Пример #5
0
 protected virtual void TraverseProperties(IObjectDescriptor value, IObjectGraphVisitor visitor, int currentDepth)
 {
     visitor.VisitMappingStart(value, typeof(string), typeof(object));
     foreach (IPropertyDescriptor descriptor in this.typeDescriptor.GetProperties(value.Type, value.Value))
     {
         IObjectDescriptor descriptor2 = descriptor.Read(value.Value);
         if (visitor.EnterMapping(descriptor, descriptor2))
         {
             this.Traverse(new ObjectDescriptor(descriptor.Name, typeof(string), typeof(string)), visitor, currentDepth);
             this.Traverse(descriptor2, visitor, currentDepth);
         }
     }
     visitor.VisitMappingEnd(value);
 }
 private static void TraverseGenericDictionaryHelper <TKey, TValue>(
     // "this" is passed as parameter so that we can cache the generic method definition
     FullObjectGraphTraversalStrategy self,
     IDictionary <TKey, TValue> value,
     IObjectGraphVisitor visitor, int currentDepth)
 {
     foreach (var entry in value)
     {
         if (visitor.EnterMapping(entry.Key, typeof(TKey), entry.Value, typeof(TValue)))
         {
             self.Traverse(entry.Key, typeof(TKey), visitor, currentDepth);
             self.Traverse(entry.Value, typeof(TValue), visitor, currentDepth);
         }
     }
 }
Пример #7
0
        private void TraverseGenericDictionaryHelper <TKey, TValue>(
            IDictionary <TKey, TValue> dictionary,
            IObjectGraphVisitor visitor, int currentDepth)
        {
            foreach (var entry in dictionary)
            {
                var key   = GetObjectDescriptor(entry.Key, typeof(TKey));
                var value = GetObjectDescriptor(entry.Value, typeof(TValue));

                if (visitor.EnterMapping(key, value))
                {
                    Traverse(key, visitor, currentDepth);
                    Traverse(value, visitor, currentDepth);
                }
            }
        }
        protected virtual void TraverseDictionary(object value, Type type, IObjectGraphVisitor visitor, int currentDepth)
        {
            visitor.VisitMappingStart(value, type, typeof(object), typeof(object));

            foreach (DictionaryEntry entry in (IDictionary)value)
            {
                var keyType   = GetObjectType(entry.Key);
                var valueType = GetObjectType(entry.Value);
                if (visitor.EnterMapping(entry.Key, keyType, entry.Value, valueType))
                {
                    Traverse(entry.Key, keyType, visitor, currentDepth);
                    Traverse(entry.Value, valueType, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(value, type);
        }
        protected virtual void SerializeProperties(object value, Type type, IObjectGraphVisitor visitor, int currentDepth)
        {
            visitor.VisitMappingStart(value, type, typeof(string), typeof(object));

            foreach (var propertyDescriptor in typeDescriptor.GetProperties(type))
            {
                var propertyValue = propertyDescriptor.Property.GetValue(value, null);

                if (visitor.EnterMapping(propertyDescriptor, propertyValue))
                {
                    Traverse(propertyDescriptor.Name, typeof(string), visitor, currentDepth);
                    Traverse(propertyValue, propertyDescriptor.Property.PropertyType, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(value, type);
        }
Пример #10
0
        protected virtual void TraverseProperties(IObjectDescriptor value, IObjectGraphVisitor visitor, int currentDepth)
        {
            visitor.VisitMappingStart(value, typeof(string), typeof(object));

            foreach (var propertyDescriptor in typeDescriptor.GetProperties(value.Type, value.Value))
            {
                var propertyValue = propertyDescriptor.Read(value.Value);

                if (visitor.EnterMapping(propertyDescriptor, propertyValue))
                {
                    Traverse(new ObjectDescriptor(propertyDescriptor.Name, typeof(string), typeof(string)), visitor, currentDepth);
                    Traverse(propertyValue, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(value);
        }
Пример #11
0
        protected virtual void TraverseDictionary(IObjectDescriptor dictionary, IObjectGraphVisitor visitor, int currentDepth)
        {
            visitor.VisitMappingStart(dictionary, typeof(object), typeof(object));

            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var key   = GetObjectDescriptor(entry.Key, typeof(object));
                var value = GetObjectDescriptor(entry.Value, typeof(object));

                if (visitor.EnterMapping(key, value))
                {
                    Traverse(key, visitor, currentDepth);
                    Traverse(value, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(dictionary);
        }
Пример #12
0
        private void TraverseGenericDictionaryHelper <TKey, TValue>(
            IDictionary <TKey, TValue> dictionary,
            IObjectGraphVisitor visitor, int currentDepth, INamingConvention namingConvention)
        {
            var isDynamic = dictionary.GetType().FullName.Equals("System.Dynamic.ExpandoObject");

            foreach (var entry in dictionary)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key.ToString();
                var key       = GetObjectDescriptor(keyString, typeof(TKey));
                var value     = GetObjectDescriptor(entry.Value, typeof(TValue));

                if (visitor.EnterMapping(key, value))
                {
                    Traverse(key, visitor, currentDepth);
                    Traverse(value, visitor, currentDepth);
                }
            }
        }
Пример #13
0
        protected virtual void TraverseDictionary<TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor<TContext> visitor, int currentDepth, Type keyType, Type valueType, TContext context)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);

            var isDynamic = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key;
                var key = GetObjectDescriptor(keyString, keyType);
                var value = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value, context))
                {
                    Traverse(key, visitor, currentDepth, context);
                    Traverse(value, visitor, currentDepth, context);
                }
            }

            visitor.VisitMappingEnd(dictionary, context);
        }
Пример #14
0
        protected virtual void TraverseDictionary <TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor <TContext> visitor, Type keyType, Type valueType, TContext context, Stack <ObjectPathSegment> path)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);

            var isDynamic = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");

            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var keyValue = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key;
                var key      = GetObjectDescriptor(keyValue, keyType);
                var value    = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value, context))
                {
                    var keyAsString = TypeConverter.ChangeType <string>(key);
                    Traverse(keyValue, key, visitor, context, path);
                    Traverse(keyValue, value, visitor, context, path);
                }
            }

            visitor.VisitMappingEnd(dictionary, context);
        }
Пример #15
0
        protected virtual void TraverseDictionary <TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor <TContext> visitor, Type keyType, Type valueType, TContext context, Stack <ObjectPathSegment> path)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);

            var isDynamic = dictionary.Type.FullName !.Equals("System.Dynamic.ExpandoObject");

#pragma warning disable CS8605 // Unboxing a possibly null value. Iterating IDictionary should not return nulls.
            foreach (DictionaryEntry entry in (IDictionary)dictionary.NonNullValue())
#pragma warning restore CS8605 // Unboxing a possibly null value.
            {
                var keyValue = isDynamic ? namingConvention.Apply(entry.Key.ToString() !) : entry.Key;
                var key      = GetObjectDescriptor(keyValue, keyType);
                var value    = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value, context))
                {
                    var keyAsString = TypeConverter.ChangeType <string>(key);
                    Traverse(keyValue, key, visitor, context, path);
                    Traverse(keyValue, value, visitor, context, path);
                }
            }

            visitor.VisitMappingEnd(dictionary, context);
        }
Пример #16
0
 public virtual bool EnterMapping(object key, Type keyType, object value, Type valueType)
 {
     return(nextVisitor.EnterMapping(key, keyType, value, valueType));
 }
 public virtual bool EnterMapping(IObjectDescriptor key, IObjectDescriptor value, IEmitter context)
 {
     return(nextVisitor.EnterMapping(key, value, context));
 }
        protected virtual void TraverseProperties(IObjectDescriptor value, IObjectGraphVisitor visitor, int currentDepth)
        {
            visitor.VisitMappingStart(value, typeof(string), typeof(object));

            foreach (var propertyDescriptor in typeDescriptor.GetProperties(value.Type, value.Value))
            {
                var propertyValue = propertyDescriptor.Read(value.Value);

                if (visitor.EnterMapping(propertyDescriptor, propertyValue))
                {
                    Traverse(new ObjectDescriptor(propertyDescriptor.Name, typeof(string), typeof(string)), visitor, currentDepth);
                    Traverse(propertyValue, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(value);
        }
        protected virtual void TraverseDictionary(IObjectDescriptor dictionary, IObjectGraphVisitor visitor, int currentDepth, Type keyType, Type valueType)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType);

            var isDynamic = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key.ToString();
                var key = GetObjectDescriptor(keyString, keyType);
                var value = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value))
                {
                    Traverse(key, visitor, currentDepth);
                    Traverse(value, visitor, currentDepth);
                }
            }

            visitor.VisitMappingEnd(dictionary);
        }