我有以下代码:
[SuppressMessage( "Microsoft.Performance", "CA1800:DoNotCastUnnecessarily" )]
private static void SetTestConnectionString( Component table )
{
if( table is Object1 )
{
fn1( (Object1)table );
}
// ... a few more if statements for different Classes
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行FxCop此类/函数时,它仍会生成警告
警告:CA1800:Microsoft.Performance:'table',一个参数,在方法'ccc.SetTestConnectionString(Component)'中多次强制输入'xxx'.缓存'as'运算符或直接强制转换的结果,以消除冗余的castclass指令.
我知道我可以重构此代码以删除警告,但是它会降低代码的可读性.在这个例子中,我想在这一个函数上抑制这一条消息.
我究竟做错了什么?
有没有办法使用Rhino Mocks生成Stub IObjectSet<T>?
之后的内容类似于以下代码:
var context = MockRepository.GenerateMock <IContext>();
//generate stub
var mockProjectObjectSet = MockRepository.GenerateStub<IObjectSet<Project>>();
TestObjectSets.GenerateFakeProjectList(mockProjectObjectSet);
context.Expect(p => p.Projects).Return(mockProjectObjectSet);
var projectRepository = new ProjectRepository(context);
Run Code Online (Sandbox Code Playgroud)
在GenerateFakeProjectList静态帮助器方法中,我只是创建指定类型的对象,并通过以下AddObject方法将它们添加到存根IObjectSet:
public static IObjectSet<Project> GenerateFakeProjectList(IObjectSet<Project> projectsObjectSet)
{
projectsObjectSet.AddObject(new Project()
{
Categories = null,
DateCreated = DateTime.Now.AddDays(-10),
.......
Run Code Online (Sandbox Code Playgroud) 我们知道c#中的Array类是抽象的.
但是此类的静态CreateInstance方法返回Array类的对象.
这怎么可能?
void f(string message)
{
string.Format(message,"x",y");
}
Run Code Online (Sandbox Code Playgroud)
f()由g调用:
g()
{
f(SomeJson+"{0}");
}
Run Code Online (Sandbox Code Playgroud)
json中的花括号被解释为string.format()f()中值的占位符.有没有办法让花括号逃脱?
"类型'int'的值不能用作默认参数,因为没有标准转换来键入'Reality.Game.Rooms.RoomActorType'"我的C#.exe中出现了错误.
错误的行:
public RoomActor GetActorByReferenceId(int ReferenceId, RoomActorType ReferenceType = 1)
{
lock (this.mActors)
{
foreach (RoomActor actor in this.mActors.Values)
{
if ((actor.Type == ReferenceType) && (actor.ReferenceId == ReferenceId)) /* line of error */
{
return actor;
}
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这是现实>游戏>房间> RoomActorType.cs:
namespace Reality.Game.Rooms
{
using System;
public enum RoomActorType
{
AiBot = 2,
UserCharacter = 1,
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
只是试验Linq:
DataClassesDataContext db = new DataClassesDataContext();
var q = from p in db.tblBlogEntries select p;
foreach (var customer in q)
{
Response.Write(customer.ID + " " + customer.title + "\n");
}
Run Code Online (Sandbox Code Playgroud)
工作正常,但我似乎只能返回1个字段,或者所有字段.我如何选择说,p.ID而且p.title,没有别的?
我定期收到以下异常.
System.Data.SqlClient.SqlException:超时已过期.操作完成之前经过的超时时间或服务器没有响应.
我已将以下内容添加到我的条件中以增加超时时间.
.SetTimeout(180)
Run Code Online (Sandbox Code Playgroud)
1)有没有办法将其添加到我的nhibernate配置中,以便180是默认时间?
2)增加超时的后果是什么?这会增加或减少死锁的可能性吗?
这是我的PHP代码:
$g = "19/06/2013";
echo $g." // ".date("Y/m/d", strtotime($g))
Run Code Online (Sandbox Code Playgroud)
输出是这19/06/2013 // 1970/01/01而不是.19/06/2013 // 2013/06/19为什么?
为什么会
DateTime.TryParseExact("08/10/2013", "dd/MM/yyyy", null, DateTimeStyles.None, out dateValue)
Run Code Online (Sandbox Code Playgroud)
归还假吗?
如何将变量插入到一段字符串中,并将单引号作为字符串的一部分.
码:
var textMessage = "myText"; //local variable storing text to be injected to string
Run Code Online (Sandbox Code Playgroud)
这是我尝试过但它没有用的:
"//div[contains(@id,'msgError') and contains(text(),'+textMessage+')]" //string where textMessage should be insterted
Run Code Online (Sandbox Code Playgroud)
OUTPUT应该是这样的:
"//div[contains(@id,'msgError') and contains(text(),'myText')]" //Output
Run Code Online (Sandbox Code Playgroud) c# ×8
arrays ×1
date ×1
datetime ×1
fxcop ×1
linq ×1
nhibernate ×1
php ×1
rhino-mocks ×1
string ×1
suppression ×1