我在我的界面上定义了一堆方法,如下所示:
T Map<T>( SomeType someParam );
Run Code Online (Sandbox Code Playgroud)
并实现如下:
public T Map<T>( SomeType someParam )
{
return AutoMapper.Mapper.Map<SomeType, T>( someParam );
}
Run Code Online (Sandbox Code Playgroud)
如何简化我的界面,以便我只有一个方法:
T Map<T>(T someParam);
Run Code Online (Sandbox Code Playgroud)
和
public T Map<T>( T someParam )
{
return AutoMapper.Mapper.Map<T, T>( someParam );
}
Run Code Online (Sandbox Code Playgroud)
但是,当我以这种方式实现它时,我收到有关从SomeType和另一种类型转换的转换错误.这可能与泛型有关,怎么样?
做TDD并希望隔离测试中的方法:Direct();
但是,当测试创建时MyClass,会SomeClass.SetupStuff();爆炸(NotImplementedException).因此,修改IMyClass接口有一个Configure();可以在MyClass构造后调用的方法来避免异常.
问题:这是一种处理这种情况的可接受的方式,还是有一些基本的OOP主体,这打破了?
public class MyClass : IMyClass
{
public MyClass()
{
// class with static method that sets stuff up
SomeClass.SetupStuff();
}
public void IMyClass.Direct()
{
// want to test this
}
}
Run Code Online (Sandbox Code Playgroud)
VS
public class MyClass : IMyClass
{
public MyClass()
{
}
public void IMyClass.Direct()
{
// want to test this
}
//
public void IMyClass.Configure()
{
// class with static method that sets …Run Code Online (Sandbox Code Playgroud) 鉴于以下类:
public class LoginInfo
{
public int UserId;
public string Username;
}
Run Code Online (Sandbox Code Playgroud)
和另一堂课
public class OtherClass
{
public static LoginInfo Info
{
get
{
return SessionBll.GetLoginInfo(someInt);
}
set
{
SessionBll.UpdateLoginInfo(value, someInt);
}
}
}
Run Code Online (Sandbox Code Playgroud)
鉴于此:
OtherClass.LoginInfo.Username = "BillyBob";
Run Code Online (Sandbox Code Playgroud)
LoginInfo当LoginInfo变更属性时,如何调用setter ?我知道我能做到:
LoginInfo info = OtherClass.LoginInfo;
info.Username = "BillyBob";
OtherClass.LoginInfo = info;
Run Code Online (Sandbox Code Playgroud)
但我想在没有这三行的情况下这样做.我希望它是自动的
谢谢
结束订阅LoginInfo类中的事件
我有一个非常简单的页面,其中包含以下逻辑:
protected void Page_Load(object sender, EventArgs e)
{
if (null == Response.Cookies["UserSettings"].Value)
{
HttpCookie cookie = new HttpCookie("UserSettings");
cookie.Value = "The Big C";
cookie.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(cookie);
}
else
{
// got here
}
}
Run Code Online (Sandbox Code Playgroud)
我在the if和the 中都设置了断点,else并且else断点永远不会被击中.该if声明每次都会被击中.这可能有什么问题?
谢谢!
我刚刚意识到我一直在使用实现ICallbackEventHandler(回调)的控件而不了解它们实际做了什么以及它们与更新面板的区别.有人可以帮我理解吗?
谢谢!
什么是CachéObjectScript将参数传递给基础构造函数的方法?
例如,在C#中,您将执行以下操作:
public MyConstructor(string id) : base(id) { }
Run Code Online (Sandbox Code Playgroud)
id您希望传递给基础构造函数的值在哪里.
该文件说,这是允许的:
ClassMethod GetContacts() As %ListOfObjects(ELEMENTTYPE="ContactDB.Contact")
[WebMethod]
Run Code Online (Sandbox Code Playgroud)
我想做这个:
Property Permissions As %ListOfObjects(ELEMENTTYPE="MyPackage.MyClass");
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
错误#5480:未声明属性参数:MyPackage.Myclass:ELEMENTTYPE
那么,我真的必须创建一个新类并为其中的每个列表设置ELEMENTTYPE参数吗?
IsAbstract 似乎不存在。它去哪儿了?
[TestMethod]
public void IsAbstractBaseClass()
{
Type type = typeof(ViewModelBase);
Assert.IsTrue(type.IsAbstract);
}
Run Code Online (Sandbox Code Playgroud) 想要使用新的x:Bind编译时绑定 MVVMLight 和ViewModelLocator类。
如何更改它以使用 x:Bind?
DataContext="{Binding Login, Source={StaticResource Locator}}"
Run Code Online (Sandbox Code Playgroud)
源似乎不受支持,因此失败:
DataContext="{x:Bind Path=Login, Source={StaticResource Locator}}"
Run Code Online (Sandbox Code Playgroud)
又怎样?
无法建立配置文件IEnumerable. Mapper.Initialize需要只运行一次项目中的所有配置文件.尝试设置profiles = new List<Profile>(),但配置文件计数始终为0.
IEnumerable<Profile> profiles = null;
var profileType = typeof(Profile);
var assemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => a.FullName.Contains("Cars.Data"));
foreach (var assembly in assemblies)
{
profiles.Concat(
assembly.GetTypes()
.Where(t => profileType.IsAssignableFrom(t) &&
t.GetConstructor(Type.EmptyTypes) != null)
.Select(Activator.CreateInstance)
.Cast<Profile>());
}
Mapper.Initialize(c => profiles.ForEach(c.AddProfile));
Run Code Online (Sandbox Code Playgroud) c# ×8
asp.net ×2
intersystems ×2
unit-testing ×2
.net ×1
.net-4.0 ×1
.net-4.5 ×1
.net-4.6 ×1
ajax ×1
collections ×1
cookies ×1
generics ×1
mvvm-light ×1
tdd ×1