C# TextWriter.GetType的代码示例

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

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


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

TextWriter.GetType的代码示例1 - MakeDifferenceString()

    using System.IO;

        public static void MakeDifferenceString(object obj1, object obj2, TextWriter messageWriter, string currentObjPath, HashSet visited)
        {
            if (visited.Contains(obj1))
                return;
            visited.Add(obj1);
            var type = obj1.GetType();
            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                if (!propertyInfo.CanRead)
                    continue;
                if (propertyInfo.PropertyType.IsAbstract)
                    continue;
                object firstValue = propertyInfo.GetValue(obj1, null);
                object secondValue = propertyInfo.GetValue(obj2, null);
                var propertyType = propertyInfo.PropertyType;
                if (propertyType.IsValueType || propertyType.IsPrimitive || propertyType == typeof(string) || firstValue == null || secondValue == null)
                {
                    if (!object.Equals(firstValue, secondValue))
                    {
                        messageWriter.WriteLine(propertyInfo.Name + ": \"" + firstValue + "\" and \"" + secondValue + "\"");
                    }
                }
                else
                {
                    var interfaces = propertyInfo.PropertyType.GetInterfaces();
                    if (interfaces.Contains(typeof(IEnumerable)))
                    {
                        if (SequenceCompare(firstValue as IEnumerable, secondValue as IEnumerable) != 0)
                        {
                            messageWriter.WriteLine(propertyInfo.Name + ": \"" + firstValue + "\" and \"" + secondValue + "\"");
                        }
                    }
                    else
                    {
                        MakeDifferenceString(firstValue, secondValue, messageWriter, currentObjPath + propertyInfo.Name + ".", visited);
                    }
                }
            }
        }
    

开发者ID:ubisoft,项目名称:Sharpmake,代码行数:41,代码来源:Util.cs

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

TextWriter.GetType的代码示例2 - WriteRecord()

    using System.IO;

        internal void WriteRecord(T record, int recordIndex, int totalRecord, TextWriter textWriter, IRecordInfo info)
        {
            string currentLine = null;

            try
            {
                if (record == null)
                    throw new BadUsageException("The record at index " + recordIndex + " is null.");

                mLineNumber++;
                mTotalRecords++;

                if (MustNotifyProgress) // Avoid object creation
                    OnProgress(new ProgressEventArgs(recordIndex + 1, totalRecord));

                if (info == null)
                {
                    throw new BadUsageException("A record is of type '" + record.GetType().Name +
                                                "' and the engine doesn't handle this type. You can add it to the constructor.");
                }

                if (info.RecordType.IsInstanceOfType(record) == false)
                {
                    throw new BadUsageException("This engine works with records of type " +
                                                info.RecordType.Name + " and you use records of type " +
                                                record.GetType().Name);
                }

                bool skip = false;
                bool mustNotifyWriteForRecord = MustNotifyWriteForRecord(info);
                if (mustNotifyWriteForRecord)
                {
                    skip = OnBeforeWriteRecord(record, LineNumber);
                }

                if (skip == false)
                {
                    currentLine = info.Operations.RecordToString(record);

                    if (mustNotifyWriteForRecord)
                    {
                        currentLine = OnAfterWriteRecord(currentLine, record);
                    }
                    textWriter.WriteLine(currentLine);
                }
            }
            catch (Exception ex)
            {
                switch (mErrorManager.ErrorMode)
                {
                    case ErrorMode.ThrowException:
                        throw;
                    case ErrorMode.IgnoreAndContinue:
                        break;
                    case ErrorMode.SaveAndContinue:
                        var err = new ErrorInfo
                        {
                            mLineNumber = mLineNumber,
                            mExceptionInfo = ex,
                            mRecordString = currentLine,
                            mRecordTypeName = RecordInfo.RecordType.Name
                        };
                        mErrorManager.AddError(err);
                        break;
                }
            }
        }
    

开发者ID:MarcosMeli,项目名称:FileHelpers,代码行数:69,代码来源:EventEngineBase.cs

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

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