小编TJ *_*hon的帖子

如何包装 UnityEngine.Debug.Log 但在单击时保留代码行

我有这种代码,目的是包装,UnityEngine.Debug.Log这样我就可以在生产中禁用它们,以便我可以稍后查找/过滤。

using System;

public enum LogType
{
    DEBUG,
    CRITICAL
}

public class LogHelper
{
    public static void Log(LogType lt, string format, params object[] objs)
    {
        if (lt == LogType.CRITICAL)
        {
            //            StackTrace st = new StackTrace(new StackFrame(true));
            //            Console.WriteLine(" Stack trace for current level: {0}", st.ToString());
            //            StackFrame sf = st.GetFrame(0);
            //            Console.WriteLine(" File: {0}", sf.GetFileName());
            //            Console.WriteLine(" Method: {0}", sf.GetMethod().Name);
            //            Console.WriteLine(" Line Number: {0}", sf.GetFileLineNumber());
            //            Console.WriteLine(" Column Number: {0}", sf.GetFileColumnNumber());
        }
        // TODO: write to …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

5
推荐指数
1
解决办法
5160
查看次数

如何避免使用 System.Reflection 在 ComboBox 中显示 Enum 属性值

我正在使用扩展方法来获取枚举的 DisplayAttribute 名称以将其加载到组合框中。这似乎是相当密集的处理器,并且 UI 的性能受到了影响。

有哪些不同的方式来显示枚举的友好名称?

如果您有兴趣,扩展方法:

public static string GetDisplayName<T>(this T enumValue) where T : IComparable, IFormattable, IConvertible
{
    try
    {
        return enumValue.GetType()
                        .GetMember(enumValue.ToString())
                        .First()
                        .GetCustomAttribute<DisplayAttribute>()
                        .GetName();
    }
    catch // If there's no DisplayAttribute.Name set, just return the ToString value
    {
        return enumValue.ToString();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# wpf combobox

2
推荐指数
1
解决办法
368
查看次数

C#并排合并两个或多个文本文件

using (StreamWriter writer = File.CreateText(FinishedFile))
{
    int lineNum = 0;
    while (lineNum < FilesLineCount.Min())
    {
        for (int i = 0; i <= FilesToMerge.Count() - 1; i++)
        {
            if (i != FilesToMerge.Count() - 1)
            {
                var CurrentFile = File.ReadLines(FilesToMerge[i]).Skip(lineNum).Take(1);
                string CurrentLine = string.Join("", CurrentFile);
                writer.Write(CurrentLine + ",");
            }
            else
            {
                var CurrentFile = File.ReadLines(FilesToMerge[i]).Skip(lineNum).Take(1);
                string CurrentLine = string.Join("", CurrentFile);
                writer.Write(CurrentLine + "\n");
            }
        }
        lineNum++;
    }
}
Run Code Online (Sandbox Code Playgroud)

我目前这样做的方式太慢了.我正在合并每个50k +行长的文件和不同数量的数据.

例如:文件1
1
2
3
4

档案2
4
3
2
1

我需要将它合并成第三个文件
文件3 …

c# performance merge

2
推荐指数
1
解决办法
76
查看次数

标签 统计

c# ×3

combobox ×1

merge ×1

performance ×1

unity-game-engine ×1

wpf ×1