我有以下界面
public interface IHandler<T>
{
void Handle(T myObject);
}
Run Code Online (Sandbox Code Playgroud)
我希望有一个HandlersManager类,它包含对象类型与相应处理程序之间的映射,但我不确定我应该如何定义保存此映射的对象.
例如,我想要的是:
typeof(string) --> instance of IHandler<string>
typeof(MyClass) --> instance of IHandler<MyClass>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我得到的最好的事情是Dictionary<Type, object>为映射定义,但在这种情况下,我必须在IHandler<T>每次获取它时将值转换为值.
有没有更好的解决方案或我完全错过的东西?
我有两个测试类,MyFirstTest和MySecondTest.独立运行每个工作正常.当我同时运行时(在eclipse中选择包含这些文件的测试文件夹,右键单击,以junit运行),MySecondTest失败,因为MyClass在运行其测试时仍然被模拟.MyFirstTest需要模拟MyClass.MySecondTest要求MyClass不被嘲笑.我认为tearDownMocks假设"移除"类.
public class MyFirstTest {
@Before
public void setUp() throws Exception {
Mockit.setUpMocks(MockMyClass.class);
}
@After
public void tearDown() throws Exception {
Mockit.tearDownMocks(MockMyClass.class);
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
Mockit.tearDownMocks(MockMyClass.class);
}
@MockClass(realClass = MyClass.class, stubs = "<clinit>")
public static class MockMyClass {
...
public class MySecondTest {
Run Code Online (Sandbox Code Playgroud) LINQ to Entities中有以下查询:
var query = from p in db.Products
where p.Price > 10M
select p;
Run Code Online (Sandbox Code Playgroud)
此时查询尚未执行,我想编写一个基于某些条件返回true/false的查询:
return query.Any(p => p.IsInStock &&
(p.Category == "Beverage" ||
p.Category == "Other"));
Run Code Online (Sandbox Code Playgroud)
这很好用; 但是,我想从我的代码中重用一些东西.我有很多方法需要根据类别是饮料还是其他来过滤,所以我尝试创建一个委托:
Func<Product, bool> eligibleForDiscount = (product) => product.Category == "Beverage" || product.Category == "Other";
Run Code Online (Sandbox Code Playgroud)
我想用代表替换内联检查:
return query.Any(p => p.IsInStock && eligibleForDiscount(p));
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误,说LINQ to Entities不支持Invoke.为什么我不能将内联代码替换为这样的委托,有什么方法可以通过其他方式实现我的重用?
我正在使用Web客户端.并通过Web客户端成功登录.但是当我发送第二个获取数据的请求时.我有一个例外
com.gargoylesoftware.htmlunit.UnexpectedPage@6d8d73`
Run Code Online (Sandbox Code Playgroud)
但是当我通过url thruogh brouser时,我得到了一个数据Json格式.
码:
webClient.getPage("http://ajax/stream/refresh-box?r=new&id=2323222&")
Run Code Online (Sandbox Code Playgroud)
Thx在先进
有谁知道如何让R包VennDiagram根据设定的大小来缩放包含3个相交集的维恩图的圆圈?
我可以通过venneular包实现这种扩展,但我发现与VennDiagram相比,其他图形选项有点受限.
VennDiagram包文档建议将参数'scaled'设置为TRUE应该可以做到这一点,但我发现这会产生3个相同大小的圆.
包文档确实以密码形式表明缩放参数可能仅适用于某些图:
?draw.triple.venn
Run Code Online (Sandbox Code Playgroud)
揭示了:
scaled:"布尔值,指示是否根据设置的尺寸缩放某些欧拉图中的圆形尺寸"
和
?venn.diagram
#Argument Venn Sizes Class Description
#scaled 2, 3 logical Enable scaling for two-set and certain three-set Euler diagrams.
Run Code Online (Sandbox Code Playgroud)
我的代码的玩具示例:
require(VennDiagram)
venn.plot <- draw.triple.venn(
area1 = 70,
area2 = 250,
area3 = 500,
n12 = 30,
n23 = 60,
n13 = 10,
n123 = 5,
category = c("C1", "C2", "C3"),
fill = c("blue", "red", "green"),
scaled=TRUE)
tiff(filename = "test.tiff", compression = "none",type = "quartz",antialias = "none")
grid.draw(venn.plot)
dev.off()
Run Code Online (Sandbox Code Playgroud)
类似地,使用'venn.diagram'函数的代码不会产生所需的缩放:
venn.diagram(x=list(A=c(1:15,16:20), B=c(6:15,21:30,100:150), C=c(11:30,200:300)), …Run Code Online (Sandbox Code Playgroud) 当我尝试创建类似的类时
type MyType () =
let func<'T> () = ()
Run Code Online (Sandbox Code Playgroud)
编译器说有错误:
显式类型参数只能用于模块或成员绑定
但是MSDN说:
模块级别,类型或计算表达式中的let绑定可以具有显式类型参数.表达式中的let绑定(例如在函数定义中)不能具有类型参数.
为什么文档和编译器说不同的东西?
我需要使用dropwizard项目实现websocket.但是我无法找到任何与之相关的文件.任何人都可以指出相同的资源.
我有以下丑陋的代码:
if (msg == null ||
msg.Content == null ||
msg.Content.AccountMarketMessage == null ||
msg.Content.AccountMarketMessage.Account == null ||
msg.Content.AccountMarketMessage.Account.sObject == null) return;
Run Code Online (Sandbox Code Playgroud)
有没有办法在C#中检查空值,以便我不必检查每个单独的级别?
我有一个水平形式的表单组.在此表单组中,右侧元素高于左侧元素.出于这个原因,我想将左侧元素垂直居中于其行中.例如:
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email1</label>
<div class="col-sm-10"> <!-- higher element -->
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
<br>Random stuff
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email2</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
Email1目前显示在其自己行的顶部,如此plunker片段中所示.
编辑:所以为了澄清我的意图,这是目前的状态:

这就是我想要的(蓝色区域是前面提到的"行"):

我正在使用以下代码进行反向地理编码
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
curLoc=newLocation;
if (curLoc != nil) {
latitude=curLoc.coordinate.latitude;
longitude=curLoc.coordinate.longitude;
//[self loadMap:latitude second:longitude];
[self MarkerPoint:latitude+0.04 second:longitude+0.1 third:latitude-0.04 forth:longitude-0.1];
NSError *error;
NSString *lookupString = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude,longitude]];
NSLog(@"URL: %@",lookupString);
lookupString = [lookupString stringByReplacingOccurrencesOfString:@" " withString:@"+"];
NSData *jsonResponse = [NSData dataWithContentsOfURL:[NSURL URLWithString:lookupString]];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonResponse options:kNilOptions error:&error];
self.locationArray = [[jsonDict valueForKey:@"results"] valueForKey:@"formatted_address"];
int total = self.locationArray.count;
NSLog(@"locationArray count: %d", self.locationArray.count);
for (int i = 0; i < total; i++)
{
NSString *statusString = …Run Code Online (Sandbox Code Playgroud) .net ×3
c# ×3
generics ×2
java ×2
dictionary ×1
dropwizard ×1
f# ×1
forms ×1
geocoding ×1
http-unit ×1
ios ×1
jmockit ×1
objective-c ×1
r ×1
reverse ×1
valign ×1
venn-diagram ×1
webclient ×1
websocket ×1