我正在尝试将T4MVC模板添加到我的项目中,但我遇到了一些问题.我去了Codeplex上,并下载最新版本的T4MVC的,并根据指示,我刚才复制的两个文件T4MVC.tt,并T4MVC.Settings.t4到我的web应用程序的根目录.
我立刻得到了以下错误:
从T4MVC.cs(生成的文件):
命名空间不能直接包含字段或方法等成员
从T4MVC.tt(代码生成模板):
编译转换:找不到类型或命名空间名称'ITextTemplatingEngineHost'(您是否缺少using指令或程序集引用?)
当我打开时T4MVC.cs,它只包含一行:
ErrorGeneratingCode
Run Code Online (Sandbox Code Playgroud)
我发现这篇文章建议再次构建,但该解决方案并不能解决我的问题 - 事实上,它并没有改变一件事.我该怎么办?
我正在尝试将文件读入Fortran程序的内存中.该文件包含N每行中包含两个值的行.这是我目前所做的(它编译和运行,但给我不正确的输出):
program readfromfile
implicit none
integer :: N, i, lines_in_file
real*8, allocatable :: cs(:,:)
N = lines_in_file('datafile.txt') ! a function I wrote, which works correctly
allocate(cs(N,2))
open(15, 'datafile.txt', status='old')
read(15,*) cs
do i=1,N
print *, cs(i,1), cs(i,2)
enddo
end
Run Code Online (Sandbox Code Playgroud)
我希望得到的是加载到变量中的数据cs,第一个索引为行,第二个列为第二列,但是当上面的代码运行时,它首先给出一行带有两个"左列"值的行,然后是一行带有两个"右列"值,然后一行与下两个"左列值"等等.
这是对情况的更直观的描述:
In my data file: Desired output: Actual output:
A1 B1 A1 B1 A1 A2
A2 B2 A2 B2 B1 B2
A3 B3 A3 B3 A3 A4
A4 B4 A4 B4 B3 B4
Run Code Online (Sandbox Code Playgroud)
我已经尝试在分配时切换索引cs,但是具有相同的结果(或段错误,取决于我还在print语句处切换索引).我也尝试逐行读取值,但由于数据文件的格式不规则(以逗号分隔,而不是列对齐),我根本无法使用它. …
我们希望让我们的构建服务器将每个构建的输出发送到
C:\Projects\{project name}\build\{build configuration}\.
为此,我将项目的Build Output路径属性设置为Visual Studio 2010中的属性,并在本地构建以确保一切正常.例如,当我这样做时,visual studio将路径更改为相对路径..\..\build\Debug.
由于项目目录在构建服务器上是不一样的(我们使用TeamCity,因此项目URL有类似C:\ BuildAgent\work\9358A92GF92),输出不会在我们想要的地方结束.
如何使Visual Studio 不将构建输出路径更改为相对路径?
可能重复:
C#:在扩展方法中验证"this"参数的最佳实践
我对设计选择感到矛盾,并希望听到SO社区的意见.我在这里提出的例子只是一个可能的情况,必须进行这种设计选择 - 实际上,可能会有更多的情况.对这个具体案例和更一般的方法都欢迎回答,并且对于如何在特定案例中做出决定的指导方针也表示赞赏.
基本上,我想知道如何考虑这个:当编写一个扩展方法,如果将null引用作为this实例传递,本质上不会失败,是否应该对参数执行null检查?
例:
我正在编写一个扩展方法IEnumerable<T>,它将遍历集合并执行一些Action<T>- 基本上,这就是它的作用:
public static void Each<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var t in collection)
{
action.Invoke(t);
}
}
Run Code Online (Sandbox Code Playgroud)
我无法决定的是,如果null传递给任一参数,这个扩展方法应该做什么.如果我不添加任何空检查,我将得到一个NullReferenceExceptionon action.Invoke(T),但是如果collection是nullfor循环将只是默默地做什么(并且即使action也是null...... 也不会抛出异常).
我决定添加一个空检查action,所以我可以抛出一个ArgumentNullException而不是NullReferenceException.但是我该collection怎么做呢?
选项1:添加空检查,并抛出ArgumentNullException.
选项2:只是默默地让方法什么都不做.
哪个在将来我想要使用该方法会更有用?为什么?
如果我在C#中声明一个接口,有没有什么办法可以显式地声明实现该接口的任何类型都是引用类型?
我想这样做的原因是,无论我在哪里使用接口作为类型参数,我都不必指定实现类型也必须是引用类型.
我想要完成的例子:
public interface IInterface
{
void A();
int B { get; }
}
public class UsingType<T> where T : IInterface
{
public void DoSomething(T input)
{
SomeClass.AnotherRoutine(input);
}
}
public class SomeClass
{
public static void AnotherRoutine<T>(T input)
where T : class
{
// Do whatever...
}
}
Run Code Online (Sandbox Code Playgroud)
由于参数SomeClass.AnotherRoutine()需要是一个引用类型,我将在这里得到一个编译器错误,我调用该方法,建议我强制T成为引用类型(where T : IInterface, class在声明中UsingType).有没有办法可以在接口级别强制执行此操作?
public interface IInterface : class
Run Code Online (Sandbox Code Playgroud)
不起作用(显然)但也许有另一种方法来完成同样的事情?
var until = $("#time").html();
function updateTime() {
$("#time").html(
date("d", until) + " day(s)<br />" +
date("h", until) + " hour(s)<br />" +
date("i", until) + " minute(s)<br />" +
date("s", until) + " second(s)"
);
}
setInterval("updateTime(until)",1000);
Run Code Online (Sandbox Code Playgroud)
每次我运行这个,我都会收到此错误:
未捕获的ReferenceError:直到未定义(匿名函数)
我看不出什么是错的.我试图谷歌很多,但我找到的每一页都说setInterval()是对的.
我有一个gradle构建脚本,其中包含一些源集,这些源集都定义了各种依赖项(一些常见,一些没有),我正在尝试使用Eclipse插件让Gradle 为Eclipse 生成.project和.classpath文件,但我不能弄清楚如何获取所有依赖项.classpath; 由于某种原因,实际上添加了很少的外部依赖项.classpath,因此Eclipse构建失败并出现1400错误(使用gradle构建工作正常).
我已经定义了我的源集:
sourceSets {
setOne
setTwo {
compileClasspath += setOne.runtimeClasspath
}
test {
compileClasspath += setOne.runtimeClasspath
compileClasspath += setTwo.runtimeClasspath
}
}
dependencies {
setOne 'external:dependency:1.0'
setTwo 'other:dependency:2.0'
}
Run Code Online (Sandbox Code Playgroud)
由于我没有使用main源集,我认为这可能与它有关,所以我补充说
sourceSets.each { ss ->
sourceSets.main {
compileClasspath += ss.runtimeClasspath
}
}
Run Code Online (Sandbox Code Playgroud)
但这没有帮助.
我无法弄清楚所包含的库的任何常见属性,或者那些没有的库的常见属性,但我找不到任何我确定的东西(虽然当然必须有一些东西).我有一种感觉,所有包含的库都是test源集的依赖关系,无论是直接还是间接,但我还没有能够验证是否存在所有test的依赖关系.
如何确保放入所有源集的依赖项.classpath?
我在ASP.NET Web API项目中的控制器上有以下操作方法:
[Route("api/v2/project/{projectId}/stuff"), HttpGet]
public IHttpActionResult Get(int projectId)
[Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpGet]
public IHttpActionResult Get(int projectId, [FromUri] Guid id)
[Route("api/v2/project/{projectId}/stuff"), HttpPost]
public IHttpActionResult Post(int projectId, [Required] Stuff stuff)
[Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpPut]
public IHttpActionResult Put(int projectId, [FromUri] Guid blastId, Stuff stuff)
[Route("api/v2/project/{projectId}/stuff/{id:guid}"), HttpDelete]
public IHttpActionResult Delete(int projectId, [FromUri] Guid id)
Run Code Online (Sandbox Code Playgroud)
由于javascript错误,我提出了DELETE请求
api/v2/project/1234/stuff/undefined
Run Code Online (Sandbox Code Playgroud)
即,而不是一个GUIDid,我得到了字符串"undefined".据我所知,这不应该与我的任何路线相匹配,但是我得到了一个响应而不是404 Not found(甚至405 Method not allowed)200 OK.
我在每个动作方法中设置了一个断点,并使用Fiddler重复请求,但没有一个断点被击中.我也尝试从nuget安装WebApiRouteDebugger软件包,但我们正在使用一个自定义控制器工厂,它通过我的DI容器挂钩,所以我根本无法使用它.我甚至尝试从我的全球注册过滤器中抛出以下异常:
throw new Exception(actionContext.ControllerContext.ControllerDescriptor.ControllerName +
" " + actionContext.ActionDescriptor.ActionName);
Run Code Online (Sandbox Code Playgroud)
但DELETE请求 …
我正在尝试.ps1使用自签名证书签名(用例是我自己在私人开发站写的脚本,所以不需要使用 - 或支付 - 真正的CA).但是,无论我阅读的证书生成和数字签名主题有多少指南,我似乎无法让它工作.
这是我迄今为止所取得的成就:
# Create a certificate to use as trusted root of the signing chain
$root = New-SelfSignedCertificate `
-Subject "CN=PowerShell Trusted Authority" `
-FriendlyName "PowerShell Trusted Authority" `
-KeyUsageProperty Sign `
-KeyUsage CertSign, CRLSign, DigitalSignature `
-CertStoreLocation Cert:\LocalMachine\My\ `
-NotAfter (Get-Date).AddYears(10)
# Create a certificate to use for signing powershell scripts
New-SelfSignedCertificate `
-Signer $root `
-Subject "CN=PowerShell Code Signing" `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-Type CodeSigningCert `
-CertStoreLocation Cert:\LocalMachine\My\
# …Run Code Online (Sandbox Code Playgroud) 考虑以下ConfigMap定义,例如foo.yml:
apiVersion: v1
kind: ConfigMap
metadata:
name: foo-data
data:
foo.json: |-
{
"foo": "foo",
"bar": 42
}
Run Code Online (Sandbox Code Playgroud)
有没有办法foo.json从外部文件加载数据,而不是在模板中内联它?如果我可以将数据放在foo.json旁边的文件中foo.yml,以某种方式引用它,并在我应用模板时让 K8s 计算出来,那就太好了。
那可能吗?如何?
如果不是,路线图上的功能是什么?
c# ×2
asp.net ×1
asp.net-mvc ×1
build ×1
file-io ×1
fortran ×1
generics ×1
gradle ×1
interface ×1
io ×1
javascript ×1
jquery ×1
kubernetes ×1
null ×1
powershell ×1
routing ×1
self-signed ×1
t4 ×1
t4mvc ×1
teamcity ×1