Beispiel #1
0
        /// <summary>
        /// This method will be called after the "CanRead" method returns TRUE. It should be responsible for returning a list of ComplexItem. Each ComplexItem represents an element in the expression.
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the children of the current entity</returns>
        public IEnumerable <ComplexEntity> GetChildren(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            var dyn = (System.Collections.IEnumerable)entity;

            foreach (KeyValuePair <string, object> item in dyn)
            {
                yield return(new DynamicItemEntity(expression, item.Key, item.Value));
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method will be called to retrieve the members (Properties and Fields) of a given entity
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the members of the entity</returns>
        public IEnumerable <ComplexEntity> GetMembers(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            var fields = factory.GetFields(entity);

            foreach (var f in fields)
            {
                yield return(new FieldEntity(expression, entity, f));
            }
        }
Beispiel #3
0
 /// <summary>
 /// This method will be called after the "CanRead" method returns TRUE. It should be responsible for returning a list of ComplexItem. Each ComplexItem represents an element in the expression.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Returns the children of the current entity</returns>
 public IEnumerable <ComplexEntity> GetChildren(ComplexExpressionFactory factory, Expression <object> expression, object entity)
 {
     // read members
     foreach (var memberReader in factory.MemberReaders)
     {
         var items = memberReader.GetMembers(factory, expression, entity);
         foreach (var item in items)
         {
             yield return(item);
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// This method will be called to retrieve the members (Properties and Fields) of a given entity
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the members of the entity</returns>
        public IEnumerable <ComplexEntity> GetMembers(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            // get all propertis:
            // 1) ignore indexed (this[...]) with GetIndexParameters > 0
            // 2) ignore properties with only setters
            var properties = factory.GetProperties(entity);

            foreach (var p in properties)
            {
                if (!p.GetIndexParameters().Any() && p.GetGetMethod() != null)
                {
                    yield return(new PropertyEntity(expression, entity, p));
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// This method will be called after the "CanRead" method returns TRUE. It should be responsible for returning a list of ComplexItem. Each ComplexItem represents an element in the expression.
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the children of the current entity</returns>
        public IEnumerable <ComplexEntity> GetChildren(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            var arrayList = (Array)entity;
            var list      = new List <ArrayItemEntity>();

            ReflectionUtils.IterateArrayMultidimensional(arrayList, indices =>
            {
                list.Add(new ArrayItemEntity(expression, indices, arrayList.GetValue(indices)));
            });

            foreach (var i in list)
            {
                yield return(i);
            }
        }
Beispiel #6
0
        /// <summary>
        /// This method will be called after the "CanRead" method returns TRUE. It should be responsible for returning a list of ComplexItem. Each ComplexItem represents an element in the expression.
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the children of the current entity</returns>
        public IEnumerable <ComplexEntity> GetChildren(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            if (entity is IDictionary dic)
            {
                var count = 0;
                foreach (DictionaryEntry entry in dic)
                {
                    yield return(new CollectionItemEntity(expression, count++, entry));
                }

                // read members, it may happen to be an instance of the
                // user that inherits from IDictionary, so you need to read the members.
                foreach (var memberReader in factory.MemberReaders)
                {
                    var items = memberReader.GetMembers(factory, expression, entity);
                    foreach (var item in items)
                    {
                        // Ignore property "Values|Keys" because the values already specify
                        if (item is PropertyEntity property &&
                            (property.Property.Name == "Values" || property.Property.Name == "Keys"))
                        {
                            continue;
                        }

                        yield return(item);
                    }
                }
            }
            else if (entity is DictionaryEntry entry)
            {
                // Read properties: "Key" and "Value"
                foreach (var memberReader in factory.MemberReaders)
                {
                    var items = memberReader.GetMembers(factory, expression, entity);
                    foreach (var item in items)
                    {
                        yield return(item);
                    }
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// This method will be called after the "CanRead" method returns TRUE. It should be responsible for returning a list of ComplexItem. Each ComplexItem represents an element in the expression.
        /// </summary>
        /// <param name="factory">Factory instance that can help in reading</param>
        /// <param name="expression">Expression instance to be used in ComplexItem constructor</param>
        /// <param name="entity">Real entity</param>
        /// <returns>Returns the children of the current entity</returns>
        public IEnumerable <ComplexEntity> GetChildren(ComplexExpressionFactory factory, Expression <object> expression, object entity)
        {
            var list       = (System.Collections.ICollection)entity;
            var enumerator = list.GetEnumerator();
            var count      = 0;

            while (enumerator.MoveNext())
            {
                yield return(new CollectionItemEntity(expression, count++, enumerator.Current));
            }

            // read members, it may happen to be an instance of the
            // user that inherits from IList, so you need to read the members.
            foreach (var memberReader in factory.MemberReaders)
            {
                var items = memberReader.GetMembers(factory, expression, entity);
                foreach (var item in items)
                {
                    yield return(item);
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// This method will determine if the entity can be read, if yes the "GetChildren" method will be called in sequence.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Return TRUE if can read</returns>
 public bool CanRead(ComplexExpressionFactory factory, object entity)
 {
     return(entity is System.Collections.ICollection);
 }
Beispiel #9
0
 /// <summary>
 /// This method will determine if the entity can be read, if yes the "GetChildren" method will be called in sequence.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Return TRUE if can read</returns>
 public bool CanRead(ComplexExpressionFactory factory, object entity)
 {
     return(!ReflectionUtils.IsSystemType(entity.GetType()));
 }
Beispiel #10
0
 /// <summary>
 /// This method will determine if the entity can be read, if yes the "GetChildren" method will be called in sequence.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Return TRUE if can read</returns>
 public bool CanRead(ComplexExpressionFactory factory, object entity)
 {
     return(entity is IDictionary || entity is DictionaryEntry);
 }
Beispiel #11
0
 /// <summary>
 /// This method will determine if the entity can be read, if yes the "GetChildren" method will be called in sequence.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Return TRUE if can read</returns>
 public bool CanRead(ComplexExpressionFactory factory, object entity)
 {
     return(entity is Array);
 }
Beispiel #12
0
 /// <summary>
 /// This method will determine if the entity can be read, if yes the "GetChildren" method will be called in sequence.
 /// </summary>
 /// <param name="factory">Factory instance that can help in reading</param>
 /// <param name="entity">Real entity</param>
 /// <returns>Return TRUE if can read</returns>
 public bool CanRead(ComplexExpressionFactory factory, object entity)
 {
     return(entity is System.Dynamic.ExpandoObject);
 }