Exemple #1
0
        static Type P_GenerateRowType(Dictionary <string, int> columnNamesOrder, IComparer <string> columnNameComparer)
        {
            columnNamesOrder.EnsureNotNull(nameof(columnNamesOrder));
            columnNameComparer.EnsureNotNull(nameof(columnNameComparer));
            var columnNamesSorted =
                columnNamesOrder
                .OrderBy(i => i.Key, columnNameComparer)
                .Select(i => i.Key)
                .ToArray();

            if (columnNamesSorted.Length < 1)
            {
                throw new ArgumentException(rt.Format(typeof(Array), "CanNotEmpty"), nameof(columnNamesOrder));
            }
            //
            string typeName;
            Guid   typeSgnatureGuid;

            using (var acquiredBuffer = StringBuilderUtilities.AcquireBuffer()) {
                var sb = acquiredBuffer.StringBuilder;
                for (var i = 0; i < columnNamesSorted.Length; i++)
                {
                    sb.Append('[');
                    sb.Append(columnNamesSorted[i]);
                    sb.Append(']');
                    if (i != columnNamesSorted.Length - 1)
                    {
                        sb.Append(',');
                    }
                }
                var sha1 = default(SHA1);
                try {
#if TRG_NETFRAMEWORK || TRG_SL5
                    sha1 = new SHA1Managed();
#else
                    sha1 = SHA1.Create();
#endif
                    var guidBytes = new byte[16];
                    sha1.Initialize();
                    Array.Copy(sha1.ComputeHash(Encoding.Unicode.GetBytes(sb.ToString())), 0, guidBytes, 0, guidBytes.Length);
                    typeName = "CsvRow_" + (typeSgnatureGuid = new Guid(guidBytes)).ToString("n");
                } finally {
                    (sha1 as IDisposable)?.Dispose();
                }
            }
            Type result;
            if (!__RowTypeRepository.TryGetValue(typeSgnatureGuid, out result))
            {
                Array.Sort(columnNamesSorted, (x, y) => columnNamesOrder[x].CompareTo(columnNamesOrder[y]));
                lock (__RowTypeRepository) {
                    if (!__RowTypeRepository.TryGetValue(typeSgnatureGuid, out result))
                    {
                        __RowTypeRepository.Add(typeSgnatureGuid, result = __RowTypeGenerator.EmitType(typeName, columnNamesSorted));
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public void Sort(int index, int count, IComparer <T> comparer)
        {
            comparer.EnsureNotNull(nameof(comparer));
            index.EnsurePositive(nameof(index));
            count.EnsurePositive(nameof(count));
            (index + count).EnsureInRange(1, Count, $"{nameof(index)} + {nameof(count)}");

            Array.Sort(m_items, index, count, comparer);
            m_version++;
        }