小编Not*_*ple的帖子

查找所有父类型(基类和接口)

我希望能够找到特定类型的所有父类型(基类和接口).

EG如果我有

class A : B, C { }
class B : D { }
interface C : E { }
class D { }
interface E { }
Run Code Online (Sandbox Code Playgroud)

我想看到A BCD和E和对象

什么是最好的方法呢?有没有一种反射方法来做到这一点,还是我需要做一些事情.

==== ====编辑

这样的事情呢?

public static IEnumerable<Type> ParentTypes(this Type type)
    {
        foreach (Type i in type.GetInterfaces())
        {
            yield return i;
            foreach (Type t in i.ParentTypes())
            {
                yield return t;
            }
        }

        if (type.BaseType != null)
        {
            yield return type.BaseType;
            foreach (Type b in type.BaseType.ParentTypes())
            {
                yield return b; …
Run Code Online (Sandbox Code Playgroud)

.net c#

14
推荐指数
3
解决办法
2万
查看次数

按ID选择多行,是否比WHERE IN更快

我有一个SQL表,我想按ID选择多行.例如,我想从我的表中获取ID为1,5和9的行.

我一直在使用类似于下面的WHERE IN语句执行此操作:

SELECT [Id]
FROM [MyTable]
WHERE [Id] IN (1,5,9)
Run Code Online (Sandbox Code Playgroud)

然而,对于"IN"子句中的大量项目来说,这是非常缓慢的

下面是使用1,000,000行的表中的where in选择行的一些性能数据

Querying for 1 random keys (where in) took 0ms
Querying for 1000 random keys (where in) took 46ms
Querying for 2000 random keys (where in) took 94ms
Querying for 3000 random keys (where in) took 249ms
Querying for 4000 random keys (where in) took 316ms
Querying for 5000 random keys (where in) took 391ms
Querying for 6000 random keys (where in) took 466ms
Querying for 7000 …
Run Code Online (Sandbox Code Playgroud)

sql sql-server-2008-r2

14
推荐指数
1
解决办法
7153
查看次数

使用reactJs TestUtils模拟文本输入

我希望能够使用reactjs模拟用户在文本框中键入内容,以便我可以测试我的验证状态消息.

我有一个在keyUp上验证的react组件

以下是我尝试过的一个简单示例.

nameInput.props.value = 'a';
React.addons.TestUtils.Simulate.keyUp(nameInput);
React.addons.TestUtils.findRenderedDOMComponentWithClass(component, 'has-error');
Run Code Online (Sandbox Code Playgroud)

当我在验证器中调试时,这似乎不会更改绑定文本框的值

React.addons.TestUtils.Simulate.keyUp(nameInput, {key: 'a'});
React.addons.TestUtils.findRenderedDOMComponentWithClass(component, 'has-error');
Run Code Online (Sandbox Code Playgroud)

这也不是.

有人能指出我在正确的轨道上,第二个内容是我可以在模拟(http://facebook.github.io/react/docs/test-utils.html)周围找到的文档,第一个对我有意义(设置实际的文本框值,然后伪造一个事件)

javascript unit-testing reactjs reactjs-testutils

14
推荐指数
1
解决办法
8069
查看次数

不在NServiceBus中自动创建队列

我正在运行NServiceBus 3.0.0 rc2但是当我启动应用程序(作为本地管理员)而没有预先创建MSMQ时,它出错了:

队列不存在或您没有足够的权限来执行操作.

使用NServiceBus 2.6没有发生这种情况.

以下是我的配置:

var bus = Configure.With()
    .Log4Net()
    .NinjectBuilder()
    .XmlSerializer()
    .DefiningCommandsAs(t => typeof(ICommand).IsAssignableFrom(t))
    .DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t))
    .DefiningMessagesAs(t => typeof(IMessage).IsAssignableFrom(t))
    .MsmqTransport()
        .DefineEndpointName("subscriber.input")
        .IsTransactional(true)
        .PurgeOnStartup(false)
    .UnicastBus()
        .LoadMessageHandlers() 
        .ImpersonateSender(false)
    .CreateBus()
    .Start();
Run Code Online (Sandbox Code Playgroud)

<configuration>
  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>    
  <MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />    
  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MyEvents" Endpoint="publisher.input" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我可以看到一个配置扩展方法来禁用自动创建队列但没有启用它.

如果我预先创建队列,它工作正常.

.net c# msmq exception-handling nservicebus

13
推荐指数
2
解决办法
7461
查看次数

Visual Studio调试器,不要停止网站停止调试

在Visual Studio的早期版本(或我多年前设置的一些设置)中,当我停止调试Web应用程序时,实际的IIS express实例将继续运行.我真的很喜欢这种行为,因为这意味着当我正在编辑我的代码/重新编译时,网站总是在修补.

自升级到VS 2013以来,这似乎不再发生,当我停止调试时,它也会停止IIS Express应用程序池.

有谁知道某个地方是否有设置可以改变这种行为?

debugging visual-studio visual-studio-2013

13
推荐指数
1
解决办法
5273
查看次数

使用await与异步数据库调用有什么好处

我只是看看默认的MVC5项目以及它如何在控制器中使用async.

我想知道async在简单地使用同步调用时提供了什么好处:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Disassociate(string loginProvider, string providerKey)
    {
        ManageMessageId? message = null;

        //why use an async database call here with await instead of just using a synchronous one?
        IdentityResult result = await UserManager.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));
        if (result.Succeeded)
        {
            message = ManageMessageId.RemoveLoginSuccess;
        }
        else
        {
            message = ManageMessageId.Error;
        }
        return RedirectToAction("Manage", new { Message = message });
    }
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

这是否会在此处发生的等待类型中提供某种性能优势?

c# async-await entity-framework-6 asp.net-mvc-5

13
推荐指数
1
解决办法
6621
查看次数

获取dotnet核心中当前正在执行的方法的名称

我想在dotnet核心应用程序中获取当前正在执行的方法的名称.

有很多关于如何使用常规c#执行此操作的示例,例如

然而,这两种方法的api似乎还没有核心(参见https://github.com/dotnet/corefx/issues/1420)

有没有其他方法可以在.net核心中获取执行方法名称?

c# .net-core

13
推荐指数
1
解决办法
6787
查看次数

实体框架导航属性生成规则

我想知道实体框架在导航属性的命名/生成方面遵循的规则.我观察过几个似乎没有意义的场景,所以我想知道是否有人确切知道这些是如何工作的.

场景1:

public class Post
{
    public int Id { get; set; }
    public User Author { get; set; }
} 
Run Code Online (Sandbox Code Playgroud)

   生成

场景1

即.默认情况下,导航属性会生成名为[PropertyName] _Id的FK

场景2:

有意义的是,如果EF在您手动指定FK ID时生成格式[PropertyName] _Id等属性,则它将遵循相同的规则:

public class Post
{
    public int Id { get; set; }
    public int? Author_Id { get; set; }
    public User Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

   生成

情景2

如您所见,这不会自动注册为nav属性.

场景3:

如果它不适用于场景2,为什么它适用于备用命名约定?

public class Post
{
    public int Id { get; set; }
    public int? AuthorId { get; set; }
    public User Author { …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

12
推荐指数
1
解决办法
6250
查看次数

MEF和ShadowCopying DLL,以便我可以在运行时覆盖它们

我试图阻止我的应用程序锁定我的MEF插件目录中的DLL,以便我可以在运行时覆盖程序集(注意我实际上并没有尝试让MEF在运行时重新加载它们,在下一个应用程序启动很好,我只是不想要停止应用程序来复制)

我试图通过为我的mef加载的程序集创建一个阴影复制的应用程序域来执行此操作,如下所示:

[Serializable]
    public class Composer:IComposer
    {
        private readonly string _pluginPath;
        public Composer(IConfigurePluginDirectory pluginDirectoryConfig)
        {
            _pluginPath = pluginDirectoryConfig.Path;
            var setup = new AppDomainSetup();
            setup.ShadowCopyFiles = "true"; // really??? is bool not good enough for you?
            var appDomain = AppDomain.CreateDomain(AppDomain.CurrentDomain.FriendlyName + "_PluginDomain", AppDomain.CurrentDomain.Evidence, setup);

            appDomain.DoCallBack(new CrossAppDomainDelegate(DoWorkInShadowCopiedDomain));      
        }

        private void DoWorkInShadowCopiedDomain()
        {
            // This work will happen in the shadow copied AppDomain.

            var catalog = new AggregateCatalog();
            var dc = new DirectoryCatalog(_pluginPath);
            catalog.Catalogs.Add(dc);
            Container = new CompositionContainer(catalog);
        }

        public CompositionContainer Container { …
Run Code Online (Sandbox Code Playgroud)

c# mef shadow-copy appdomain

12
推荐指数
1
解决办法
4365
查看次数

React + Webpack HMR刷新页面(不热装)

我在使反应热的webpack加载器正常工作时遇到了一些麻烦.

当我加载页面时,我得到以下内容,如我所料:

[HMR]等待来自WDS的更新信号...
[WDS]启用热模块更换.

但是当我保存更改时,页面会自动刷新浏览器(而不是HMR替换).

//webpack.config.js

 {
  entry: {
    client: 'webpack-dev-server/client?http://localhost:8786', // WebpackDevServer host and port
    app: "./HelloWorld.tsx"
  },
  devtool: process.env.WEBPACK_DEVTOOL || 'cheap-module-source-map',
  output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].entry.js'
  },
  module: {
    loaders: [
      {
        test: /\.ts(x?)$/,
        loaders: ['react-hot', 'babel-loader?cacheDirectory=true,presets[]=es2015,presets[]=react', 'ts-loader']
      }
    ]
  },
    devServer: {
        contentBase: "./dist",
    port:8786
    },
    plugins: [
        new webpack.NoErrorsPlugin()
    ]
}
Run Code Online (Sandbox Code Playgroud)

命令: webpack-dev-server --hot --inline

在一个有趣的旁注,如果我使用babel-preset-react-hmre一切按预期工作.(但是我真的不想使用它,因为它似乎比正确的反应热装载机支持更少).

javascript reactjs webpack webpack-dev-server react-hot-loader

12
推荐指数
1
解决办法
6428
查看次数