小编Den*_*i35的帖子

Lambda for getter和setter of property

在C#6.0中我可以写:

public int Prop => 777;
Run Code Online (Sandbox Code Playgroud)

但我想使用getter和setter.有办法做下一件事吗?

public int Prop {
   get => propVar;
   set => propVar = value;
}
Run Code Online (Sandbox Code Playgroud)

c# c#-6.0

46
推荐指数
2
解决办法
6万
查看次数

如何让 Dispose 等待所有异步方法?

我有异步方法的一次性类。

class Gateway : IDisposable {
  public Gateway() {}
  public void Dispose() {}

  public async Task<Data> Request1 () {...}
  public async Task<Data> Request2 () {...}
  public async Task<Data> Request3 () {...}
}
Run Code Online (Sandbox Code Playgroud)

我需要 Dispose 等待所有正在运行的请求完成。

那么,要么我需要跟踪所有正在运行的任务,要么使用AsyncLockAsyncEx 或其他东西?

更新

正如我所看到的,有人害怕阻止 Dispose。然后我们可以制作Task WaitForCompletionAsync()Task CancelAllAsync()方法。

.net c# multithreading asynchronous async-await

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

Polymer.js双向绑定到textarea值

在0.5版本中很容易:

<polymer-element name="textarea-tpl" attributes="value placeholder">
    <template>
        <link rel="stylesheet" type="text/css" href="css/index.css">

        <textarea id="textarea" value="{{value}}" placeholder="{{placeholder}}"></textarea>
        <textarea id="hidden_textarea"></textarea>
    </template>
    <script>
        Polymer({
            ready: function() {
                var text = this.$.textarea;
                var hidden_text = this.$.hidden_textarea;

                text.onkeyup = function() {
                    hidden_text.value = text.value + "\n";
                    var height = hidden_text.scrollHeight;
                    text.style.height = height+'px';
                };
            }
        });
    </script>
</polymer-element>
Run Code Online (Sandbox Code Playgroud)

在1.0版本中,此绑定不起作用.只写一次作品而且很奇怪,只有一次.v1.0的代码:

<dom-module id="chat-textarea">
    <template>
        <textarea id="textarea" value="{{value}}" placeholder="{{placeholder}}"></textarea>
        <textarea id="hidden_textarea"></textarea>
    </template>

    <script>
        Polymer({
            is: "chat-textarea",
            properties: {
                value: String,
                placeholder: String
            },

            set text(val) {
                this.$.textarea.value = val;
            }, …
Run Code Online (Sandbox Code Playgroud)

javascript polymer polymer-1.0

7
推荐指数
1
解决办法
3206
查看次数

Asp.net核心+ IIS Express.如何查看日志消息?

我正试图通过以下方式打印消息:

Console.WriteLine( "Hello World!" );

loggerFactory.MinimumLevel = LogLevel.Debug;
loggerFactory.AddConsole( LogLevel.Debug );
var logger = loggerFactory.CreateLogger("Startup");
logger.LogWarning( "Hi!" );
Run Code Online (Sandbox Code Playgroud)

但是我在哪里可以看到这些消息?

输出窗口不包含此消息.

如果我将项目作为Web运行,它会运行dnx控制台,在那里我可以看到这些消息.但这不方便.

但是,如果我将项目作为IIS Express运行,我看不到也没有控制台,也没有消息.

有没有办法在Visual Studio中查看此消息?

asp.net visual-studio iis-express asp.net-core

6
推荐指数
2
解决办法
6127
查看次数

为什么是typeof(Child <>).BaseType.IsGenericTypeDefinition false?

例:

class Base<T>{}
class Child<T> : Base<T>{}

typeof( Base<> ).IsGenericTypeDefinition; // == true ie. parameterless 
typeof( Child<> ).BaseType.IsGenericTypeDefinition; // == false wtf???

// Eventually 
typeof( Base<> ) != typeof( Child<> ).BaseType;
Run Code Online (Sandbox Code Playgroud)

由于此功能typeof( Child<> ).IsSubclassOf( typeof( Base<> ) )不起作用.

.net c# generics

6
推荐指数
1
解决办法
134
查看次数

VS2017、VSIX:刚刚创建的 AsyncPackage 没有被实例化

这是默认的 VSPackage。我只添加了 ProvideAutoLoad 属性。

using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.Win32;
using Task = System.Threading.Tasks.Task;

namespace VSIXProject1
{
    /// <summary>
    /// This is the class that implements the package exposed by this assembly.
    /// </summary>
    /// <remarks>
    /// <para>
    /// The minimum requirement for a class to be considered a valid package for Visual Studio
    /// is to implement the IVsPackage …
Run Code Online (Sandbox Code Playgroud)

visual-studio vsix visual-studio-extensions vssdk

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

NLog:什么是布局和布局渲染器?

我是 NLog 新手,对布局和布局渲染器感到困惑。

我看到以下代码\页面:

  1. https://github.com/NLog/NLog/wiki/Configuration-API

    Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}"

  2. https://github.com/NLog/NLog/wiki/CsvLayout (xml)

  3. https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer(类似于第一个)

我明白第一个(日志消息的格式),但第二个和第三个我不明白。

nlog

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