Esempio n. 1
0
        /// <summary>
        /// generate object this will ignore properties is not in select nodes
        /// </summary>
        /// <param name="currentData"></param>
        /// <param name="selectNode"></param>
        /// <returns></returns>
        private object GenerateObject(object currentData, SelectNode selectNode)
        {
            if (selectNode == null || currentData == null || GeneratedObjects.Contains(currentData))
            {
                return(currentData);
            }
            else if (currentData is IEnumerable)
            {
                return(GenerateArrayObject(currentData, selectNode));
            }
            GeneratedObjects.Add(currentData);
            Type type = currentData.GetType();

            System.Reflection.PropertyInfo[] properties = type.GetProperties();
            //get list of properties and set default value if that is not in select node
            for (int i = 0; i < properties.Length; i++)
            {
                System.Reflection.PropertyInfo property = properties[i];
                string propertyName = property.Name.ToLower();
                if (selectNode.Properties.TryGetValue(propertyName, out List <SelectNode> nodes))
                {
                    if (nodes == null || nodes.Count == 0)
                    {
                        continue;
                    }
                    object value = property.GetValue(currentData);
                    GenerateObject(value, nodes.FirstOrDefault());
                }
                else
                {
                    property.SetValue(currentData, Shared.Converters.DataExchangeConverter.GetDefault(property.PropertyType));
                }
            }
            return(currentData);
        }
Esempio n. 2
0
        /// <summary>
        /// generate object that is in list
        /// </summary>
        /// <param name="data"></param>
        /// <param name="selectNode"></param>
        /// <returns></returns>
        private object GenerateArrayObject(object data, SelectNode selectNode)
        {
            if (GeneratedObjects.Contains(data))
            {
                return(data);
            }
            GeneratedObjects.Add(data);

            foreach (object item in (IEnumerable)data)
            {
                GenerateObject(item, selectNode);
            }
            return(data);
        }