小编Bal*_*tar的帖子

将System.Linq.IOrderedEnumerable <T>转换为List <T>

.NET编译器不会隐式转换System.Linq.IOrderedEnumerable<T>System.Collections.Generic.List<T>

一个明确的演员:

using System.Collections.Generic;

var items = new List<MyType>;

var selectedItems =
  from item in items
  where item.Active 
  select item;

return (List<MyType>)selectedItems;
Run Code Online (Sandbox Code Playgroud)

发出警告:

Suspicious cast: there is no type in the solution which inherits from both System.Linq.IOrderedEnumerable<MyType> and System.Collections.Generic.List<MyType>
Run Code Online (Sandbox Code Playgroud)

这里的最佳做法是什么

.net c# linq

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

NuGet提供托管选项,包括MyGet

我一直在调查NuGet feed主机的选项.

目前,我们使用TeamCity构建/发布TC的内置服务器包.对于指向TC的Visual Studio包源,我们发现订阅/更新过程非常缓慢 - 即使我们的开发人员工作站位于同一本地子网内,并且我们只有几十个包.

我知道的其他包裹选项:

  1. nw分享
  2. 基于NuGet.Server的内部Web服务器
  3. MyGet
  4. ProGet

有没有人拥有任何这些解决方案的企业级经验?

MyGet看起来非常有前景,但值得关注的是(至少根据他们的网站)只有大约1500个Feed是活跃的.如果MyGet真的流行起来,那似乎应该是150,000左右.

另外:NuGet世界中有什么类似于Maven的本地"快照"包引擎和提要服务器的概念吗?

谢谢.

package nuget nuget-package nuget-server myget

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

如何将驱动器号映射到PowerShell中的本地路径?

在PowerShell中,是否可以将驱动器号映射到本地路径?

所以例如map x:\toc:\myfolder1\myfolder2\

powershell

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

PowerShell Invoke-Expression命令参数包含逗号

密码包含PowerShell特殊字符时,我该怎么办?

Invoke-Expression -Command "net use x: $Path /USER:domain1\user1 7Ui4RT,@T /persistent:no"
Run Code Online (Sandbox Code Playgroud)

这在语法上失败 - 因为PowerShell解释7Ui4RT,@T为数组:

Invoke-Expression -Command "net use x: $Path /USER:domain1\user1 7Ui4RT`,@T /persistent:no"
Run Code Online (Sandbox Code Playgroud)

这在语法上失败 - 显然是因为PowerShell无法解释 7Ui4RT``,@T

Invoke-Expression -Command "net use x: $Path /USER:domain1\user1 "7Ui4RT,@T" /persistent:no"
Run Code Online (Sandbox Code Playgroud)

这失败是因为PowerShell将其解释7Ui4RT,@T为对象而不是字符串(error ="找不到接受参数'System.Object []'的位置参数.").

我该怎么办?

powershell mapped-drive special-characters

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

C#LINQ过滤器IEnumerable <IX>并表示为IEnumerable <X:IX>

显然,这是不可能投WhereEnumerableIterator<IX>IEnumerable<X:IX>

public interface IX 

public class X1 : IX 
public class X2 : IX

public void Method1(IEnumerable<IX> arg)
{
    var filtered = arg.Where(e => e.GetType() == typeof(X2));
    // filtered will be of type WhereEnumerableIterator<IX>
    Method2(filtered as IEnumerable<X2>);
}

public void Method2(IEnumerable<X2> arg) 
{
    // at runtime arg will be null
}
Run Code Online (Sandbox Code Playgroud)

显然,CLR无法投WhereEnumerableIterator<IX>IEnumerable<X2>和集导致空(有点神秘).

似乎合乎逻辑的是,可以应用过滤器IEnumerable<IX>并将结果表示为IEnumerable<X:IX>(实际上没有枚举).

但是怎么做呢?

c# linq ienumerable casting interface

3
推荐指数
1
解决办法
66
查看次数

System.DateTime.ParseExact:无法识别的格式字符串

var timestamp = DateTime.ParseExact("20140101T000000Z", "YYYYMMDDThhmmssZ", CultureInfo.InvariantCulture);

System.FormatException was unhandled by user code
  HResult=-2146233033
  Message=String was not recognized as a valid DateTime.
  Source=mscorlib
Run Code Online (Sandbox Code Playgroud)

这对我来说没有任何意义,因为YYYYMMDDThhmmssZISO-8601 YYYY-MM-DDThh:mm:ssZ删除了特殊格式字符.

.net c# datetime timestamp iso8601

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

如何通过 libgit2sharp 在本地克隆 GitHub 存储库?

我编写了代码,通过 libgit2sharp ( v0.21.0.176 ) 以编程方式将 GitHub 私有存储库克隆到本地存储库

var cloneOptions = new CloneOptions { BranchName = "master", Checkout = true };
var cloneResult = Repository.Clone( @"https://github.com/my-organization/my-repo.git", @"c:\github\my-organization\my-repo" );
Run Code Online (Sandbox Code Playgroud)

抛出异常:

{LibGit2Sharp.LibGit2SharpException: Request failed with status code: 401
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)
   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)
Run Code Online (Sandbox Code Playgroud)

cloneResult 值为空(由于抛出异常而从未设置)

请注意,无论 \my-repo\ 文件夹是否存在,都会抛出相同的 401 异常。

我的函数调用语法正确吗?

从命令行执行,git clone首先创建要克隆到的本地 dir 文件夹。

libgit2sharp 的Repository.Clone()工作方式不同吗?

git github git-clone libgit2sharp

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

GitExtensions 编辑器的 Windows .gitconfig 设置

Windows 7 Git 扩展

GitExtensions安装程序会自动添加一行.gitconfig来指示git使用GitExtensions editor

我的.gitconfig被​​另一个程序更改了,GitExtensions安装程序修复模式不会重新添加设置。

有人可以提供一下吗?

我已经尝试过以下语法,但它是错误的:

[core]
editor =  !\"C:\\Program Files (x86)\\GitExtensions\\GitExtensions.exe\"
Run Code Online (Sandbox Code Playgroud)

windows git editor git-config git-extensions

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

c#结合多个函数的yield return

只有当调用者实际需要该特定枚举元素时,c#yield compute才会延迟循环的每次迭代的执行.是否可以组合多个这样的yield return函数并仍然将动态枚举集暴露给最终调用者?

public IEnumerable<string> GetDelayedCompute1()
{
    // compute ...
    foreach(var s in results)
    {
        yield return s;
    }
}

public IEnumerable<string> GetDelayedCompute2()
{
    // compute ... 
    foreach(var s in results)
    {
        yield return s;
    }
}

public IEnumerable<string> GetResults()
{
    // how to combine results of GetDelayedCompute1 and GetDelayedCompute2
    // and yield return without forcing enumeration
}
Run Code Online (Sandbox Code Playgroud)

c# ienumerable yield concat return

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

写puppet配置来克隆github repo

我写了一个Puppet模块在Windows上安装Git.Puppet Master是Linux.

是否可以使用puppet资源(即没有脚本或exec)编写Puppet清单来克隆GitHub仓库?

这是一个私人仓库,因此解决方案需要包含安全凭证.

windows git puppet git-clone rspec-puppet

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

筛选器链接的语法较短

var fileIO = new FileIO();
var datafiles = _fileIo.GetFileDetails(directory)
   .Where(f => !f.FileName.EndsWith(".csv"))
   .Where(f => !f.FileName.EndsWith(".xls"))
   .Where(f => !f.FileName.EndsWith(".xlsx"));
Run Code Online (Sandbox Code Playgroud)

似乎应该有一种更简洁的语法,该语法允许传递后缀字符串列表。

c# linq

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