小编Uwe*_*eim的帖子

如何使用out参数调用方法?

我想暴露WebClient.DownloadDataInternal方法,如下所示:

[ComVisible(true)]
public class MyWebClient : WebClient
{
    private MethodInfo _DownloadDataInternal;

    public MyWebClient()
    {
        _DownloadDataInternal = typeof(WebClient).GetMethod("DownloadDataInternal", BindingFlags.NonPublic | BindingFlags.Instance);
    }

    public byte[] DownloadDataInternal(Uri address, out WebRequest request)
    {
        _DownloadDataInternal.Invoke(this, new object[] { address, out request });
    }

}
Run Code Online (Sandbox Code Playgroud)

WebClient.DownloadDataInternal有一个out参数,我不知道如何调用它.救命!

c# reflection out-parameters

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

TypeScript:重复标识符'LibraryManagedAttributes'

我有同样的问题:

React typescript(2312,14):重复标识符'LibraryManagedAttributes'

TypeScript错误:重复标识符'LibraryManagedAttributes'

但我找不到任何解决方案.

我已经升级到最新的node/npm/yarn/typescript版本.还尝试降级.什么都没有帮助.

yarn build --verbose
yarn run v1.9.4
$ react-scripts-ts build --verbose
Creating an optimized production build...
Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
ts-loader: Using typescript@3.0.3 and C:\dev\project\frontend\tsconfig.prod.json
Warning: member-ordering - Bad member kind: public-before-private
Failed to compile.

C:/dev/project/frontend/node_modules/@types/prop-types/node_modules/@types/react/index.d.ts
(2312,14): Duplicate identifier 'LibraryManagedAttributes'.


error Command failed with exit code 1.
Run Code Online (Sandbox Code Playgroud)

--verbose 不知何故不给我更多信息.

我可以看到LibraryManagedAttributes定义如下:

  • node_modules/@types/react/index.d.ts
  • node_modules/@types/prop-types/node_modules/@types/react/index.d.ts
  • node_modules/@types/react-overlays/node_modules/@types/react/index.d.ts
  • ....

这是从哪里来的?我怎么能避免这种情况?

我想找出这个错误的来源,以便我可以向正确的实体报告,但我不知道从哪里开始.

我还能尝试什么?

typescript reactjs

42
推荐指数
8
解决办法
2万
查看次数

如何使用显示文本设置select元素的selectedIndex?

如何使用显示文本作为参考设置select元素的selectedIndex?

例:

<input id="AnimalToFind" type="text" />
<select id="Animals">
    <option value="0">Chicken</option>
    <option value="1">Crocodile</option>
    <option value="2">Monkey</option>
</select>
<input type="button" onclick="SelectAnimal()" />

<script type="text/javascript">
    function SelectAnimal()
    {
        //Set selected option of Animals based on AnimalToFind value...
    }
 </script>
Run Code Online (Sandbox Code Playgroud)

没有循环,有没有其他方法可以做到这一点?你知道,我在想一个内置的JavaScript代码.另外,我不使用jQuery ...

javascript selectedindex

41
推荐指数
2
解决办法
22万
查看次数

String.replaceAll(regex)进行两次相同的替换

谁能告诉我为什么

System.out.println("test".replaceAll(".*", "a"));
Run Code Online (Sandbox Code Playgroud)

结果是

aa
Run Code Online (Sandbox Code Playgroud)

请注意,以下结果相同:

System.out.println("test".replaceAll(".*$", "a"));
Run Code Online (Sandbox Code Playgroud)

我已经在java 6和7上测试了它,两者似乎都表现得一样.我错过了什么或者这是java正则表达式引擎中的错误吗?

java regex

41
推荐指数
1
解决办法
1742
查看次数

只获取特定列

我可以让我的EF对象只检索执行的sql中的特定列吗?如果我正在执行下面的代码来检索对象,那么我可以做些什么来获取某些列,如果需要的话?

public IEnumerable<T> GetBy(Expression<Func<T, bool>> exp)
{
    return _ctx.CreateQuery<T>(typeof(T).Name).Where<T>(exp);
}
Run Code Online (Sandbox Code Playgroud)

这将生成包含所有列的select子句.但是,如果我有一个包含大量数据的列真的会降低查询速度,那么如何让我的对象从生成的sql中排除该列?

如果我的表有Id(int),Status(int),Data(blob),我该如何进行查询

select Id, Status from TableName
Run Code Online (Sandbox Code Playgroud)

代替

select Id, Status, Data from TableName
Run Code Online (Sandbox Code Playgroud)

根据下面的建议,我的方法是

public IEnumerable<T> GetBy(Expression<Func<T, bool>> exp, Expression<Func<T, T>> columns)
{
    return Table.Where<T>(exp).Select<T, T>(columns);
}
Run Code Online (Sandbox Code Playgroud)

我这样称呼它

mgr.GetBy(f => f.Id < 10000, n => new {n.Id, n.Status});
Run Code Online (Sandbox Code Playgroud)

但是,我收到编译错误:

无法将类型'AnonymousType#1'隐式转换为'Entities.BatchRequest'

entity-framework

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

广度优先遍历

我试图解决一个面试问题,但为此我必须逐级旅行二叉树.我设计的BinaryNode具有以下变量

private object data;
private BinaryNode left;
private BinaryNode right;
Run Code Online (Sandbox Code Playgroud)

有人可以帮我在BinarySearchTree类中编写BreadthFirstSearch方法吗?

更新:感谢大家的投入.所以这是面试问题."给定一个二叉搜索树,设计一个算法,创建每个深度的所有节点的链表(即,如果你有一个深度为D的树,你将有D个链表)".

这是我的方法,让我知道你的专家评论.

public List<LinkedList<BNode>> FindLevelLinkList(BNode root)
    {
        Queue<BNode> q = new Queue<BNode>();
        // List of all nodes starting from root.
        List<BNode> list = new List<BNode>();
        q.Enqueue(root);
        while (q.Count > 0)
        {
            BNode current = q.Dequeue();
            if (current == null)
                continue;
            q.Enqueue(current.Left);
            q.Enqueue(current.Right);
            list.Add(current);
        }

        // Add tree nodes of same depth into individual LinkedList. Then add all LinkedList into a List
        LinkedList<BNode> LL = new LinkedList<BNode>();
        List<LinkedList<BNode>> result = …
Run Code Online (Sandbox Code Playgroud)

.net c# algorithm data-structures

40
推荐指数
2
解决办法
4万
查看次数

在字典中使用byte []作为键

我需要byte[]在a中使用a 作为键Dictionary.由于byte[]不会覆盖默认GetHashCode方法,byte[]因此包含相同数据的两个单独对象将在字典中使用两个单独的插槽.基本上我想要的是这个:

Dictionary<byte[], string> dict = new Dictionary<byte[], string>();
dict[new byte[] {1,2,3}] = "my string";
string str = dict[new byte[] {1,2,3}];
// I'd like str to be set to "my string" at this point
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法吗?我唯一能想到的就是构建一个包装类,它只包含一个基于内容的byte[]覆盖,但这似乎容易出错.GetHashCodebyte[]

c#

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

内联列表初始化

这样做时我得到一个奇怪的错误:(.net 2.0)

public overrides List<String> getSpaceballs
{
    get { return new List<String>() { "abc","def","egh" }; }
}
Run Code Online (Sandbox Code Playgroud)

VS要求;之后().为什么?

我当然可以这样做:

public overrides string[] getSpaceballs
{
    get { return new string[] { "abc","def","egh" }; }
}
Run Code Online (Sandbox Code Playgroud)

c#

39
推荐指数
4
解决办法
6万
查看次数

允许的X字节内存大小耗尽

致命错误:允许的内存大小为67108864字节耗尽(尝试分配13965430字节)

PHPInfo显示我有一个128M的memory_limit,所以我很困惑为什么错误说我只有64M.phpinfo是否可能报错?或者为PHP使用两个单独的php.inis?

该错误是由我的一个同事在我不知情的情况下添加的一个主要php文件中的ini_set调用引起的.

php memory memory-management out-of-memory memory-limit

39
推荐指数
4
解决办法
10万
查看次数

在.NET中自行安装Windows服务

我读过这个问题.我有同样的问题,但我不明白lubos hasko的答案.我怎么能这样做?你能有人给我发一个完整的演练吗?

当我在下面运行代码时,安装了一些东西,但是在服务列表中,我找不到它.

我有这个,但这不起作用:

using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{

public class Service1 : ServiceBase
{
    public Service1()
    {
        File.AppendAllText("sss.txt", "ccccc");
    }

    protected override void OnStart(string[] args)
    {
        File.AppendAllText("sss.txt", "asdfasdf");
    }

    protected override void OnStop()
    {
        File.AppendAllText("sss.txt", "bbbbb");
    }


    static void Main(string[] args)
    {
        if (System.Environment.UserInteractive)
        {
            string parameter = string.Concat(args);
            switch (parameter)
            {
                case "--install":
                    ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
                    break;
                case "--uninstall":
                    ManagedInstallerClass.InstallHelper(new …
Run Code Online (Sandbox Code Playgroud)

c# windows-services

39
推荐指数
1
解决办法
4万
查看次数