我需要使用反射设置类的属性.
我有一个Dictionary<string,string>属性名称和字符串值.
在反射循环中,我需要在为每个属性设置值时将字符串值转换为适当的属性类型.其中一些属性类型是可空类型.
编辑: 此博客评论中定义的第一个方法似乎也可以解决这个问题:http: //weblogs.asp.net/pjohnson/archive/2006/02/07/437631.aspx
Rhino Mocks存根和模拟只对接口有用,而不是具体的类吗?我花了很多时间试图让这段代码工作.我没想到存根的pubSubClient总是从类中调用Send方法.该方法有一些依赖项并抛出异常.
[Test]
public void Test01()
{
PubSubMessage psm = new PubSubMessage();
var pubSubClient = MockRepository.GenerateStub<PubSubClient>();
pubSubClient.Stub(x => x.Send(psm)).IgnoreArguments().Return(null);
// actual PubSubClient Send method throws exception
// the rest of the test is skipped...
}
Run Code Online (Sandbox Code Playgroud)
但是,当我提取界面并使用IPubSubClient运行相同的测试时,它似乎按预期工作.
这是否意味着我必须为我想要使用Rhino模拟/存根的每个类提取接口?或者我在技术上或概念上遗漏了什么?
更新:好的,我似乎弄清楚了我缺少的部分: Rhino Mocks无法拦截对非虚方法的调用.所以,我想我要么使用接口,要么在具体类虚拟上使用每个方法.如果还有其他选择,请纠正我.
如何将MembershipProvider类添加到VS 2010 B2中的.NET 4.0项目?
我想自定义MembershipProvider,但我不能不添加这个类.请指导我完成这个过程.
我在Heroku上使用Devise有一个Rails 3应用程序.问题是我正在发送带有Sendgrid的电子邮件,而且电子邮件递送速度很慢,这会让应用程序挂起.所以我有兴趣使用delayed_job在后台排队电子邮件,因此我的应用程序响应用户.
Devise如何与delayed_job一起使用?设置Devise以使用delayed_job的任何方法?
如何删除Elmah在服务器上生成的日志文件?
Elmah中是否有可用于删除日志文件的设置?我更愿意指定一些标准(例如,超过30天的日志文件).
或者我应该为此编写自己的代码?
我有这个代码:
using System.Configuration;
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
string ErrorMessage = ex.Message;
string StackTrace = ex.StackTrace;
string ExceptionType = ex.GetType().FullName;
string UserId = Getloggedinuser();
string WebErrorSendEmail =
ConfigurationManager.AppSettings["WebErrorSendEmail"];
// save the exception in DB
LogStuffInDbAndSendEmailFromDb();
}
Run Code Online (Sandbox Code Playgroud)
这是(大部分)我的代码.在一小部分情况下,我没有得到足够的信息.我不知道异常起源于哪个页面.
如何获取与异常源自的页面相关的任何信息?
以下是最短消息的示例:
Base-64 char数组的长度无效.
在System.Web上的System.Web.UI.ObjectState.mat.UI.Object.UI.ObjectState.Formatter. System.Web.UI.HiddenFieldPageStatePersister.Load()中的.UI.Util.DeserializeWithAssert(IStateFormatter formatter,String serializedState)
我刚刚开始一个类来处理与TCP服务器的客户端连接.这是我到目前为止编写的代码:
Imports System.Net.Sockets
Imports System.Net
Public Class Client
Private _Socket As Socket
Public Property Socket As Socket
Get
Return _Socket
End Get
Set(ByVal value As Socket)
_Socket = value
End Set
End Property
Public Enum State
RequestHeader ''#Waiting for, or in the process of receiving, the request header
ResponseHeader ''#Sending the response header
Stream ''#Setup is complete, sending regular stream
End Enum
Public Sub New()
End Sub
Public Sub New(ByRef Socket As Socket)
Me._Socket = Socket
End Sub
End Class …Run Code Online (Sandbox Code Playgroud) 我有字典拿着我的书:
Dictionary<string, book> books
Run Code Online (Sandbox Code Playgroud)
预定定义:
class book
{
string author { get; set; }
string title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我在字典里添加了一些书.
如何检查词典中是否有与用户提供的标题相匹配的书?
当我编写以下代码时,注释器告诉我BrowserSelector在第二个typedef中没有定义:
/**
* @typedef {{name: String, minVer: Number, maxVer: Number}} BrowserSelector
*/
/**
* @typedef {{type:String, browser: BrowserSelector, attribute: Object}} Selector
*/
Run Code Online (Sandbox Code Playgroud)
我认为它没有将类型与名称相关联.我怎样才能做到这一点?
我不想为它添加实际代码,只是jsdoc注释.
运行此代码:
_foo = MockRepository.GenerateStub<IBar>();
_foo.Stub(x => x.Foo()).Return("sdf");
Run Code Online (Sandbox Code Playgroud)
什么时候
public interface IBar
{
string Foo();
}
public class Bar : IBar
{
public string Foo()
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
抛出NotSupportedException - "无法创建密封类的模拟".我明白为什么你不能模拟一个密封的类(虽然在TypeMock中有解决方案),但是模拟一个返回密封类(字符串)的类有什么问题?
c# ×5
asp.net ×2
mocking ×2
rhino-mocks ×2
.net ×1
.net-4.0 ×1
asp.net-mvc ×1
byref ×1
byval ×1
contains ×1
devise ×1
dictionary ×1
elmah ×1
global-asax ×1
heroku ×1
javascript ×1
jsdoc ×1
reflection ×1
sealed ×1
stub ×1
stubbing ×1
unit-testing ×1
vb.net ×1
webstorm ×1