小编Tru*_*ill的帖子

在C#-ASP.NET中有哪些性能[Dos/Don'ts]

我正在完成我的一个项目,并查看整个项目,寻找错误,错误和性能错误.我正在使用MVC.我抓到一个不要,那是:

永远不要将RenderPartial放在循环中.它会大大减慢整个服务器的速度.

c# asp.net-mvc performance

11
推荐指数
3
解决办法
1978
查看次数

数据将枚举属性绑定到网格并显示描述

这是一个类似于如何将自定义枚举描述绑定到DataGrid的问题,但在我的情况下,我有多个属性.

public enum ExpectationResult
{
    [Description("-")]
    NoExpectation,

    [Description("Passed")]
    Pass,

    [Description("FAILED")]
    Fail
}

public class TestResult
{
    public string TestDescription { get; set; }
    public ExpectationResult RequiredExpectationResult { get; set; }
    public ExpectationResult NonRequiredExpectationResult { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我将BindingList <TestResult>绑定到WinForms DataGridView(实际上是DevExpress.XtraGrid.GridControl,但通用解决方案将更广泛适用).我希望描述出现而不是枚举名称.我怎么能做到这一点?(class/enum/attributes没有约束;我可以随意更改它们.)

c# data-binding enums datagridview winforms

11
推荐指数
2
解决办法
9376
查看次数

使用React切换Font Awesome 5图标

我试图通过单击待办事项列表项来切换Font Awesome图标.这是整个组件......

import React from 'react';

import './TodoItem.scss';

class TodoItem extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      complete: false
    }
    this.toggleComplete = this.toggleComplete.bind(this);
  }

  toggleComplete() {
    this.setState(prevState => ({
      complete: !prevState.complete
    }));
  }

  render() {
    const incompleteIcon = <span className="far fa-circle todo-item-icon"></span>;
    const completeIcon = <span className="far fa-check-circle todo-item-icon"></span>;

    return (
      <div className="todo-item" onClick={this.toggleComplete}>
        {this.state.complete ? completeIcon : incompleteIcon}
        <span className="todo-item-text">{this.props.item}</span>
      </div>
    );
  }
}

export default TodoItem;
Run Code Online (Sandbox Code Playgroud)

这是我的FA 5 CDN(直接来自网站)......

<script defer src="https://use.fontawesome.com/releases/v5.0.1/js/all.js"></script>
Run Code Online (Sandbox Code Playgroud)

我拍了一些React开发工具和检查员的截图......

这是React组件,但不完整(默认) 反应组件虽然不完整

虽然完整...... 完成后反应组件

检查器中的两个图标元素,我注意到默认情况下未使用的元素已被注释掉. …

javascript font-awesome reactjs font-awesome-5

11
推荐指数
3
解决办法
8373
查看次数

C#4,动态关键字和后期绑定的CreateObject等价物?

如何在不引用库的情况下从程序标识符或ProgID(例如"Word.Application")在C#4.0中创建动态COM/OLE/ActiveX对象?

在C#3.5中,我必须写一些类似的东西

Type comObjectType = Type.GetTypeFromProgID(progId, true);
Activator.CreateInstance(comObjectType);
Run Code Online (Sandbox Code Playgroud)

有没有更简单的方法在C#4.0中这样做,所以我可以将它分配给动态类型的变量(使用动态关键字)?

c# com dynamic c#-4.0

10
推荐指数
1
解决办法
4772
查看次数

在方法调用前放一个代字号?

我正在通过一个例子,我看到了......

#if DEBUG
    /// <summary>
    /// Useful for ensuring that ViewModel objects are properly garbage collected.
    /// </summary>
    ~ViewModelBase()
    {
        string msg = string.Format("{0} ({1}) ({2}) Finalized", this.GetType().Name, this.DisplayName, this.GetHashCode());
        System.Diagnostics.Debug.WriteLine(msg);
    }
#endif
Run Code Online (Sandbox Code Playgroud)

我试图谷歌它但无法得到任何结果......我只是想知道这意味着什么.谁知道?

谢谢

c#

10
推荐指数
2
解决办法
4139
查看次数

使用TPL实现经典异步模式

我正在尝试为WF 4实现自定义TrackingParticipant.我可以编写Track方法,但我的实现速度很慢.

如何使用.NET 4.0的任务并行库(TPL)实现Begin/EndTrack覆盖?我看过TPL和Traditional .NET异步编程,但我不知道如何在这里应用它.

请注意,TrackingParticipant是.NET的一部分,并具有使用虚拟方法预定义的经典异步模式.

public class MyTrackingParticipant : TrackingParticipant
{
    protected override IAsyncResult BeginTrack(
        TrackingRecord record, TimeSpan timeout,
        AsyncCallback callback, object state)
    {
        // ?
    }

    protected override void EndTrack(IAsyncResult result)
    {
        // ?
    }

    protected override void Track(TrackingRecord record, TimeSpan timeout)
    {
        // synchronous code to be called
    }
}
Run Code Online (Sandbox Code Playgroud)

c# asynchronous .net-4.0 workflow-foundation-4 task-parallel-library

10
推荐指数
1
解决办法
4150
查看次数

Select-String to grep但只返回唯一的组

我有一个包含很长行的文本文件.我需要来自每一行的一条信息,并且需要查看唯一值.我最初的想法是使用Select-String并指定带有捕获组的正则表达式.我看了几个其他的帖子,但都没有用.这是快速而肮脏的C#等价物:

var text = File.ReadAllText(@"path\File.txt");
var r = new Regex("Path=\"(.*?)\"");
var matches = r.Matches(text);

var h = new HashSet<string>();

foreach(Match match in matches)
{
    h.Add(match.Groups[1].Value);
}

foreach (var s in h)
{
    Console.WriteLine(s);
}
Run Code Online (Sandbox Code Playgroud)

我怎么能在PowerShell中这样做?

更新:

测试答案,我意识到还有一个额外的要求.每个源代码行可以有多个匹配项.例:

Path="One" Path="Two"
Path="Two" Path="Three"

结果应该是:

One
Two
Three

regex powershell

10
推荐指数
1
解决办法
4628
查看次数

Delphi编译时整数转换警告?

在Delphi XE或2006中,有没有办法在编译时检测整数类型之间的隐式转换可能会丢失数据?我意识到可以通过运行时检查来检测这一点.我希望它标记以下示例,即使"big"值为1.(我们正在考虑将int更改为bigint以用于某些数据库键,并希望确定对大型遗留代码库的影响.)

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  small: Integer;
  big: Int64;
begin
  big := 3000000000000;
  small := big;  // Detect me!

  Writeln(small);
end.
Run Code Online (Sandbox Code Playgroud)

delphi type-conversion compiler-warnings delphi-xe

10
推荐指数
1
解决办法
699
查看次数

如何使用webdeploy定位已存在的应用程序池?

我正在尝试确保将我的应用程序部署到使用Web Deploy时已存在的特定应用程序池.在通过IIS管理器安装应用程序时,或者通过从Web包通过命令行安装时更改.setparameters.xml文件中的值,应由用户使用GUI配置应用程序池.将以下参数条目插入我的parameters.xml中并不起作用.

<parameter name="Application Pool" description="Application Pool for this site" tags="iisApp" defaultValue="ASP.NET v4.0">
    <parameterEntry kind="providerPath" scope="IisApp" match="applicationPool" />
</parameter>
Run Code Online (Sandbox Code Playgroud)

有没有直接的方法来实现这一目标?如果没有,我将如何完成这项工作?

msdeploy webdeploy microsoft-web-deploy

10
推荐指数
1
解决办法
6236
查看次数

为什么lambdas可以转换为表达式而方法组不是?

LINQPad示例:

void Main()
{
    One(i => PrintInteger(i));
    One(PrintInteger);

    Two(i => PrintInteger(i));
    // Two(PrintInteger); - won't compile
}

static void One(Action<int> a)
{
    a(1);
}

static void Two(Expression<Action<int>> e)
{
    e.Compile()(2);
}

static void PrintInteger(int i)
{
    Console.WriteLine(i);
}
Run Code Online (Sandbox Code Playgroud)

取消注释该Two(PrintInteger);行会导致错误:

无法从'方法组'转换为'System.Linq.Expressions.Expression <System.Action <int >>'

这类似于将方法组转换为表达式,但我对"为什么"感兴趣.我知道功能需要花费金钱,时间和精力 ; 我想知道是否有更有趣的解释.

c# lambda c#-4.0

10
推荐指数
1
解决办法
1177
查看次数