所以我一直在阅读我不应该编写自己的CSV读写器,所以我一直在尝试使用通过nuget安装的CsvHelper库.CSV文件是灰度图像,行数是图像高度,数字列是宽度.我想将行值逐行读入单个List<string>或List<byte>.
我到目前为止的代码是:
using CsvHelper;
public static List<string> ReadInCSV(string absolutePath)
{
IEnumerable<string> allValues;
using (TextReader fileReader = File.OpenText(absolutePath))
{
var csv = new CsvReader(fileReader);
csv.Configuration.HasHeaderRecord = false;
allValues = csv.GetRecords<string>
}
return allValues.ToList<string>();
}
Run Code Online (Sandbox Code Playgroud)
但是allValues.ToList<string>()扔了一个:
用户代码未处理CsvConfigurationException
CsvHelper.dll中出现"CsvHelper.Configuration.CsvConfigurationException"类型的异常,但未在用户代码中处理
附加信息:继承IEnumerable的类型无法自动映射.您是否意外调用了对单个记录执行操作的GetRecord或WriteRecord,而不是调用作为记录列表的GetRecords或WriteRecords?
GetRecords可能期望我自己的自定义类,但我只是想将值作为一些原始类型或字符串.此外,我怀疑整行正在转换为单个字符串,而不是每个值都是一个单独的字符串.
在xUnit中,我可以Theory使用以下形式的泛型:
[Theory]
[MemberData(SomeScenario)]
public void TestMethod<T>(T myType)
{
Assert.Equal(typeof(double), typeof(T));
}
public static IEnumerable<object[]> SomeScenario()
{
yield return new object[] { 1.23D };
}
Run Code Online (Sandbox Code Playgroud)
这将给我通用T参数as double.是否可以使用MemberData为具有以下签名的测试指定泛型类型参数:
[Theory]
[MemberData(SomeTypeScenario)]
public void TestMethod<T>()
{
Assert.Equal(typeof(double), typeof(T));
}
Run Code Online (Sandbox Code Playgroud)
如果无法使用MemberData或任何其他提供的属性(我怀疑它不是),是否可以为Xunit创建一个可以实现此目的的属性?也许类似于在Scenarios方法中指定类型并使用与Jon Skeet的答案类似的方式使用反射:C#中的泛型,使用变量的类型作为参数
我有一个类Vector3D具有的属性X,Y和Z类型的双(它也有其它性能如Magnitude).
使用Fluent Assertions以给定精度近似比较所有属性或属性选择的最佳方法是什么?
目前我一直在这样做:
calculated.X.Should().BeApproximately(expected.X, precision);
calculated.Y.Should().BeApproximately(expected.Y, precision);
calculated.Z.Should().BeApproximately(expected.Z, precision);
Run Code Online (Sandbox Code Playgroud)
是否有单线方法可以实现相同的目标?比如使用ShouldBeEquivalentTo,或者这是否需要构建允许包含/排除属性的通用扩展方法?
在 SonarAnalyzer.CSharp Nuget 包上,它具有描述:
发现代码中的错误和代码异味的分析器。此包最好与用于 Visual Studio ( http://vs.sonarlint.org ) 和/或 SonarQube 平台 ( http://www.sonarqube.org )的 SonarLint一起使用。
我知道 SonarLint 是 VisualStudio 的插件,因此它的规则集会自动应用于在 VisualStudio 中打开的每个项目。但是,如果我将 SonarAnalyzer.CSharp Nuget Package 安装到项目中,SonarLint 会为我提供更多功能,还是它们只是提供相同 Roslyn 规则的两种方式?
我正在尝试让.Net Framework和NetStandard程序集相互通信(以了解可能的内容).我目前有四个项目,两个Framework 4.5.2项目和两个NetStandard1.2项目:
Framework452.LibraryNetStandard12.CentralLibraryNetStandard12.BaseLibraryFramework452.Tests引用结构是:
Framework452.Tests参考NetStandard12.CentralLibrary:通过添加NetStandard.Library nuget包来工作Framework452.Tests.NetStandard12.CentralLibrary参考NetStandard12.BaseLibrary:无需修改即可工作.NetStandard12.CentralLibrary参考Framework452.Library:不工作,即使Framework452.Library安装了NetStandard.Library nuget包.NetStandard项目可以参考Framework项目吗?如果是这样,我需要做些什么才能让他们进行沟通?目前我可以添加引用,但代码不可见.
更新
我重新创建了解决方案并添加了下面的代码,当我尝试编译时,从Framework452.Tests项目中给出以下错误:
错误CS0006:找不到元数据文件'〜\ TryNETStandard\NetStandard12.CentralLibrary\bin\Debug \netstandard1.2\NetStandard12.CentralLibrary.dll'.
namespace Framework452.Library
{
public class Returner452 {
public static bool ReturnTrue() { return true; }
}
}
using Xunit;
namespace Framework452.Tests
{
public class Class1 {
[Fact]
public void FrameworkTest() {
Assert.True(NetStandard12.CentralLibrary.Class1.Return452());
}
[Fact]
public void NetStandardTest() {
Assert.True(NetStandard12.CentralLibrary.Class1.Return12());
}
}
}
namespace NetStandard12.BaseLibrary
{
public …Run Code Online (Sandbox Code Playgroud) 我有一个方法正在接受Action<string>(参见下面的简单示例),但是在Action构造它的调用方法中,Resharper建议应该使用本地函数.
有关使用本地功能代替操作的建议做法是什么,是否重要,或者是否有必要注意?
public void Caller()
{
string holder;
Action<string> act = s => holder = s;
void SetHolder(string s) => holder = s;
DoStuff(act);
DoStuff(SetHolder);
}
public void DoStuff(Action<string> setHolder)
{
setHolder("holders new string");
}
Run Code Online (Sandbox Code Playgroud) 是否有用于 Node-RED 项目的标准或推荐的 .gitignore 文件?或者是否有应该忽略的文件或文件夹?例如,像.config.json或flow_cred.json这样的文件应该被忽略吗?
目前我正在使用gitignore.io生成的 Node 模板(见下文),但这不包含任何特定于 Node-RED 的内容。
我发现这些带有 .gitignore 文件的 github 项目:
但我不确定这些是否适用于任何 Node-RED 项目。
节点 .gitignore 文件:
# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov …Run Code Online (Sandbox Code Playgroud) 我有一个包含textarea元素的div。div的大小是固定的,但是如果输入了足够的文本,则会显示滚动条。当前,textarea高度会动态正确地增长和缩小,但宽度不会正确增长。
我一直在修改此处给出的代码:http ://alistapart.com/article/expanding-text-areas-made-elegant,并且到此为止(显示在jsfiddle中):http : //jsfiddle.net/fayu5sh2/ 2 /
当前的工作方式是将textarea设置为div的宽度和高度的100%,并将其内容输入到一个隐藏的跨度中,该跨度会更改包含div的高度(按Enter时)和宽度。尽管跨度正常运行,但文本区域无法保持宽度:100%。是否有可能做到这一点?
当前可以看到隐藏的跨度以显示其内容在做什么,textarea中的文本应直接位于跨度中的文本上方。
这是html:
<div id="containing_box">
<div class="expandingArea">
<pre><span></span><br></pre>
<textarea></textarea>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是JavaScript:
$(document).ready(
function() {
$('div.expandingArea').each(function() {
var area = $('textarea', $(this));
var span = $('span', $(this));
area.bind('input', function() {
span.text(area.val());
});
span.text(area.val());
$(this).addClass('active');
});
}
);
Run Code Online (Sandbox Code Playgroud)
和CSS:
#containing_box {
width: 300px;
height: 200px;
overflow: auto;
border: 1px solid;
}
textarea,
pre, p {
margin: 0;
padding: 0;
outline: 0;
border: 0;
}
.expandingArea {
position: relative;
border: 1px solid #888; …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×1
attributes ×1
c#-7.0 ×1
css ×1
csv ×1
csvhelper ×1
frameworks ×1
generics ×1
gitignore ×1
html ×1
javascript ×1
jquery ×1
node-red ×1
node.js ×1
sonarlint ×1
sonarlint-vs ×1
unit-testing ×1
xunit ×1