C# StreamReader.GetType的代码示例

通过代码示例来学习C# StreamReader.GetType方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


StreamReader.GetType是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的StreamReader.GetType() 已经帮大家高亮显示了,大家可以重点学习StreamReader.GetType() 方法的写法,从而快速掌握该方法的应用。

StreamReader.GetType的代码示例1 - TryLoadFromDisk()

    using System.IO;

        /// An optional callback to be run as soon as the fileLock is taken
        protected bool TryLoadFromDisk(
            TryParseAdd tryParseAdd,
            TryParseRemove tryParseRemove,
            Action add,
            out string error,
            Action synchronizedAction = null)
        {
            lock (this.fileLock)
            {
                try
                {
                    if (synchronizedAction != null)
                    {
                        synchronizedAction();
                    }

                    this.fileSystem.CreateDirectory(this.dataDirectoryPath);

                    this.OpenOrCreateDataFile(retryUntilSuccess: false);

                    if (this.collectionAppendsDirectlyToFile)
                    {
                        this.RemoveLastEntryIfInvalid();
                    }

                    long lineCount = 0;

                    this.dataFileHandle.Seek(0, SeekOrigin.Begin);
                    StreamReader reader = new StreamReader(this.dataFileHandle);
                    Dictionary parsedEntries = new Dictionary();
                    while (!reader.EndOfStream)
                    {
                        lineCount++;

                        // StreamReader strips the trailing /r/n
                        string line = reader.ReadLine();
                        if (line.StartsWith(RemoveEntryPrefix))
                        {
                            TKey key;
                            if (!tryParseRemove(line.Substring(RemoveEntryPrefix.Length), out key, out error))
                            {
                                error = string.Format("{0} is corrupt on line {1}: {2}", this.GetType().Name, lineCount, error);
                                return false;
                            }

                            parsedEntries.Remove(key);
                        }
                        else if (line.StartsWith(AddEntryPrefix))
                        {
                            TKey key;
                            TValue value;
                            if (!tryParseAdd(line.Substring(AddEntryPrefix.Length), out key, out value, out error))
                            {
                                error = string.Format("{0} is corrupt on line {1}: {2}", this.GetType().Name, lineCount, error);
                                return false;
                            }

                            parsedEntries[key] = value;
                        }
                        else
                        {
                            error = string.Format("{0} is corrupt on line {1}: Invalid Prefix '{2}'", this.GetType().Name, lineCount, line[0]);
                            return false;
                        }
                    }

                    foreach (KeyValuePair kvp in parsedEntries)
                    {
                        add(kvp.Key, kvp.Value);
                    }

                    if (!this.collectionAppendsDirectlyToFile)
                    {
                        this.CloseDataFile();
                    }
                }
                catch (IOException ex)
                {
                    error = ex.ToString();
                    this.CloseDataFile();
                    return false;
                }
                catch (Exception e)
                {
                    this.CloseDataFile();
                    throw new FileBasedCollectionException(e);
                }

                error = null;
                return true;
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:95,代码来源:FileBasedCollection.cs

在TryLoadFromDisk()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例2 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoCSVRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder csv = new StringBuilder();
                configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoCSVWriter(csv, configuration))
                    w.Write(rec as DataTable);
                return csv.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder csv = new StringBuilder();
                configuration = configuration == null ? new ChoCSVRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoCSVWriter(csv, configuration))
                    w.Write(rec as IDataReader);
                return csv.ToString();
            }

            ChoCSVRecordWriter writer = new ChoCSVRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:35,代码来源:ChoCSVWriter.cs

在ToText()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例3 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoFixedLengthRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder text = new StringBuilder();
                configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoFixedLengthWriter(text, configuration))
                    w.Write(rec as DataTable);
                return text.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder text = new StringBuilder();
                configuration = configuration == null ? new ChoFixedLengthRecordConfiguration().Configure(c => c.WithFirstLineHeader()) : configuration;
                using (var w = new ChoFixedLengthWriter(text, configuration))
                    w.Write(rec as IDataReader);
                return text.ToString();
            }

            ChoFixedLengthRecordWriter writer = new ChoFixedLengthRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:35,代码来源:ChoFixedLengthWriter.cs

在ToText()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例4 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoJSONRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoJSONWriter(json, configuration))
                {
                    w.Write(rec as DataTable);
                }
                return json.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoJSONWriter(json, configuration))
                {
                    w.Write(rec as IDataReader);
                }
                return json.ToString();
            }

            ChoJSONRecordWriter writer = new ChoJSONRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:37,代码来源:ChoJSONWriter.cs

在ToText()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例5 - ToText()

    using System.IO;

        public static string ToText(TRec record, ChoXmlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string xpath = null)
            where TRec : class
        {
            if (record is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as DataTable);
                return xml.ToString();
            }
            else if (record is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as IDataReader);
                return xml.ToString();
            }

            if (configuration == null)
            {
                configuration = new ChoXmlRecordConfiguration(typeof(TRec));
                configuration.IgnoreRootName = true;
                configuration.RootName = null;
                configuration.IgnoreNodeName = false;
            }

            if (record != null)
            {
                if (configuration.NodeName.IsNullOrWhiteSpace())
                {
                    ChoDynamicObject rec1 = record as ChoDynamicObject;
                    if (rec1 != null)
                    {
                        if (rec1.DynamicObjectName != ChoDynamicObject.DefaultName)
                        {
                            configuration.NodeName = rec1.DynamicObjectName;
                        }
                        else
                        {
                            //configuration.IgnoreNodeName = true;
                            //configuration.NodeName = null;
                        }
                    }
                    else
                    {
                        XmlRootAttribute root = ChoType.GetCustomAttribute(record.GetType(), false);
                        string nodeName = "XElement";
                        if (root != null && !root.ElementName.IsNullOrWhiteSpace())
                            nodeName = root.ElementName.Trim();
                        else
                            nodeName = record.GetType().Name;

                        configuration.NodeName = nodeName;
                    }
                }
            }

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var writer = new StreamWriter(stream))
            using (var parser = new ChoXmlWriter(writer, configuration) { TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch })
            {
                //parser.Configuration.XPath = xpath;

                if (record != null)
                    parser.Write(ChoEnumerable.AsEnumerable(record));

                parser.Close();

                writer.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:77,代码来源:ChoXmlWriter.cs

在ToText()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例6 - ToText()

    using System.IO;

        internal static string ToText(object rec, ChoYamlRecordConfiguration configuration, Encoding encoding, int bufferSize, TraceSwitch traceSwitch = null)
        {
            if (rec is DataTable)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as DataTable);
                }
                return json.ToString();
            }
            else if (rec is IDataReader)
            {
                StringBuilder json = new StringBuilder();
                using (var w = new ChoYamlWriter(json, configuration))
                {
                    w.Write(rec as IDataReader);
                }
                return json.ToString();
            }

            ChoYamlRecordWriter writer = new ChoYamlRecordWriter(rec.GetType(), configuration);
            writer.TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitchOff : traceSwitch;

            using (var stream = new MemoryStream())
            using (var reader = new StreamReader(stream))
            using (var sw = new StreamWriter(stream, configuration.Encoding, configuration.BufferSize))
            {
                writer.WriteTo(sw, new object[] { rec }).Loop();
                sw.Flush();
                stream.Position = 0;

                return reader.ReadToEnd();
            }
        }
    

开发者ID:Cinchoo,项目名称:ChoETL,代码行数:37,代码来源:ChoYamlWriter.cs

在ToText()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

StreamReader.GetType的代码示例7 - ReadPrintLoopLogFileAsync()

    using System.IO;
        #endregion

        #region ReadPrintLoopLogFileAsync
        private void ReadPrintLoopLogFileAsync(bool isWriteToConsole) {
            Task.Factory.StartNew(() => {
                bool isLogFileCreated = true;
                int n = 0;
                while (!File.Exists(this.LogFileFullName)) {
                    if (n >= 20) {
                        // 20秒钟都没有建立日志文件,不可能
                        isLogFileCreated = false;
                        NTMinerConsole.UserFail("呃!意外,竟然20秒钟未产生内核输出。常见原因:1.挖矿内核被杀毒软件删除; 2.没有磁盘空间了; 3.反馈给开发人员");
                        break;
                    }
                    Thread.Sleep(1000);
                    if (n == 0) {
                        NTMinerConsole.UserInfo("等待内核出场");
                    }
                    if (this != NTMinerContext.Instance.LockedMineContext) {
                        NTMinerConsole.UserWarn("结束内核输出等待。");
                        isLogFileCreated = false;
                        break;
                    }
                    n++;
                }
                if (isLogFileCreated) {
                    StreamReader sreader = null;
                    try {
                        Process kernelProcess = this.KernelProcess;
                        DateTime _kernelRestartKeywordOn = DateTime.MinValue;
                        sreader = new StreamReader(File.Open(this.LogFileFullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.Default);
                        while (this.KernelProcess != null && this.KernelProcess == kernelProcess) {
                            string outline = sreader.ReadLine();
                            if (string.IsNullOrEmpty(outline)) {
                                Thread.Sleep(100);
                            }
                            else {
                                string input = outline;
                                if (this.KernelOutput != null) {
                                    Guid kernelOutputId = this.KernelOutput.GetId();
                                    // 前译
                                    NTMinerContext.Instance.ServerContext.KernelOutputTranslaterSet.Translate(kernelOutputId, ref input, isPre: true);
                                    if (!string.IsNullOrEmpty(KernelOutput.KernelRestartKeyword) && input.Contains(KernelOutput.KernelRestartKeyword)) {
                                        if (_kernelRestartKeywordOn.AddSeconds(1) < DateTime.Now) {
                                            KernelSelfRestartCount += 1;
                                            _kernelRestartKeywordOn = DateTime.Now;
                                            VirtualRoot.RaiseEvent(new KernelSelfRestartedEvent());
                                        }
                                    }
                                    // 挖矿时如果主界面状态栏的数据更新的慢不是程序执行的慢而是挖矿内核将输出刷到磁盘的时间有缓冲
                                    KernelOutputPicker.Pick(ref input, this);
                                    var kernelOutputKeywords = NTMinerContext.Instance.KernelOutputKeywordSet.GetKeywords(this.KernelOutput.GetId());
                                    if (kernelOutputKeywords != null && kernelOutputKeywords.Count != 0) {
                                        foreach (var keyword in kernelOutputKeywords) {
                                            if (keyword != null && !string.IsNullOrEmpty(keyword.Keyword) && input.Contains(keyword.Keyword)) {
                                                if (keyword.MessageType.TryParse(out LocalMessageType messageType)) {
                                                    string content = input;
                                                    if (!string.IsNullOrEmpty(keyword.Description)) {
                                                        content = $" 大意:{keyword.Description} 详情:" + content;
                                                    }
                                                    VirtualRoot.LocalMessage(
                                                        LocalMessageChannel.Kernel, 
                                                        this.GetType().Name, 
                                                        messageType, 
                                                        consoleLine: keyword.Description, 
                                                        content, 
                                                        OutEnum.None);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (isWriteToConsole) {
                                    if (!string.IsNullOrEmpty(input)) {
                                        NTMinerConsole.UserLine(input, ConsoleColor.White);
                                    }
                                }
                                else {
                                    NTMinerConsole.ConsoleOutLineSet.Add(new ConsoleOutLine {
                                        Timestamp = Timestamp.GetTimestamp(),
                                        Line = outline
                                    });
                                }
                            }
                        }
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e);
                    }
                    finally {
                        sreader?.Close();
                        sreader?.Dispose();
                    }
                    NTMinerConsole.UserWarn("挖矿已停止");
                }
            }, TaskCreationOptions.LongRunning);
        }
    

开发者ID:ntminer,项目名称:NtMiner,代码行数:98,代码来源:MineContext.cs

在ReadPrintLoopLogFileAsync()方法中,StreamReader的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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