예제 #1
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            if (index >= ChildrenTokens.Count)
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");

            CheckReentrancy();

            JToken item = ChildrenTokens[index];
            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            JToken next = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
                previous.Next = next;
            if (next != null)
                next.Previous = previous;

            item.Parent = null;
            item.Previous = null;
            item.Next = null;

            ChildrenTokens.RemoveAt(index);

#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
            if (_listChanged != null)
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#endif
#if !(NET20 || NET35 || PORTABLE40)
            if (_collectionChanged != null)
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
#endif
        }
예제 #2
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }
            CheckReentrancy();
            JToken jToken  = ChildrenTokens[index];
            JToken jToken2 = ((index == 0) ? null : ChildrenTokens[index - 1]);
            JToken jToken3 = ((index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1]);

            if (jToken2 != null)
            {
                jToken2.Next = jToken3;
            }
            if (jToken3 != null)
            {
                jToken3.Previous = jToken2;
            }
            jToken.Parent   = null;
            jToken.Previous = null;
            jToken.Next     = null;
            ChildrenTokens.RemoveAt(index);
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
        }
예제 #3
0
        internal virtual void InsertItem(int index, JToken item)
        {
            if (index > ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index must be within the bounds of the List.");
            }

            CheckReentrancy();

            item = EnsureParentToken(item);

            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            // haven't inserted new token yet so next token is still at the inserting index
            JToken next = (index == ChildrenTokens.Count) ? null : ChildrenTokens[index];

            ValidateToken(item, null);

            item.Parent = this;

            item.Previous = previous;
            if (previous != null)
            {
                previous.Next = item;
            }

            item.Next = next;
            if (next != null)
            {
                next.Previous = item;
            }

            ChildrenTokens.Insert(index, item);
        }
예제 #4
0
        internal virtual void InsertItem(int index, JToken item)
        {
            if (index > ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index must be within the bounds of the List.");
            }
            CheckReentrancy();
            item = EnsureParentToken(item);
            JToken jToken  = ((index == 0) ? null : ChildrenTokens[index - 1]);
            JToken jToken2 = ((index == ChildrenTokens.Count) ? null : ChildrenTokens[index]);

            ValidateToken(item, null);
            item.Parent   = this;
            item.Previous = jToken;
            if (jToken != null)
            {
                jToken.Next = item;
            }
            item.Next = jToken2;
            if (jToken2 != null)
            {
                jToken2.Previous = item;
            }
            ChildrenTokens.Insert(index, item);
            if (this.ListChanged != null)
            {
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
            }
        }
예제 #5
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();

#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
            if (_listChanged != null)
            {
                OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
            }
#endif
#if !(NET20 || NET35 || PORTABLE40)
            if (_collectionChanged != null)
            {
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
#endif
        }
예제 #6
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }

            CheckReentrancy();

            JToken item     = ChildrenTokens[index];
            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            JToken next     = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
            {
                previous.Next = next;
            }
            if (next != null)
            {
                next.Previous = previous;
            }

            item.Parent   = null;
            item.Previous = null;
            item.Next     = null;

            ChildrenTokens.RemoveAt(index);
        }
예제 #7
0
 internal virtual void ClearItems()
 {
     CheckReentrancy();
     foreach (JToken childrenToken in ChildrenTokens)
     {
         childrenToken.Parent   = null;
         childrenToken.Previous = null;
         childrenToken.Next     = null;
     }
     ChildrenTokens.Clear();
     OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
 }
예제 #8
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();
        }
예제 #9
0
        private HomePageViewModel GetHomePageViewModel(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                url = "https://swapi.dev/api/people/";
            }

            WebRequest  request  = WebRequest.Create(url);
            WebResponse response = request.GetResponse();

            string json = string.Empty;

            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                json = reader.ReadToEnd();
            }

            ModelState.Remove("Previous");
            ModelState.Remove("Next");

            ChildrenTokens tokens = JsonConvert.DeserializeObject <ChildrenTokens>(json);

            HomePageViewModel viewModel = new HomePageViewModel
            {
                Next     = tokens.next,
                Previous = tokens.previous,
                People   = new List <PersonViewModel>()
            };

            foreach (object result in tokens.results)
            {
                Person person = JsonConvert.DeserializeObject <Person>(result.ToString());

                person.film_count = JsonConvert.DeserializeObject <ChildrenTokens>(result.ToString()).films.Count;

                viewModel.People.Add(new PersonViewModel
                {
                    Name      = person.name,
                    BirthYear = person.birth_year,
                    Mass      = person.mass,
                    Height    = person.height,
                    FilmCount = person.film_count.ToString(),
                    EyeColor  = person.eye_color.Substring(0, 1).ToUpper() + person.eye_color.Substring(1, person.eye_color.Length - 1)
                });
            }

            return(viewModel);
        }
예제 #10
0
        internal virtual void InsertItem(int index, JToken item, bool skipParentCheck)
        {
            if (index > ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index must be within the bounds of the List.");
            }

            CheckReentrancy();

            item = EnsureParentToken(item, skipParentCheck);

            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            // haven't inserted new token yet so next token is still at the inserting index
            JToken next = (index == ChildrenTokens.Count) ? null : ChildrenTokens[index];

            ValidateToken(item, null);

            item.Parent = this;

            item.Previous = previous;
            if (previous != null)
            {
                previous.Next = item;
            }

            item.Next = next;
            if (next != null)
            {
                next.Previous = item;
            }

            ChildrenTokens.Insert(index, item);

#if !(NETFX_CORE || PORTABLE40 || PORTABLE)
            if (_listChanged != null)
            {
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
            }
#endif
#if !(NET20 || NET35 || PORTABLE40)
            if (_collectionChanged != null)
            {
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
            }
#endif
        }
예제 #11
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();

#if !UNITY_IOS
            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
#endif
        }
예제 #12
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();

#if !(UNITY_ANDROID || (UNITY_IOS || UNITY_IPHONE) || (UNITY_WP8 || UNITY_WP_8_1) || (UNITY_WINRT && !UNITY_EDITOR))
            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
#endif
        }
예제 #13
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();

            if (_collectionChanged != null)
            {
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
예제 #14
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }

            CheckReentrancy();

            JToken item     = ChildrenTokens[index];
            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            JToken next     = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
            {
                previous.Next = next;
            }
            if (next != null)
            {
                next.Previous = previous;
            }

            item.Parent   = null;
            item.Previous = null;
            item.Next     = null;

            //IList implementation is broken on Web Player (Unity Bug) and RemoveAt will not remove the item
#if !UNITY_WEBPLAYER
            ChildrenTokens.RemoveAt(index);
#else
            if (ChildrenTokens is JObject.JPropertKeyedCollection)
            {
                (ChildrenTokens as JObject.JPropertKeyedCollection).RemoveItemAt(index);
            }
#endif

#if !(UNITY_ANDROID || (UNITY_IOS || UNITY_IPHONE) || (UNITY_WP8 || UNITY_WP_8_1) || (UNITY_WINRT && !UNITY_EDITOR))
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#endif
        }
예제 #15
0
        internal virtual void ClearItems()
        {
            CheckReentrancy();

            foreach (JToken item in ChildrenTokens)
            {
                item.Parent   = null;
                item.Previous = null;
                item.Next     = null;
            }

            ChildrenTokens.Clear();

#if !SILVERLIGHT
            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
#endif
#if SILVERLIGHT || !(NET20 || NET35)
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
#endif
        }
예제 #16
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }

            CheckReentrancy();

            var item     = ChildrenTokens[index];
            var previous = (index == 0) ? null : ChildrenTokens[index - 1];
            var next     = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
            {
                previous.Next = next;
            }
            if (next != null)
            {
                next.Previous = previous;
            }

            item.Parent   = null;
            item.Previous = null;
            item.Next     = null;

            ChildrenTokens.RemoveAt(index);

            if (_listChanged != null)
            {
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
            }
            if (_collectionChanged != null)
            {
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
            }
        }
예제 #17
0
        internal virtual void InsertItem(int index, JToken item)
        {
            if (index > ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index must be within the bounds of the List.");
            }

            CheckReentrancy();

            item = EnsureParentToken(item);

            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            // haven't inserted new token yet so next token is still at the inserting index
            JToken next = (index == ChildrenTokens.Count) ? null : ChildrenTokens[index];

            ValidateToken(item, null);

            item.Parent = this;

            item.Previous = previous;
            if (previous != null)
            {
                previous.Next = item;
            }

            item.Next = next;
            if (next != null)
            {
                next.Previous = item;
            }

            ChildrenTokens.Insert(index, item);

#if !(UNITY_ANDROID || (UNITY_IOS || UNITY_IPHONE) || (UNITY_WP8 || UNITY_WP_8_1) || (UNITY_WINRT && !UNITY_EDITOR))
            if (ListChanged != null)
            {
                OnListChanged(new ListChangedEventArgs(ListChangedType.ItemAdded, index));
            }
#endif
        }
예제 #18
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }

            CheckReentrancy();

            JToken item     = ChildrenTokens[index];
            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            JToken next     = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
            {
                previous.Next = next;
            }
            if (next != null)
            {
                next.Previous = previous;
            }

            item.Parent   = null;
            item.Previous = null;
            item.Next     = null;

            ChildrenTokens.RemoveAt(index);

#if !(SILVERLIGHT || MONODROID || MONOTOUCH)
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#endif
#if !MONOTOUCH && SILVERLIGHT || !(NET20 || NET35)
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
#endif
        }
예제 #19
0
        internal virtual void RemoveItemAt(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "Index is less than 0.");
            }
            if (index >= ChildrenTokens.Count)
            {
                throw new ArgumentOutOfRangeException("index", "Index is equal to or greater than Count.");
            }

            CheckReentrancy();

            JToken item     = ChildrenTokens[index];
            JToken previous = (index == 0) ? null : ChildrenTokens[index - 1];
            JToken next     = (index == ChildrenTokens.Count - 1) ? null : ChildrenTokens[index + 1];

            if (previous != null)
            {
                previous.Next = next;
            }
            if (next != null)
            {
                next.Previous = previous;
            }

            item.Parent   = null;
            item.Previous = null;
            item.Next     = null;

            ChildrenTokens.RemoveAt(index);

#if !(UNITY_ANDROID || (UNITY_IOS || UNITY_IPHONE) || UNITY_WP8 || (UNITY_WINRT && !UNITY_EDITOR))
            OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
#endif
        }
예제 #20
0
 /// <summary>
 /// Gets an <see cref="IEnumerable{JProperty}"/> of this object's properties.
 /// </summary>
 /// <returns>An <see cref="IEnumerable{JProperty}"/> of this object's properties.</returns>
 public IEnumerable <JProperty> Properties()
 {
     return(ChildrenTokens.Cast <JProperty>());
 }
예제 #21
0
 internal int IndexOfItem(JToken item)
 {
     return(ChildrenTokens.IndexOf(item, JTokenReferenceEqualityComparer.Instance));
 }
예제 #22
0
 /// <summary>
 /// Returns a collection of the child values of this token, in document order.
 /// </summary>
 /// <typeparam name="T">The type to convert the values to.</typeparam>
 /// <returns>
 /// A <see cref="IEnumerable{T}"/> containing the child values of this <see cref="JToken"/>, in document order.
 /// </returns>
 public override IEnumerable <T> Values <T>()
 {
     return(ChildrenTokens.Convert <JToken, T>());
 }