找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1352|回复: 1

[分享] CSVReader.cs & StringConverter.cs

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-6-10 17:42:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 csharp 于 2014-6-10 17:58 编辑

  1. /* CSVReader - a simple open source C# class library to read CSV data
  2. * by Andrew Stellman - http://www.stellman-greene.com/CSVReader
  3. *
  4. * CSVReader.cs - Class to read CSV data from a string, file or stream
  5. *
  6. * download the latest version: http://svn.stellman-greene.com/CSVReader
  7. *
  8. * (c) 2008, Stellman & Greene Consulting
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *     * Redistributions of source code must retain the above copyright
  14. *       notice, this list of conditions and the following disclaimer.
  15. *     * Redistributions in binary form must reproduce the above copyright
  16. *       notice, this list of conditions and the following disclaimer in the
  17. *       documentation and/or other materials provided with the distribution.
  18. *     * Neither the name of Stellman & Greene Consulting nor the
  19. *       names of its contributors may be used to endorse or promote products
  20. *       derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY STELLMAN & GREENE CONSULTING ''AS IS'' AND ANY
  23. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL STELLMAN & GREENE CONSULTING BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */

  34. using System;
  35. using System.Collections.Generic;
  36. using System.IO;
  37. using System.Data;
  38. using System.Text;

  39. namespace Com.StellmanGreene.CSVReader
  40. {
  41.     /// <summary>
  42.     /// Read CSV-formatted data from a file or TextReader
  43.     /// </summary>
  44.     public class CSVReader : IDisposable
  45.     {
  46.         public const string NEWLINE = "\r\n";

  47.         /// <summary>
  48.         /// This reader will read all of the CSV data
  49.         /// </summary>
  50.         private BinaryReader reader;

  51.         /// <summary>
  52.         /// The number of rows to scan for types when building a DataTable (0 to scan the whole file)
  53.         /// </summary>
  54.         public int ScanRows = 0;

  55.         #region Constructors

  56.         /// <summary>
  57.         /// Read CSV-formatted data from a file
  58.         /// </summary>
  59.         /// <param name="filename">Name of the CSV file</param>
  60.         public CSVReader(FileInfo csvFileInfo)
  61.         {
  62.             if (csvFileInfo == null)
  63.                 throw new ArgumentNullException("Null FileInfo passed to CSVReader");

  64.             this.reader = new BinaryReader(File.OpenRead(csvFileInfo.FullName));
  65.         }

  66.         /// <summary>
  67.         /// Read CSV-formatted data from a string
  68.         /// </summary>
  69.         /// <param name="csvData">String containing CSV data</param>
  70.         public CSVReader(string csvData)
  71.         {
  72.             if (csvData == null)
  73.                 throw new ArgumentNullException("Null string passed to CSVReader");


  74.             this.reader = new BinaryReader(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(csvData)));
  75.         }

  76.         /// <summary>
  77.         /// Read CSV-formatted data from a TextReader
  78.         /// </summary>
  79.         /// <param name="reader">TextReader that's reading CSV-formatted data</param>
  80.         public CSVReader(TextReader reader)
  81.         {
  82.             if (reader == null)
  83.                 throw new ArgumentNullException("Null TextReader passed to CSVReader");

  84.             this.reader = new BinaryReader(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(reader.ReadToEnd())));
  85.         }

  86.         #endregion



  87.         string currentLine = "";
  88.         /// <summary>
  89.         /// Read the next row from the CSV data
  90.         /// </summary>
  91.         /// <returns>A list of objects read from the row, or null if there is no next row</returns>
  92.         public List<object> ReadRow()
  93.         {
  94.             // ReadLine() will return null if there's no next line
  95.             if (reader.BaseStream.Position >= reader.BaseStream.Length)
  96.                 return null;

  97.             StringBuilder builder = new StringBuilder();

  98.             // Read the next line
  99.             while ((reader.BaseStream.Position < reader.BaseStream.Length) && (!builder.ToString().EndsWith(NEWLINE)))
  100.             {
  101.                 char c = reader.ReadChar();
  102.                 builder.Append(c);
  103.             }

  104.             currentLine = builder.ToString();
  105.             if (currentLine.EndsWith(NEWLINE))
  106.                 currentLine = currentLine.Remove(currentLine.IndexOf(NEWLINE), NEWLINE.Length);

  107.             // Build the list of objects in the line
  108.             List<object> objects = new List<object>();
  109.             while (currentLine != "")
  110.                 objects.Add(ReadNextObject());
  111.             return objects;
  112.         }

  113.         /// <summary>
  114.         /// Read the next object from the currentLine string
  115.         /// </summary>
  116.         /// <returns>The next object in the currentLine string</returns>
  117.         private object ReadNextObject()
  118.         {
  119.             if (currentLine == null)
  120.                 return null;

  121.             // Check to see if the next value is quoted
  122.             bool quoted = false;
  123.             if (currentLine.StartsWith("""))
  124.                 quoted = true;

  125.             // Find the end of the next value
  126.             string nextObjectString = "";
  127.             int i = 0;
  128.             int len = currentLine.Length;
  129.             bool foundEnd = false;
  130.             while (!foundEnd && i <= len)
  131.             {
  132.                 // Check if we've hit the end of the string
  133.                 if ((!quoted && i == len) // non-quoted strings end with a comma or end of line
  134.                     || (!quoted && currentLine.Substring(i, 1) == ",")
  135.                     // quoted strings end with a quote followed by a comma or end of line
  136.                     || (quoted && i == len - 1 && currentLine.EndsWith("""))
  137.                     || (quoted && currentLine.Substring(i, 2) == "","))
  138.                     foundEnd = true;
  139.                 else
  140.                     i++;
  141.             }
  142.             if (quoted)
  143.             {
  144.                 if (i > len || !currentLine.Substring(i, 1).StartsWith("""))
  145.                     throw new FormatException("Invalid CSV format: " + currentLine.Substring(0, i));
  146.                 i++;
  147.             }
  148.             nextObjectString = currentLine.Substring(0, i).Replace("""", """);

  149.             if (i < len)
  150.                 currentLine = currentLine.Substring(i + 1);
  151.             else
  152.                 currentLine = "";

  153.             if (quoted)
  154.             {
  155.                 if (nextObjectString.StartsWith("""))
  156.                     nextObjectString = nextObjectString.Substring(1);
  157.                 if (nextObjectString.EndsWith("""))
  158.                     nextObjectString = nextObjectString.Substring(0, nextObjectString.Length - 1);
  159.                 return nextObjectString;
  160.             }
  161.             else
  162.             {
  163.                 object convertedValue;
  164.                 StringConverter.ConvertString(nextObjectString, out convertedValue);
  165.                 return convertedValue;
  166.             }
  167.         }

  168.         /// <summary>
  169.         /// Read the row data read using repeated ReadRow() calls and build a DataColumnCollection with types and column names
  170.         /// </summary>
  171.         /// <param name="headerRow">True if the first row contains headers</param>
  172.         /// <returns>System.Data.DataTable object populated with the row data</returns>
  173.         public DataTable CreateDataTable(bool headerRow)
  174.         {
  175.             // Read the CSV data into rows
  176.             List<List<object>> rows = new List<List<object>>();
  177.             List<object> readRow = null;
  178.             while ((readRow = ReadRow()) != null)
  179.                 rows.Add(readRow);

  180.             // The types and names (if headerRow is true) will be stored in these lists
  181.             List<Type> columnTypes = new List<Type>();
  182.             List<string> columnNames = new List<string>();

  183.             // Read the column names from the header row (if there is one)
  184.             if (headerRow)
  185.                 foreach (object name in rows[0])
  186.                     columnNames.Add(name.ToString());

  187.             // Read the column types from each row in the list of rows
  188.             bool headerRead = false;
  189.             foreach (List<object> row in rows)
  190.                 if (headerRead || !headerRow)
  191.                     for (int i = 0; i < row.Count; i++)
  192.                         // If we're adding a new column to the columnTypes list, use its type.
  193.                         // Otherwise, find the common type between the one that's there and the new row.
  194.                         if (columnTypes.Count < i + 1)
  195.                             columnTypes.Add(row[i].GetType());
  196.                         else
  197.                             columnTypes[i] = StringConverter.FindCommonType(columnTypes[i], row[i].GetType());
  198.                 else
  199.                     headerRead = true;

  200.             // Create the table and add the columns
  201.             DataTable table = new DataTable();
  202.             for (int i = 0; i < columnTypes.Count; i++)
  203.             {
  204.                 table.Columns.Add();
  205.                 table.Columns[i].DataType = columnTypes[i];
  206.                 if (i < columnNames.Count)
  207.                     table.Columns[i].ColumnName = columnNames[i];
  208.             }

  209.             // Add the data from the rows
  210.             headerRead = false;
  211.             foreach (List<object> row in rows)
  212.                 if (headerRead || !headerRow)
  213.                 {
  214.                     DataRow dataRow = table.NewRow();
  215.                     for (int i = 0; i < row.Count; i++)
  216.                         dataRow[i] = row[i];
  217.                     table.Rows.Add(dataRow);
  218.                 }
  219.                 else
  220.                     headerRead = true;

  221.             return table;
  222.         }

  223.         /// <summary>
  224.         /// Read a CSV file into a table
  225.         /// </summary>
  226.         /// <param name="filename">Filename of CSV file</param>
  227.         /// <param name="headerRow">True if the first row contains column names</param>
  228.         /// <param name="scanRows">The number of rows to scan for types when building a DataTable (0 to scan the whole file)</param>
  229.         /// <returns>System.Data.DataTable object that contains the CSV data</returns>
  230.         public static DataTable ReadCSVFile(string filename, bool headerRow, int scanRows)
  231.         {
  232.             using (CSVReader reader = new CSVReader(new FileInfo(filename)))
  233.             {
  234.                 reader.ScanRows = scanRows;
  235.                 return reader.CreateDataTable(headerRow);
  236.             }
  237.         }

  238.         /// <summary>
  239.         /// Read a CSV file into a table
  240.         /// </summary>
  241.         /// <param name="filename">Filename of CSV file</param>
  242.         /// <param name="headerRow">True if the first row contains column names</param>
  243.         /// <returns>System.Data.DataTable object that contains the CSV data</returns>
  244.         public static DataTable ReadCSVFile(string filename, bool headerRow)
  245.         {
  246.             using (CSVReader reader = new CSVReader(new FileInfo(filename)))
  247.                 return reader.CreateDataTable(headerRow);
  248.         }

  249.         #region IDisposable Members

  250.         public void Dispose()
  251.         {
  252.             if (reader != null)
  253.             {
  254.                 try
  255.                 {
  256.                     // Can't call BinaryReader.Dispose due to its protection level
  257.                     reader.Close();
  258.                 }
  259.                 catch { }
  260.             }
  261.         }

  262.         #endregion
  263.     }
  264. }

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 859个

财富等级: 财运亨通

 楼主| 发表于 2014-6-10 17:56:37 | 显示全部楼层

  1. /* CSVReader - a simple open source C# class library to read CSV data
  2. * by Andrew Stellman - http://www.stellman-greene.com/CSVReader
  3. *
  4. * StringConverter.cs - Class to convert strings to typed objects
  5. *
  6. * download the latest version: http://svn.stellman-greene.com/CSVReader
  7. *
  8. * (c) 2008, Stellman & Greene Consulting
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *     * Redistributions of source code must retain the above copyright
  14. *       notice, this list of conditions and the following disclaimer.
  15. *     * Redistributions in binary form must reproduce the above copyright
  16. *       notice, this list of conditions and the following disclaimer in the
  17. *       documentation and/or other materials provided with the distribution.
  18. *     * Neither the name of Stellman & Greene Consulting nor the
  19. *       names of its contributors may be used to endorse or promote products
  20. *       derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY STELLMAN & GREENE CONSULTING ''AS IS'' AND ANY
  23. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL STELLMAN & GREENE CONSULTING BE LIABLE FOR ANY
  26. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  29. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */

  34. using System;
  35. using System.Collections.Generic;

  36. namespace Com.StellmanGreene.CSVReader
  37. {
  38.     /// <summary>
  39.     /// Static class to convert strings to typed values
  40.     /// </summary>
  41.     public static class StringConverter
  42.     {
  43.         public static Type ConvertString(string value, out object convertedValue)
  44.         {
  45.             // First check the whole number types, because floating point types will always parse whole numbers
  46.             // Start with the smallest types
  47.             byte byteResult;
  48.             if (byte.TryParse(value, out byteResult))
  49.             {
  50.                 convertedValue = byteResult;
  51.                 return typeof(byte);
  52.             }

  53.             short shortResult;
  54.             if (short.TryParse(value, out shortResult))
  55.             {
  56.                 convertedValue = shortResult;
  57.                 return typeof(short);
  58.             }

  59.             int intResult;
  60.             if (int.TryParse(value, out intResult))
  61.             {
  62.                 convertedValue = intResult;
  63.                 return typeof(int);
  64.             }

  65.             long longResult;
  66.             if (long.TryParse(value, out longResult))
  67.             {
  68.                 convertedValue = longResult;
  69.                 return typeof(long);
  70.             }

  71.             ulong ulongResult;
  72.             if (ulong.TryParse(value, out ulongResult))
  73.             {
  74.                 convertedValue = ulongResult;
  75.                 return typeof(ulong);
  76.             }

  77.             // No need to check the rest of the unsigned types, which will fit into the signed whole number types

  78.             // Next check the floating point types
  79.             float floatResult;
  80.             if (float.TryParse(value, out floatResult))
  81.             {
  82.                 convertedValue = floatResult;
  83.                 return typeof(float);
  84.             }


  85.             // It's not clear that there's anything that double.TryParse() and decimal.TryParse() will parse
  86.             // but which float.TryParse() won't
  87.             double doubleResult;
  88.             if (double.TryParse(value, out doubleResult))
  89.             {
  90.                 convertedValue = doubleResult;
  91.                 return typeof(double);
  92.             }

  93.             decimal decimalResult;
  94.             if (decimal.TryParse(value, out decimalResult))
  95.             {
  96.                 convertedValue = decimalResult;
  97.                 return typeof(decimal);
  98.             }

  99.             // It's not a number, so it's either a bool, char or string
  100.             bool boolResult;
  101.             if (bool.TryParse(value, out boolResult))
  102.             {
  103.                 convertedValue = boolResult;
  104.                 return typeof(bool);
  105.             }

  106.             char charResult;
  107.             if (char.TryParse(value, out charResult))
  108.             {
  109.                 convertedValue = charResult;
  110.                 return typeof(char);
  111.             }

  112.             convertedValue = value;
  113.             return typeof(string);
  114.         }

  115.         /// <summary>
  116.         /// Compare two types and find a type that can fit both of them
  117.         /// </summary>
  118.         /// <param name="typeA">First type to compare</param>
  119.         /// <param name="typeB">Second type to compare</param>
  120.         /// <returns>The type that can fit both types, or string if they're incompatible</returns>
  121.         public static Type FindCommonType(Type typeA, Type typeB)
  122.         {
  123.             // Build the singleton type map (which will rebuild it in a typesafe manner
  124.             // if it's not already built).
  125.             BuildTypeMap();

  126.             if (!typeMap.ContainsKey(typeA))
  127.                 return typeof(string);

  128.             if (!typeMap[typeA].ContainsKey(typeB))
  129.                 return typeof(string);

  130.             return typeMap[typeA][typeB];
  131.         }


  132.         // Dictionary to map two types to a common type that can hold both of them
  133.         private static Dictionary<Type, Dictionary<Type, Type>> typeMap = null;

  134.         // Locker object to build the singleton typeMap in a typesafe manner
  135.         private static object locker = new object();

  136.         /// <summary>
  137.         /// Build the singleton type map in a typesafe manner.
  138.         /// This map is a dictionary that maps a pair of types to a common type.
  139.         /// So typeMap[typeof(float)][typeof(uint)] will return float, while
  140.         /// typemap[typeof(char)][typeof(bool)] will return string.
  141.         /// </summary>
  142.         private static void BuildTypeMap()
  143.         {
  144.             lock (locker)
  145.             {
  146.                 if (typeMap == null)
  147.                 {
  148.                     typeMap = new Dictionary<Type, Dictionary<Type, Type>>()
  149.                     {
  150.                         // Comparing byte
  151.                         {typeof(byte), new Dictionary<Type, Type>() {
  152.                             { typeof(byte), typeof(byte) },
  153.                             { typeof(short), typeof(short) },
  154.                             { typeof(int), typeof(int) },
  155.                             { typeof(long), typeof(long) },
  156.                             { typeof(ulong), typeof(ulong) },
  157.                             { typeof(float), typeof(float) },
  158.                             { typeof(double), typeof(double) },
  159.                             { typeof(decimal), typeof(decimal) },
  160.                             { typeof(bool), typeof(string) },
  161.                             { typeof(char), typeof(string) },
  162.                             { typeof(string), typeof(string) },
  163.                         }},

  164.                         // Comparing short
  165.                         {typeof(short), new Dictionary<Type, Type>() {
  166.                             { typeof(byte), typeof(short) },
  167.                             { typeof(short), typeof(short) },
  168.                             { typeof(int), typeof(int) },
  169.                             { typeof(long), typeof(long) },
  170.                             { typeof(ulong), typeof(ulong) },
  171.                             { typeof(float), typeof(float) },
  172.                             { typeof(double), typeof(double) },
  173.                             { typeof(decimal), typeof(decimal) },
  174.                             { typeof(bool), typeof(string) },
  175.                             { typeof(char), typeof(string) },
  176.                             { typeof(string), typeof(string) },
  177.                         }},

  178.                         // Comparing int
  179.                         {typeof(int), new Dictionary<Type, Type>() {
  180.                             { typeof(byte), typeof(int) },
  181.                             { typeof(short), typeof(int) },
  182.                             { typeof(int), typeof(int) },
  183.                             { typeof(long), typeof(long) },
  184.                             { typeof(ulong), typeof(ulong) },
  185.                             { typeof(float), typeof(float) },
  186.                             { typeof(double), typeof(double) },
  187.                             { typeof(decimal), typeof(decimal) },
  188.                             { typeof(bool), typeof(string) },
  189.                             { typeof(char), typeof(string) },
  190.                             { typeof(string), typeof(string) },
  191.                         }},

  192.                         // Comparing long
  193.                         {typeof(long), new Dictionary<Type, Type>() {
  194.                             { typeof(byte), typeof(long) },
  195.                             { typeof(short), typeof(long) },
  196.                             { typeof(int), typeof(long) },
  197.                             { typeof(long), typeof(long) },
  198.                             { typeof(ulong), typeof(ulong) },
  199.                             { typeof(float), typeof(float) },
  200.                             { typeof(double), typeof(double) },
  201.                             { typeof(decimal), typeof(decimal) },
  202.                             { typeof(bool), typeof(string) },
  203.                             { typeof(char), typeof(string) },
  204.                             { typeof(string), typeof(string) },
  205.                         }},

  206.                         // Comparing ulong
  207.                         {typeof(ulong), new Dictionary<Type, Type>() {
  208.                             { typeof(byte), typeof(ulong) },
  209.                             { typeof(short), typeof(ulong) },
  210.                             { typeof(int), typeof(ulong) },
  211.                             { typeof(long), typeof(ulong) },
  212.                             { typeof(ulong), typeof(ulong) },
  213.                             { typeof(float), typeof(float) },
  214.                             { typeof(double), typeof(double) },
  215.                             { typeof(decimal), typeof(decimal) },
  216.                             { typeof(bool), typeof(string) },
  217.                             { typeof(char), typeof(string) },
  218.                             { typeof(string), typeof(string) },
  219.                         }},

  220.                         // Comparing float
  221.                         {typeof(float), new Dictionary<Type, Type>() {
  222.                             { typeof(byte), typeof(float) },
  223.                             { typeof(short), typeof(float) },
  224.                             { typeof(int), typeof(float) },
  225.                             { typeof(long), typeof(float) },
  226.                             { typeof(ulong), typeof(float) },
  227.                             { typeof(float), typeof(float) },
  228.                             { typeof(double), typeof(double) },
  229.                             { typeof(decimal), typeof(decimal) },
  230.                             { typeof(bool), typeof(string) },
  231.                             { typeof(char), typeof(string) },
  232.                             { typeof(string), typeof(string) },
  233.                         }},

  234.                         // Comparing double
  235.                         {typeof(double), new Dictionary<Type, Type>() {
  236.                             { typeof(byte), typeof(double) },
  237.                             { typeof(short), typeof(double) },
  238.                             { typeof(int), typeof(double) },
  239.                             { typeof(long), typeof(double) },
  240.                             { typeof(ulong), typeof(double) },
  241.                             { typeof(float), typeof(double) },
  242.                             { typeof(double), typeof(double) },
  243.                             { typeof(decimal), typeof(decimal) },
  244.                             { typeof(bool), typeof(string) },
  245.                             { typeof(char), typeof(string) },
  246.                             { typeof(string), typeof(string) },
  247.                         }},

  248.                         // Comparing decimal
  249.                         {typeof(decimal), new Dictionary<Type, Type>() {
  250.                             { typeof(byte), typeof(decimal) },
  251.                             { typeof(short), typeof(decimal) },
  252.                             { typeof(int), typeof(decimal) },
  253.                             { typeof(long), typeof(decimal) },
  254.                             { typeof(ulong), typeof(decimal) },
  255.                             { typeof(float), typeof(decimal) },
  256.                             { typeof(double), typeof(decimal) },
  257.                             { typeof(decimal), typeof(decimal) },
  258.                             { typeof(bool), typeof(string) },
  259.                             { typeof(char), typeof(string) },
  260.                             { typeof(string), typeof(string) },
  261.                         }},

  262.                         // Comparing bool
  263.                         {typeof(bool), new Dictionary<Type, Type>() {
  264.                             { typeof(byte), typeof(string) },
  265.                             { typeof(short), typeof(string) },
  266.                             { typeof(int), typeof(string) },
  267.                             { typeof(long), typeof(string) },
  268.                             { typeof(ulong), typeof(string) },
  269.                             { typeof(float), typeof(string) },
  270.                             { typeof(double), typeof(string) },
  271.                             { typeof(decimal), typeof(string) },
  272.                             { typeof(bool), typeof(bool) },
  273.                             { typeof(char), typeof(string) },
  274.                             { typeof(string), typeof(string) },
  275.                         }},

  276.                         // Comparing char
  277.                         {typeof(char), new Dictionary<Type, Type>() {
  278.                             { typeof(byte), typeof(string) },
  279.                             { typeof(short), typeof(string) },
  280.                             { typeof(int), typeof(string) },
  281.                             { typeof(long), typeof(string) },
  282.                             { typeof(ulong), typeof(string) },
  283.                             { typeof(float), typeof(string) },
  284.                             { typeof(double), typeof(string) },
  285.                             { typeof(decimal), typeof(string) },
  286.                             { typeof(bool), typeof(string) },
  287.                             { typeof(char), typeof(char) },
  288.                             { typeof(string), typeof(string) },
  289.                         }},

  290.                         // Comparing string
  291.                         {typeof(string), new Dictionary<Type, Type>() {
  292.                             { typeof(byte), typeof(string) },
  293.                             { typeof(short), typeof(string) },
  294.                             { typeof(int), typeof(string) },
  295.                             { typeof(long), typeof(string) },
  296.                             { typeof(ulong), typeof(string) },
  297.                             { typeof(float), typeof(string) },
  298.                             { typeof(double), typeof(string) },
  299.                             { typeof(decimal), typeof(string) },
  300.                             { typeof(bool), typeof(string) },
  301.                             { typeof(char), typeof(string) },
  302.                             { typeof(string), typeof(string) },
  303.                         }},

  304.                     };
  305.                 }
  306.             }
  307.         }
  308.     }
  309. }

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-22 21:29 , Processed in 0.362933 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表