我有一个问题,正确处理我正在为一个项目编写的DAO库的返回.这个库可能会被其他人使用,我想要正确地使用它.我应该如何处理DAO功能的返回声明?
示例1 我有getCustomer函数应该返回String.如果查询没有返回任何结果,我应该返回null,空字符串或抛出某种异常?
示例2
我有一个函数,getCutomerList它返回ArrayList <String>类型的值.如果查询没有返回任何结果我应该返回null,一个空的ArrayList或抛出一些异常?
示例3
检测到一些SQL异常,我应该怎么做,抛出异常或执行可能发生的块的try..catch
在我的案例中适用的"好"做法或"最佳"做法是什么?
我正在尝试创建并配置Message Inspector以执行WCF Rest HTTP请求的某些身份验证.我正在使用4.0,所以我试图避开WCF入门套件,尽管我已经设法让我的旧RequestInterceptor以我想要的方式工作.使用RequestInterceptor的问题是我丢失了WebHttpBehavior提供的automaticFormatSelectionEnabled功能,我真的想保留它.
所以我的问题是如何配置Message Inspector,我仍然使用WebHttpBehavior并保留它的功能.
我的web.config看起来像这样
<standardEndpoints>
<webHttpEndpoint>
<!-- the "" standard endpoint is used by WebServiceHost for auto creating a web endpoint. -->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
<!-- Disable the help page for the directory end point-->
<standardEndpoint name="DirectoryEndpoint"/>
</webHttpEndpoint>
</standardEndpoints>
Run Code Online (Sandbox Code Playgroud) 我有这个奇怪的问题.在调试时,我有时候代码看起来像这样
<?php
$var = 15;
die($var);
Run Code Online (Sandbox Code Playgroud)
die() 功能有效,但没有输出
但是,这一个有效
<?php
$var = 15;
die($var."<-");
Run Code Online (Sandbox Code Playgroud)
http://sandbox.phpcode.eu/g/81462.php
这怎么可能?我错过了什么?还是错误?
我已经设置了我的行为,以便在成功运行构建时,Xcode将打开一个自定义调试窗口.我希望在运行完成时关闭此窗口,但是我看不到这个选项.我能管理的最好的方法是将焦点返回到我的主窗口而不关闭调试窗口.
我有两个显示器设置,大部分时间使用第二个显示器为Xcode组织器.显然,在运行应用程序时,调试窗口对我来说更有用,但是我想让我的组织者重新回到顶层.
Xcode 4.1中是否存在"关闭标签"行为或类似行为?
谢谢
更新:
只是说我已向Apple提交了功能请求.由于大多数其他行为都有显示/隐藏的选项(一个弹出菜单),因此看起来这也应该是标签/窗口的一个选项.
我正在寻找暂时禁用d3库提供的缩放功能的可能性.我尝试在停用缩放时保存洞穴当前缩放/平移值,并在再次激活缩放时设置缩放/平移值.不幸的是,这不起作用.
这是我创建的代码示例:
var savedTranslation = null;
var savedScale = null;
var body = d3.select("body");
var svg = body.append("svg");
var svgContainer = svg.append("svg:g");
var circle = svgContainer.append("svg:circle")
.attr('cx', 100)
.attr('cy', 100)
.attr('r',30)
.attr('fill', 'red');
circle.on('click', clickFn);
function clickFn(){
if (circle.attr('fill') === 'red'){
circle.attr('fill','blue')
}
else if (circle.attr('fill') === 'blue'){
circle.attr('fill','red')
}
};
svg.call(zoom = d3.behavior.zoom().on('zoom', redrawOnZoom)).on('dblclick.zoom', null);
function redrawOnZoom(){
if (circle.attr('fill') === 'red'){
if (savedScale !== null){
zoom.scale(savedScale)
savedScale = null
}
if (savedTranslation !== null){
zoom.translate(savedTranslation)
savedTranslation = null
} …Run Code Online (Sandbox Code Playgroud) class Program
{
static void Main(string[] args)
{
string value = "12345";
Type enumType = typeof(Fruits);
Fruits fruit = Fruits.Apple;
try
{
fruit = (Fruits) Enum.Parse(enumType, value);
}
catch (ArgumentException)
{
Console.WriteLine(String.Format("{0} is no healthy food.", value));
}
Console.WriteLine(String.Format("You should eat at least one {0} per day.", fruit));
Console.ReadKey();
}
public enum Fruits
{
Apple,
Banana,
Orange
}
}
Run Code Online (Sandbox Code Playgroud)
如果您执行上面的代码,结果显示:
你应该每天至少吃一个12345.
我真的希望在传递未知名称(字符串)时抛出ArgumentException.仔细查看Enum.Parse定义可以看出:
摘要:
将一个或多个枚举常量的名称或数值的字符串表示形式转换为等效的枚举对象.异常:
ArgumentException:enumType不是枚举. - 或 - 值是空字符串或仅包含空格.- 或 - value是一个名称,但不是为枚举定义的命名常量之一.
即,如果传递整数的字符串表示,则创建新的枚举值,并且现在设计引发异常.这有意义吗?
至少我现在知道在Enum.IsDefined(enumType, …
我们在我们的应用程序和窗口中使用MVVM模式,我们有两个TreeView允许从第一个树中拖动项目并将其放在第二个树上.为了避免代码落后,我们使用行为绑定对ViewModel的拖放.
该行为实现非常类似于此示例,并且像魅力一样工作,有一个错误.
场景是一个比显示它的窗口大的树,因此它有一个垂直滚动条.当选择一个项目并且用户想要滚动时,程序开始拖放(这会阻止实际滚动,因此不是我们想要的).
由于滚动条包含在TreeView控件中,因此这并不奇怪.但是我无法确定鼠标是否在滚动条上方.
将TreeViewItems通过主题使用边框,面板等为代表,所以一个简单的InputHitTest并不像人们想象的那么简单.
有没有人遇到过同样的问题?
如果需要更多代码覆盖问题,我可以粘贴.xaml中的一些行.
编辑
合并Nikolays链接我使用IsMouseOverScrollbar方法解决了问题,如果将来有人遇到此问题,必须通过以下方式更改上面的代码:
private static void PreviewMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed || startPoint == null)
return;
if (!HasMouseMovedFarEnough(e))
return;
if (IsMouseOverScrollbar(sender, e.GetPosition(sender as IInputElement)))
{
startPoint = null;
return;
}
var dependencyObject = (FrameworkElement)sender;
var dataContext = dependencyObject.GetValue(FrameworkElement.DataContextProperty);
var dragSource = GetDragSource(dependencyObject);
if (dragSource.GetDragEffects(dataContext) == DragDropEffects.None)
return;
DragDrop.DoDragDrop(
dependencyObject, dragSource.GetData(dataContext), dragSource.GetDragEffects(dataContext));
}
private static bool IsMouseOverScrollbar(object sender, Point …Run Code Online (Sandbox Code Playgroud) 所以今天我正在创建一个表单,并且恰好在foreach循环中给出一个与后来使用的名称相同的变量名.令我惊讶的是,foreach循环的声明覆盖了变量的先前声明.
对我来说,这似乎很奇怪,因为我期望as $value => $a将两个变量的范围限制为foreach循环.
这是发生的事情:
php > $a = 5;
php > $b = array(1,2,3);
php > foreach($b as $value => $a){ echo $a; };
123
php > echo $a;
3
Run Code Online (Sandbox Code Playgroud)
这是我的预期:
php > $a = 5; //define a in outer scope
php > $b = array(1,2,3);
php > foreach($b as $value => $a){ echo $a; /* This $a should be the one from the foreach declaration */ };
123
php > echo $a; //expecting …Run Code Online (Sandbox Code Playgroud) 我无法理解为什么,在Ruby中, Array#slice并且Array#slice!行为Array#sort与Array#sort!(和一种方式在新数组上返回结果而另一种在当前对象上工作的方式)不同.
使用sort第一个(没有爆炸),返回当前数组的排序副本,并对当前数组进行sort!排序.
slice,返回具有指定范围的Array,并从当前对象中slice! 删除指定的范围.
这样做的原因是什么,Array#slice!而不是使当前对象成为具有指定范围的数组?
例:
a = [0,1,2,3,4,5,6,7,8,9]
b = a.slice( 2,2 )
puts "slice:"
puts " a = " + a.inspect
puts " b = " + b.inspect
b = a.slice!(2,2)
puts "slice!:"
puts " a = " + a.inspect
puts " b = " + b.inspect
Run Code Online (Sandbox Code Playgroud)
输出:
slice:
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] …Run Code Online (Sandbox Code Playgroud) ${var:?}Ash、Dash 或 Bash、Zsh以不同的方式处理此处文档中的无效空参数扩展错误。
下面是experiment.sh使用真正的 POSIX 语法的代码:
#!/usr/bin/env sh
empty_var=
read -r value << EOF
Expected fail here ${empty_var:?}"
EOF
printf '$?=%d\nvalue=%s\n' $? "$value"
Run Code Online (Sandbox Code Playgroud)
下面是使用不同 shell 运行实验的代码:
for sh in ash bash dash ksh zsh; do
printf 'Testing with: %s\n' "$sh"
LC_ALL=C "$sh" ./experiment.sh || :
echo
done
Run Code Online (Sandbox Code Playgroud)
得到的结果:
Testing with: ash
./experiment.sh: 5: empty_var: parameter not set or null
$?=2
value=
Testing with: bash
./experiment.sh: line 5: empty_var: parameter null or not set
Testing with: dash
./experiment.sh: …Run Code Online (Sandbox Code Playgroud)