Beispiel #1
0
 public WhenWeViolateFlagLimit()
 {
     x = new EnumerationFlags(StatesSample.One)
     {
         AllowMultipleSelections = false
     };
 }
Beispiel #2
0
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            System.Collections.IEnumerator rator = null;
            switch (flags)
            {
            case EnumerationFlags.Forward:
                rator = new Enumerator(this);
                break;

            case EnumerationFlags.Reverse:
                rator = new ReverseEnumerator(this);
                break;

            case EnumerationFlags.ForwardPosition:
                rator = new PostionEnumerator(this);
                break;

            case EnumerationFlags.ReversePosition:
                rator = new ReversePostionEnumerator(this);
                break;

            default:
                rator = new Enumerator(this);
                break;
            }
            flags = 0;
            return(rator);
        }
Beispiel #3
0
            public void ItShouldWork()
            {
                var x    = new EnumerationFlags(StatesSample.One);
                var json = JsonConvert.SerializeObject(x);
                var y    = JsonConvert.DeserializeObject <EnumerationFlags>(json);

                Assert.True(y.HasFlag(StatesSample.One));
            }
Beispiel #4
0
            public void ItShouldWork()
            {
                var x = new EnumerationFlags(StatesSample.One);

                x.AddFlag(StatesSample.Three);
                var json = JsonConvert.SerializeObject(x);
                var y    = JsonConvert.DeserializeObject <EnumerationFlags>(json);

                Assert.Equal(2, y.SelectedKeys.Count);
                Assert.Equal(StatesSample.Three, StatesSample.GetInstanceFromKey(y.SelectedKeys.Last()));
            }
Beispiel #5
0
 /// <summary>
 /// Removes a object at a specified index
 /// </summary>
 /// <param name="index">the index to remove</param>
 public virtual void RemoveAt(int index)
 {
     if (index * 2 > count)
     {
         flags = EnumerationFlags.ReversePosition;
         index = count - index - 1;
     }
     else
     {
         flags = EnumerationFlags.ForwardPosition;
     }
     foreach (IPosition pos in this as System.Collections.ICollection)
     {
         if (index-- == 0)
         {
             Remove(pos);
             return;
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// Inserts an object at a specified index
        /// </summary>
        /// <param name="index">the index to insert the object</param>
        /// <param name="obj">the object to insert</param>
        public virtual void Insert(int index, T obj)
        {
            if (index * 2 > count)
            {
                flags = EnumerationFlags.ReversePosition;
                index = count - index - 1;
            }
            else
            {
                flags = EnumerationFlags.ForwardPosition;
            }
            foreach (Position pos in this as System.Collections.ICollection)
            {
                if (index-- == 0)
                {
                    version++;
                    count++;

                    Position p = new Position();
                    p.prev      = pos;
                    p.next      = pos.next;
                    p.prev.next = p;
                    pos.prev    = p;
                    p.data      = obj;

                    Type t = obj.GetType();

                    if (keytype == null)
                    {
                        keytype = t;
                    }
                    else if (keytype != t)
                    {
                        Debug.Fail("Invalid condition");
                    }
                    reversemapping.Add(obj, p);

                    return;
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns an enumerator for the list
        /// </summary>
        /// <returns>the enumerator</returns>
        public virtual IEnumerator <T> GetEnumerator()
        {
            IEnumerator <T> rator = null;

            switch (flags)
            {
            case EnumerationFlags.Forward:
                rator = new Enumerator(this);
                break;

            case EnumerationFlags.Reverse:
                rator = new ReverseEnumerator(this);
                break;

            default:
                rator = new Enumerator(this);
                break;
            }
            flags = 0;
            return(rator);
        }
Beispiel #8
0
 static bool CryptEnumerateContainerNames(ProviderHandle providerHandle, byte[] containerName, ref int containerNameLength_Bytes, EnumerationFlags flags)
 {
     return(CryptGetProvParam(providerHandle, CryptGetProvParamParameterTypes.PP_ENUMCONTAINERS, containerName, ref containerNameLength_Bytes, (uint)flags));
 }
Beispiel #9
0
 public WhenWeCreateAFlaggedState()
 {
     x = new EnumerationFlags(StatesSample.One);
 }
Beispiel #10
0
 public WhenWeAddASecondState()
 {
     x = new EnumerationFlags(StatesSample.One);
     x.AddFlag(StatesSample.Two);
 }
Beispiel #11
0
 public WhenWeRemoveAState()
 {
     x = new EnumerationFlags(StatesSample.One);
     x.AddFlag(StatesSample.Two);
     x.RemoveFlag(StatesSample.One);
 }
Beispiel #12
0
            public void ItShouldNotThrowAnError()
            {
                var x = new EnumerationFlags(StatesSample.One);

                x.RemoveFlag(StatesSample.One);
            }
Beispiel #13
0
        /// <summary>
        /// Enumerate the children.
        /// Do not use this method in performance critical code. Makes garbadge !
        /// </summary>
        /// <param name="enumerationFlags">The enumeration flags.</param>
        /// <returns></returns>
        public IEnumerable<MyEntity> EnumChildren(EnumerationFlags enumerationFlags = EnumerationFlags.None)
        {
            for (int i = 0; i < this.m_children.Count; i++)
            {
                var child = this.m_children[i];

                yield return child;

                if ((enumerationFlags & EnumerationFlags.Hierarchically) != 0)
                {
                    foreach (var subChild in child.EnumChildren(enumerationFlags))
                    {
                        yield return subChild;
                    }
                }
            }
        }