예제 #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);
        }
예제 #2
0
 /// <summary>
 /// run select query on your object and filter it to new query
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public object Run(object data)
 {
     try
     {
         return(GenerateObject(data, CompilerSelectNodes.FirstOrDefault()));
     }
     finally
     {
         GeneratedObjects.Clear();
     }
 }
예제 #3
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);
        }
예제 #4
0
    public override void Generate()
    {
        Vector3[] copyPositions = CalculatePositions();

        if (copyPositions.Length > 0)
        {
            transform.position = copyPositions [0];

            for (int i = 1; i < copyPositions.Length; i++)
            {
                GameObject copy = GameObject.Instantiate(gameObject);
                //Array needs to be removed, since the copies are not under control of the Generator yet to handle removal
                DestroyImmediate(copy.GetComponent <MultiplyingProperty> ());
                copy.transform.position = copyPositions [i];
                copy.transform.SetParent(gameObject.transform.parent);
                GeneratedObjects.Add(copy);
            }
        }
    }