我正在使用System.Management.Automation API来调用PowerShell脚本C#WPF应用程序.在下面的示例中,您将如何更改起始目录($ PWD),以便它从C:\ scripts \执行foo.ps1而不是从它调用的.exe的位置?
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
using (Pipeline pipeline = runspace.CreatePipeline())
{
pipeline.Commands.Add(@"C:\scripts\foo.ps1");
pipeline.Invoke();
}
runspace.Close();
}
Run Code Online (Sandbox Code Playgroud) 对于常见的方法类型,C#有一些命名约定:
BeginFoo()/ EndFoo()用于异步方法TryGet()/ TryParse()返回false而不是抛出异常FooOrDefault()对于返回default(T)而不是抛出异常的方法IsFoo 对于布尔标志我想知道,有一个递归的内部方法吗?例如,在此示例中来自另一个Stack Overflow问题:
public int CalculateSomethingRecursively(int someNumber)
{
return doSomethingRecursively(someNumber, 0);
}
// What to call this?
private int doSomethingRecursively(int someNumber, int level)
{
if (level >= MAX_LEVEL || !shouldKeepCalculating(someNumber))
return someNumber;
return doSomethingRecursively(someNumber, level + 1);
}
Run Code Online (Sandbox Code Playgroud)
在CI中,人们使用foo(...)+ foo_r(...)作为惯例.但是在.NET中怎么样?
Dapper可以将查询参数作为匿名对象传递,并支持任何ADO.NET数据提供程序.但是,对Sybase 15 ADO.NET驱动程序运行以下查询时:
using (var connection = new AseConnection("..."))
{
connection.Open();
var results = connection.Query<Foo>(
"dbo.sp_columns", new { table_name = "dbo.sysusers"},
commandType: CommandType.StoredProcedure);
}
Run Code Online (Sandbox Code Playgroud)
...抛出以下错误:
Sybase.Data.AseClient.AseException: Procedure sp_columns expects parameter @table_name, which was not supplied.
at Sybase.Data.AseClient.AseCommand.?(Int32 A_0)
at Sybase.Data.AseClient.AseCommand.?()
at Sybase.Data.AseClient.AseCommand.?(CommandBehavior A_0)
at Sybase.Data.AseClient.AseCommand.System.Data.IDbCommand.ExecuteReader()
at Dapper.SqlMapper.<QueryInternal>d__13`1.MoveNext() in SqlMapper.cs: line 579
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList(IEnumerable`1 source)
at Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in SqlMapper.cs: line 536
Run Code Online (Sandbox Code Playgroud)
将其更改为DynamicParameters使用"@table_name"设置的Dapper …
我已经从mysql切换到Dynamo DB.在mysql中我使用了一个查询来获取更接近特定纬度和经度的所有用户.查询是
SELECT *,SQRT( POW( 69.1 * ( latitude - $latitude) , 2 ) + POW( 69.1 * ( $longitude - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance FROM coupon WHERE is_active='Y' HAVING distance<=$radius
Run Code Online (Sandbox Code Playgroud)
是否可以像在Dynamo DB中创建一个查询.我使用PHP作为我的后端
如何在C#中流畅地配置以下WCF数据服务?
<configuration>
...
<system.serviceModel>
<services>
<service name="Foo.WebServices.FooService">
<endpoint address="http://localhost:8081/PhoenixData"
binding="webHttpBinding"
bindingConfiguration=""
contract="System.Data.Services.IRequestHandler" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)