Esempio n. 1
0
 static void Main()
 {
     var ints = new EnumerableCollection <int>(new[] { 1, 2, 3, 4 });
     IEnumerator <int> enumerator = ints.GetEnumerator(true);
     // Получить ссылку на поле synchronized
     // Note: исключение object field = enumerator.GetType().GetField("synchronized").GetValue(enumerator);
 }
Esempio n. 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            CollectionEntry entry = (CollectionEntry)PropertyUtility.GetTargetObjectOfProperty(property);

            SerializedProperty    idProperty = property.FindPropertyRelative("field");
            CollectionInformation info       = EnumerableCollection.GetReflectionInformation(entry.IndexType);

            string[] names = info.fieldNames;

            int currentIndex = -1;

            for (int i = 0; i < names.Length; i++)
            {
                if (names[i] == idProperty.stringValue)
                {
                    currentIndex = i;
                    break;
                }
            }
            if (currentIndex == -1)
            {
                currentIndex           = 0;
                idProperty.stringValue = names[EditorGUI.Popup(position, label.text, currentIndex, names)];
                Debug.Log("Assignig default value");
            }

            EditorGUI.BeginChangeCheck();

            idProperty.stringValue = names[EditorGUI.Popup(position, label.text, currentIndex, names)];

            if (EditorGUI.EndChangeCheck())
            {
                entry.entryIndex = -1;
            }
        }
        public void When_CopyToTooSmallArray_Expect_ArgumentOutOfRangeException()
        {
            var input = new[] { "a", "b", "c" };
            var enumerableCollection = new EnumerableCollection <string>(input, input.Length);
            var output = new string[2];

            Assert.Throws <ArgumentOutOfRangeException>(() => { enumerableCollection.CopyTo(output, 0); });
        }
        public void When_CopyToArray_Expect_OutputEqualToInput()
        {
            var input = new[] { "a", "b", "c" };
            var enumerableCollection = new EnumerableCollection <string>(input, input.Length);
            var output = new string[3];

            enumerableCollection.CopyTo(output, 0);
            Assert.Equal(input, output);
        }
        /// <summary>
        /// Gets a collection that does not implement IList or INotifyCollectionChanged
        /// </summary>
        /// <returns>Generated collection of items</returns>
        public static EnumerableCollection<TestClass> GetEnumerableCollection()
        {
            EnumerableCollection<TestClass> collection = new EnumerableCollection<TestClass>();
            for (int i = 0; i < 25; i++)
            {
                collection.Add(GetTestClassInstance(i));
            }

            return collection;
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            object[] attributeObjects = fieldInfo.GetCustomAttributes(typeof(CollectionTypeAttribute), true);

            if (attributeObjects.Length == 0)
            {
                EditorGUI.HelpBox(position, "There are no " + typeof(CollectionEntry).Name + "'s on \"" +
                                  fieldInfo.Name + "\".", MessageType.None);
                return;
            }

            CollectionTypeAttribute collectionAttribute = (CollectionTypeAttribute)attributeObjects[0];

            SerializedProperty idProperty = property.FindPropertyRelative("field");

            CollectionInformation info = EnumerableCollection.GetReflectionInformation(
                collectionAttribute.collectionType);

            string[] names = info.fieldNames;

            int currentIndex = 0;

            for (int i = 0; i < names.Length; i++)
            {
                if (names[i] == idProperty.stringValue)
                {
                    currentIndex = i;
                    break;
                }
            }

            EditorGUI.BeginChangeCheck();

            idProperty.stringValue = names[EditorGUI.Popup(position, label.text, currentIndex, names)];

            if (EditorGUI.EndChangeCheck())
            {
                CollectionEntry entry = (CollectionEntry)PropertyUtility.GetTargetObjectOfProperty(property);

                entry.entryIndex = -1;
            }
        }
Esempio n. 7
0
        private T[] FindAllSockets <T> ()
            where T : Socket
        {
            List <T> foundObjects = new List <T> ();

            for (int i = 0; i < CollectionFields.Length; i++)
            {
                FieldInfo targetField = CollectionFields[i];

                if (typeof(T).IsAssignableFrom(targetField.FieldType))
                {
                    T childSocket = (T)targetField.GetValue(this);
                    if (childSocket == null)
                    {
                        childSocket = (T)Activator.CreateInstance(targetField.FieldType);
                        targetField.SetValue(this, childSocket);
                    }
                    childSocket.SocketName = targetField.Name;
                    childSocket.ParentNode = this;
                    foundObjects.Add(childSocket);
                }
                else if (typeof(IEnumerable <T>).IsAssignableFrom(targetField.FieldType))
                {
                    IEnumerable <T> childCollection = (IEnumerable <T>)targetField.GetValue(this);
                    if (childCollection == null)
                    {
                        if (childCollection == null)
                        {
                            continue;
                        }
                    }
                    foreach (var childSocket in childCollection)
                    {
                        if (childSocket == null)
                        {
                            continue;
                        }

                        childSocket.SocketName = targetField.Name;
                        childSocket.ParentNode = this;
                        foundObjects.Add(childSocket);
                    }
                }
                else if (typeof(EnumerableCollection <T>).IsAssignableFrom(targetField.FieldType))
                {
                    if (!typeof(T).IsAssignableFrom(targetField.FieldType.BaseType.GetGenericArguments()[0]))
                    {
                        continue;
                    }

                    EnumerableCollection <T> enumer = (EnumerableCollection <T>)targetField.GetValue(this);

                    if (enumer == null)
                    {
                        continue;
                    }

                    foreach (object child in enumer)
                    {
                        if (child == null)
                        {
                            continue;
                        }

                        if (typeof(T).IsAssignableFrom(child.GetType()))
                        {
                            T childSocket = (T)child;

                            if (childSocket == null)
                            {
                                childSocket = (T)Activator.CreateInstance(targetField.FieldType);
                                targetField.SetValue(this, childSocket);
                            }

                            childSocket.SocketName = targetField.Name;
                            childSocket.ParentNode = this;
                            foundObjects.Add(childSocket);
                        }
                    }
                }
            }

            return(foundObjects.ToArray());
        }
Esempio n. 8
0
 /// <summary>
 /// Enumerates the possible values of the domain of this instance/variable.
 /// </summary>
 /// <returns>A <see cref="T:IEnumerable`1"/> containing all the possible values of the domain.</returns>
 public override IEnumerable <int> EnumerateDomain()
 {
     return(EnumerableCollection.RangeEnumerable(this.Length));
 }
Esempio n. 9
0
        private T[] FindAllSockets <T> ()
            where T : Socket
        {
            List <T>       foundObjects = new List <T> ();
            Stack <string> socketPath   = new Stack <string> ();

            for (int i = 0; i < CollectionFields.Length; i++)
            {
                FieldInfo targetField = CollectionFields[i];
                socketPath.Push(targetField.Name);

                if (typeof(T).IsAssignableFrom(targetField.FieldType))
                {
                    T childSocket = (T)targetField.GetValue(this);
                    if (childSocket == null)
                    {
                        childSocket = (T)Activator.CreateInstance(targetField.FieldType);
                        targetField.SetValue(this, childSocket);
                    }
                    childSocket.SocketPath = string.Join(".", socketPath.Reverse());
                    childSocket.ParentNode = this;
                    foundObjects.Add(childSocket);
                }
                else if (typeof(EnumerableCollection).IsAssignableFrom(targetField.FieldType))
                {
                    if (!typeof(T).IsAssignableFrom(targetField.FieldType.BaseType.GetGenericArguments()[0]))
                    {
                        continue;
                    }

                    EnumerableCollection enumer = (EnumerableCollection)targetField.GetValue(this);

                    if (enumer == null)
                    {
                        continue;
                    }

                    foreach (var child in enumer.FindAllRoutes())
                    {
                        object childObject = child.Member.GetValue(child.Target);

                        if (childObject == null)
                        {
                            childObject = (T)Activator.CreateInstance(targetField.FieldType);
                            targetField.SetValue(this, childObject);
                        }

                        if (typeof(T).IsAssignableFrom(childObject.GetType()))
                        {
                            T childSocket = (T)childObject;

                            socketPath.Push(child.Member.Name);
                            childSocket.SocketPath = string.Join(".", socketPath.Reverse());
                            socketPath.Pop();

                            childSocket.ParentNode = this;
                            foundObjects.Add(childSocket);
                        }
                    }
                }
                else if (typeof(IEnumerable <T>).IsAssignableFrom(targetField.FieldType))
                {
                    IEnumerable <T> childCollection = (IEnumerable <T>)targetField.GetValue(this);
                    if (childCollection == null)
                    {
                        continue;
                    }

                    foreach (var childSocket in childCollection)
                    {
                        if (childSocket == null)
                        {
                            continue;
                        }

                        childSocket.SocketPath = string.Join(".", socketPath.Reverse());
                        childSocket.ParentNode = this;
                        foundObjects.Add(childSocket);
                    }
                }
                socketPath.Pop();
            }

            return(foundObjects.ToArray());
        }