Exemplo n.º 1
0
        // Helper method for sorting an ArrayList.  If the comparer is a SortFieldComparer,
        // use the cached-value approach to avoid excessive reflection.  For other
        // comparers, sort the usual way
        internal static void SortHelper(ArrayList al, IComparer comparer)
        {
            SortFieldComparer sfc = comparer as SortFieldComparer;

            if (sfc == null)
            {
                // sort the usual way
                al.Sort(comparer);
            }
            else
            {
                // Sort with cached values.
                // Step 1.  Copy the items into a list augmented with slots for
                // the cached values.
                int n                  = al.Count;
                int nFields            = sfc._fields.Length;
                CachedValueItem[] list = new CachedValueItem[n];
                for (int i = 0; i < n; ++i)
                {
                    list[i].Initialize(al[i], nFields);
                }

                // Step 2. Sort the augmented list.  The SortFieldComparer will
                // fill in the slots as necessary to perform its comparisons.
                Array.Sort(list, sfc);

                // Step 3. Copy the items back into the original list, now in
                // sorted order
                for (int i = 0; i < n; ++i)
                {
                    al[i] = list[i].OriginalItem;
                }
            }
        }
Exemplo n.º 2
0
            object GetValueFromCVI(CachedValueItem cvi)
            {
                object value = cvi[index];

                if (value == DependencyProperty.UnsetValue)
                {
                    // first query for this value.  Compute it and cache it.
                    value = cvi[index] = GetValueCore(cvi.OriginalItem);
                }

                return(value);
            }
Exemplo n.º 3
0
        // Helper method for sorting an ArrayList.  If the comparer is a SortFieldComparer,
        // use the cached-value approach to avoid excessive reflection.  For other 
        // comparers, sort the usual way
        internal static void SortHelper(ArrayList al, IComparer comparer)
        {
            SortFieldComparer sfc = comparer as SortFieldComparer; 
            if (sfc == null)
            { 
                // sort the usual way 
                al.Sort(comparer);
            } 
            else
            {
                // Sort with cached values.
                // Step 1.  Copy the items into a list augmented with slots for 
                // the cached values.
                int n = al.Count; 
                int nFields = sfc._fields.Length; 
                CachedValueItem[] list = new CachedValueItem[n];
                for (int i=0; i<n; ++i) 
                {
                    list[i].Initialize(al[i], nFields);
                }
 
                // Step 2. Sort the augmented list.  The SortFieldComparer will
                // fill in the slots as necessary to perform its comparisons. 
                Array.Sort(list, sfc); 

                // Step 3. Copy the items back into the original list, now in 
                // sorted order
                for (int i=0; i<n; ++i)
                {
                    al[i] = list[i].OriginalItem; 
                }
            } 
        } 
Exemplo n.º 4
0
            object GetValueFromCVI(CachedValueItem cvi)
            {
                object value = cvi[index];
 
                if (value == DependencyProperty.UnsetValue)
                { 
                    // first query for this value.  Compute it and cache it. 
                    value = cvi[index] = GetValueCore(cvi.OriginalItem);
                } 

                return value;
            }