示例#1
0
文件: Utils.cs 项目: exxeleron/qXL
        //-------------------------------------------------------------------//
        /// <summary>
        ///     Searches for the longest array in a dictionary.
        /// </summary>
        /// <param name="dict">dictionary</param>
        /// <returns>length of longest array within the dictionary</returns>
        public static int GetMaxDictSize(QDictionary dict)
        {
            var maxLen = -1;
            foreach (var array in from QDictionary.KeyValuePair kv in dict select kv.Value as Array)
            {
                if (array != null)
                {
                    var type = array.GetType().Name.ToLower();
                    if (!type.Equals("char[]"))
                    {
                        if (array.GetValue(array.GetLowerBound(0)) is Array)
                            throw new ConversionException(
                                "Cannot handle nested multidimensional arrays as a dictionary value");

                        maxLen = (maxLen < array.Length) ? (array.Length) : maxLen;
                    }
                    else
                    {
                        maxLen = (maxLen < 1) ? 1 : maxLen;
                    }
                }
                else
                {
                    maxLen = (maxLen < 1) ? 1 : maxLen;
                }
            }
            return maxLen;
        }
示例#2
0
        /// <summary>
        ///     Determines whether the specified QDictionary is equal to the current QDictionary.
        /// </summary>
        /// <param name="d">The QDictionary to compare with the current QDictionary.</param>
        /// <returns>true if the specified QDictionary is equal to the current QDictionary; otherwise, false</returns>
        public bool Equals(QDictionary d)
        {
            if (d == null)
            {
                return(false);
            }

            if (_areValuesArray)
            {
                return(Utils.ArrayEquals(Keys, d.Keys) && Utils.ArrayEquals(Values as Array, d.Values as Array));
            }
            var qTable = Values as QTable;

            return(qTable != null && (Utils.ArrayEquals(Keys, d.Keys) && qTable.Equals(d.Values)));
        }
示例#3
0
 //-------------------------------------------------------------------//
 private static object[,] QDict2Excel(QDictionary dict)
 {
     try
     {
         var len = Utils.GetMaxDictSize(dict);
         var res = new object[len + 1, dict.Keys.Length];
         var keyCounter = 0;
         foreach (QDictionary.KeyValuePair kv in dict)
         {
             var k = Convert2Excel(kv.Key);
             if (k is Array)
             {
                 k =
                     (from object x in ((Array) k) where x != null select x).Aggregate("",
                         (current, x) => current + (" " + x)).Trim();
             }
             res[0, keyCounter] = k; //kv.Key.ToString();
             var array = kv.Value as Array;
             var type = kv.Value.GetType().Name.ToLower();
             if (array != null && !type.Equals("char[]"))
             {
                 for (var i = 0; i < array.Length; i++)
                 {
                     res[i + 1, keyCounter] = Convert2Excel(array.GetValue(i));
                 }
                 if (array.Length + 1 < res.GetLength(0))
                 {
                     for (var i = array.Length; i < res.GetLength(0) - 1; i++)
                     {
                         res[i + 1, keyCounter] = ""; // remove null elements
                     }
                 }
             }
             else
             {
                 res[1, keyCounter] = Convert2Excel(kv.Value);
                 if (1 < res.GetLength(0))
                 {
                     for (var i = 1; i < res.GetLength(0) - 1; i++)
                     {
                         res[i + 1, keyCounter] = ""; // remove null elements
                     }
                 }
             }
             keyCounter++;
         }
         return res;
     }
     catch (ConversionException e)
     {
         return new object[,] {{e.Message}};
     }
 }
示例#4
0
 private void WriteDictionary(QDictionary d)
 {
     _writer.Write((sbyte)QType.Dictionary);
     WriteObject(d.Keys);
     WriteObject(d.Values);
 }
示例#5
0
 public QDictionaryEnumerator(QDictionary dictionary)
 {
     _dictionary = dictionary;
 }
示例#6
0
 /// <summary>
 ///     Initializes a new instance of the KeyValuePair.
 /// </summary>
 public KeyValuePair(QDictionary dictionary, int index)
 {
     _dictionary = dictionary;
     _index = index;
 }
示例#7
0
        /// <summary>
        ///     Determines whether the specified QDictionary is equal to the current QDictionary.
        /// </summary>
        /// <param name="d">The QDictionary to compare with the current QDictionary.</param>
        /// <returns>true if the specified QDictionary is equal to the current QDictionary; otherwise, false</returns>
        public bool Equals(QDictionary d)
        {
            if (d == null)
            {
                return false;
            }

            if (_areValuesArray)
            {
                return Utils.ArrayEquals(Keys, d.Keys) && Utils.ArrayEquals(Values as Array, d.Values as Array);
            }
            var qTable = Values as QTable;
            return qTable != null && (Utils.ArrayEquals(Keys, d.Keys) && qTable.Equals(d.Values));
        }
示例#8
0
 private void WriteDictionary(QDictionary d)
 {
     writer.Write((sbyte)QType.Dictionary);
     WriteObject(d.Keys);
     WriteObject(d.Values);
 }
示例#9
0
 public QDictionaryEnumerator(QDictionary dictionary)
 {
     _dictionary = dictionary;
     _current    = new QDictionary.KeyValuePair(_dictionary, _index);
 }
示例#10
0
 /// <summary>
 ///     Initializes a new instance of the KeyValuePair.
 /// </summary>
 public KeyValuePair(QDictionary dictionary, int index) : this()
 {
     _dictionary = dictionary;
     Index       = index;
 }
示例#11
0
        /// <summary>
        ///     Determines whether the specified QDictionary is equal to the current QDictionary.
        /// </summary>
        /// <param name="d">The QDictionary to compare with the current QDictionary.</param>
        /// <returns>true if the specified QDictionary is equal to the current QDictionary; otherwise, false</returns>
        public bool Equals(QDictionary d)
        {
            if (d == null)
            {
                return false;
            }

            if (areValuesArray)
            {
                return Utils.ArrayEquals(Keys, d.Keys) && Utils.ArrayEquals(Values as Array, d.Values as Array);
            }
            else
            {
                return Utils.ArrayEquals(Keys, d.Keys) && (Values as QTable).Equals(d.Values);
            }
        }