当前位置: 首页>>代码示例>>C#>>正文


C# StringReader.Dispose方法代码示例

本文整理汇总了C#中StringReader.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# StringReader.Dispose方法的具体用法?C# StringReader.Dispose怎么用?C# StringReader.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringReader的用法示例。


在下文中一共展示了StringReader.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: loadCSVTable

    public CSVTable loadCSVTable(string para_tableName, string para_fullFilePath)
    {
        UnityEngine.TextAsset ta = (UnityEngine.TextAsset) UnityEngine.Resources.Load(para_fullFilePath,typeof(UnityEngine.TextAsset));
        StringReader sr = new StringReader(ta.text);

        List<string> columnHeaders = new List<string>();
        List<CSVTableRow> dataRows = new List<CSVTableRow>();

        int counter = 0;
        string csvLine = sr.ReadLine();
        while(csvLine != null)
        {
            List<string> parsedLine = parseCSVStringToList(csvLine);

            if(counter == 0)
            {
                // Store column headers.
                columnHeaders = parsedLine;
            }
            else
            {
                // Store next data row.
                dataRows.Add(new CSVTableRow(parsedLine));
            }

            counter++;
            csvLine = sr.ReadLine();
        }

        sr.Close();
        sr.Dispose();

        // Fill Table.
        CSVTable nwTable = new CSVTable(para_tableName,columnHeaders.ToArray(),dataRows);
        return nwTable;
    }
开发者ID:TAPeri,项目名称:WordsMatter,代码行数:36,代码来源:CSVTableHelper.cs

示例2: CXmlFileToDataSet

        /**/
        /// <summary>   
        /// 读取Xml文件信息,并转换成DataSet对象    
        /// </summary>    
        /// <remarks>    
        /// DataSet ds = new DataSet();    
        /// ds = CXmlFileToDataSet("/XML/upload.xml");    
        /// </remarks>    
        /// <param name="xmlFilePath">Xml文件地址</param>    
        /// <returns>DataSet对象</returns>    
        public static DataSet CXmlFileToDataSet(string xmlFilePath)
        {
            if (!string.IsNullOrEmpty(xmlFilePath))
            {
                string path = HttpContext.Current.Server.MapPath(xmlFilePath);
                StringReader StrStream = null;
                XmlTextReader Xmlrdr = null;
                try
                {
                    XmlDocument xmldoc = new XmlDocument();
                    //根据地址加载Xml文件
                    xmldoc.Load(path);
                    DataSet ds = new DataSet();
                    //读取文件中的字符流
                    StrStream = new StringReader(xmldoc.InnerXml);
                    //获取StrStream中的数据
                    Xmlrdr = new XmlTextReader(StrStream);
                    //ds获取Xmlrdr中的数据
                    ds.ReadXml(Xmlrdr);
                    return ds;
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    //释放资源
                    if (Xmlrdr != null)
                    {
                        Xmlrdr.Close();
                        StrStream.Close();
                        StrStream.Dispose();
                    }
                }
            }
            else
            {
                return null;
            }
        }

        /**/
        /// <summary>   
        /// 将Xml内容字符串转换成DataSet对象    
        /// </summary>    
        /// <param name="xmlStr">Xml内容字符串</param>    
        /// <returns>DataSet对象</returns>    
        public static DataSet CXmlToDataSet(string xmlStr)
        {
            if (!string.IsNullOrEmpty(xmlStr))
            {
                StringReader StrStream = null;
                XmlTextReader Xmlrdr = null;
                try
                {
                    DataSet ds = new DataSet();
                    //读取字符串中的信息
                    StrStream = new StringReader(xmlStr);
                    //获取StrStream中的数据
                    Xmlrdr = new XmlTextReader(StrStream);
                    //ds获取Xmlrdr中的数据
                    ds.ReadXml(Xmlrdr);
                    return ds;
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    //释放资源
                    if (Xmlrdr != null)
                    {
                        Xmlrdr.Close();
                        StrStream.Close();
                        StrStream.Dispose();
                    }
                }
            }
            else
            {
                return null;
            }
        }
开发者ID:vinStar,项目名称:vin_zone_2009,代码行数:95,代码来源:showXML.aspx.cs

示例3: SetValues

    private void SetValues(string xml)
    {
        StringReader stringReader = new StringReader(xml);
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.CheckCharacters = false;
        XmlReader reader = XmlReader.Create(stringReader, settings);
        //XmlTextReader reader = new XmlTextReader(stringReader);
        //reader.WhitespaceHandling = WhitespaceHandling.None;

        string fieldName = "";
        string fieldValue = "";
        string fieldAttr = "";
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    fieldName = reader.Name;
                    fieldAttr = reader.GetAttribute("CustomColourType");
                    break;
                case XmlNodeType.Text:
                    fieldValue = reader.Value;
                    break;
                case XmlNodeType.CDATA:
                    fieldValue = reader.Value;
                    break;
                case XmlNodeType.EndElement:
                    SetControlValue(fieldName, fieldValue, fieldAttr);
                    fieldName = "";
                    fieldValue = "";
                    fieldAttr = "";
                    break;
            }
        }

        reader.Close();
        stringReader.Close();
        stringReader.Dispose();
    }
开发者ID:prasannapattam,项目名称:ExamPatient,代码行数:39,代码来源:ExamPatient.aspx.cs

示例4: Deserialize

    public static bool Deserialize(string data)
    {
        StringReader reader = null;
        XmlSerializer xmls = new XmlSerializer(typeof(SceneCollection));

        try {
            reader = new StringReader(data);
            collection = xmls.Deserialize(reader) as SceneCollection;
        }
        catch(Exception e) {
            Debug.LogError("Something went horribly wrong: \n" + e.ToString());
            return false;
        }
        finally {
            reader.Dispose();
        }

        return true;
    }
开发者ID:lorenalexm,项目名称:unity-browser-saving,代码行数:19,代码来源:SceneSerializer.cs

示例5: GetDictionary

    public static Dictionary<string, string> GetDictionary(string xml, bool removeDupsSuffix)
    {
        Dictionary<string, string> dict = new Dictionary<string, string>();

        StringReader stringReader = new StringReader(xml);
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.CheckCharacters = false;
        XmlReader reader = XmlReader.Create(stringReader, settings);
        //XmlTextReader reader = new XmlTextReader(stringReader);
        //reader.WhitespaceHandling = WhitespaceHandling.None;

        string fieldName = "";
        string fieldValue = "";
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    fieldName = reader.Name;
                    break;
                case XmlNodeType.Text:
                    fieldValue = reader.Value;
                    break;
                case XmlNodeType.CDATA:
                    fieldValue = reader.Value;
                    break;
                case XmlNodeType.EndElement:
                    if (fieldName != "")
                    {
                        if (removeDupsSuffix & fieldValue.Contains("~"))
                        {
                            string dupNumber = fieldValue.Substring(fieldValue.LastIndexOf('~') + 1);
                            int dupNumberOut;
                            if (Int32.TryParse(dupNumber, out dupNumberOut))
                            {
                                fieldValue = fieldValue.Remove(fieldValue.LastIndexOf('~'));
                            }
                        }
                        dict.Add(fieldName, fieldValue);
                    }
                    fieldName = "";
                    break;
            }
        }

        reader.Close();
        stringReader.Close();
        stringReader.Dispose();

        return dict;
    }
开发者ID:prasannapattam,项目名称:ExamPatient,代码行数:51,代码来源:WebUtil.cs

示例6: getFileInfo

    public static int zipFiles, zipFolders;// global integers that store the number of files and folders in a zip file.

    //This function fills the Lists with the filenames and file sizes that are in the zip file
    //Returns			: the total size of uncompressed bytes of the files in the zip archive 
    //
    //zipArchive		: the full path to the archive, including the archives name. (/myPath/myArchive.zip)
    //path              : the path where a temporary file will be created (recommended to use the Application.persistentDataPath);
	//FileBuffer		: A buffer that holds a zip file. When assigned the function will read from this buffer and will ignore the filePath. (Linux, iOS, Android, MacOSX)
    //
    //ERROR CODES       : -1 = Input file not found
    //                  : -2 = Path to write the temporary log does not exist (for mobiles the Application.persistentDataPath is recommended)
    //                  : -3 = Error of info data of the zip file
    //                  : -4 = Log file not found
    //
    public static long getFileInfo(string zipArchive, string path, byte[] FileBuffer = null)
    {
        ninfo.Clear(); uinfo.Clear(); cinfo.Clear();
        zipFiles = 0; zipFolders = 0;

		int res;
		
		#if (UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_OSX || UNITY_ANDROID || UNITY_STANDALONE_LINUX || UNITY_EDITOR) && !UNITY_EDITOR_WIN
			if(FileBuffer!= null) {
				GCHandle fbuf = GCHandle.Alloc(FileBuffer, GCHandleType.Pinned);
				res = zipGetInfo(null, @path, fbuf.AddrOfPinnedObject(), FileBuffer.Length);
				fbuf.Free();
			}else{
				res = zipGetInfo(@zipArchive, @path, IntPtr.Zero, 0);
			}
		#else
				res = zipGetInfo(@zipArchive, @path, IntPtr.Zero, 0);
		#endif


        if (res == -1) { /*Debug.Log("Input file not found.");*/ return -1; }

		#if (UNITY_WP8_1 || UNITY_WSA) && !UNITY_EDITOR
			if(!UnityEngine.Windows.Directory.Exists(@path)) { /*Debug.Log("Path does not exist: " + path);*/ return -2; }
		#else
        	if (res == -2) { /*Debug.Log("Path does not exist: " + path);*/ return -2; }
		#endif
        if (res == -3) { /*Debug.Log("Entry info error.");*/ return -3; }

        string logPath = @path + "/uziplog.txt";


        if (!File.Exists(logPath)) { /*Debug.Log("Info file not found.");*/ return -4; }

		#if !NETFX_CORE
        StreamReader r = new StreamReader(logPath);
		#endif
		#if NETFX_CORE
			#if UNITY_WSA_10_0
			IsolatedStorageFile ipath = IsolatedStorageFile.GetUserStoreForApplication();
			StreamReader r = new StreamReader(new IsolatedStorageFileStream("uziplog.txt", FileMode.Open, ipath));
			#endif
			#if UNITY_WSA_8_1 ||  UNITY_WP_8_1 || UNITY_WINRT_8_1
			var data = UnityEngine.Windows.File.ReadAllBytes(logPath);
			string ss = System.Text.Encoding.UTF8.GetString(data,0,data.Length);
			StringReader r = new StringReader(ss);
			#endif
		#endif
        string line;
        string[] rtt;
        long t = 0, sum = 0;

        while ((line = r.ReadLine()) != null)
        {
            rtt = line.Split('|');
            ninfo.Add(rtt[0]);

            long.TryParse(rtt[1], out t);
            sum += t;
            uinfo.Add(t);
            if (t > 0) zipFiles++; else zipFolders++;

            long.TryParse(rtt[2], out t);
            cinfo.Add(t);
        }

		#if !NETFX_CORE
        r.Close(); 
		#endif
        r.Dispose();

        File.Delete(logPath);

        return sum;

    }
开发者ID:JimWee,项目名称:MyAssetBundleManager,代码行数:90,代码来源:lzip.cs


注:本文中的StringReader.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。