我有以下丑陋的if语句,它是从IOC容器中提取的类的一部分:
protected virtual void ExecuteSourceControlGet(IBuildMetaData buildMetaData, IPackageTree componentTree)
{
if ((buildMetaData.RepositoryElementList != null) && (buildMetaData.RepositoryElementList.Count > 0))
{
componentTree.DeleteWorkingDirectory();
foreach (var repositoryElement in buildMetaData.RepositoryElementList)
{
repositoryElement.PrepareRepository(componentTree, get).Export();
}
}
if((buildMetaData.ExportList != null) && (buildMetaData.ExportList.Count > 0))
{
var initialise = true;
foreach (var sourceControl in buildMetaData.ExportList)
{
log.InfoFormat("\nHorn is fetching {0}.\n\n".ToUpper(), sourceControl.Url);
get.From(sourceControl).ExportTo(componentTree, sourceControl.ExportPath, initialise);
initialise = false;
}
}
log.InfoFormat("\nHorn is fetching {0}.\n\n".ToUpper(), buildMetaData.SourceControl.Url);
get.From(buildMetaData.SourceControl).ExportTo(componentTree);
}
Run Code Online (Sandbox Code Playgroud)
我消除if语句的常用方法是为每个条件创建一个子类.
这个例子的不同之处是:
任何建议都非常欢迎.
我正在写一个简单的程序.里面只有一节课.有一个私人成员'char*号码'和两个功能(会有更多,但首先这些应该正常工作:)).
第一个应该将'source'复制到'number'变量中(我想这里的某个地方就是问题):
LongNumber::LongNumber(const char * source ){
int digits = strlen(source);
char* number = new char[digits+1];
strcpy( number, source );
// cout<<number<<endl; - if the line is uncommented,
// the output is correct and there isn't a problem
}
Run Code Online (Sandbox Code Playgroud)
和打印功能:
void LongNumber::print(){
cout<<number<<endl;
// when I try to print with the same line of code here..it crashes
}
Run Code Online (Sandbox Code Playgroud)
当然,我错过了什么......但是什么?
(因为这是我的第一篇文章......你认为标签是否已经更正......你会如何标记帖子?)
先感谢您 :)
我有一个输出大量数据的python脚本,示例如下.4个字段中的第一个字母总是由两个字母组成,一个数字,一个斜线和一个或两个数字
Gi3/2 --.--.--.-- 0024.e89b.c10e Dell Inc.
Gi5/4 --.--.--.-- 0030.c1cd.f038 HEWLETTPACKARD
Gi4/3 --.--.--.-- 0020.ac00.6703 INTERFLEX DATENSYSTEME GMBH
Gi3/7 --.--.--.-- 0009.4392.34f2 Cisco Systems
Gi6/6 --.--.--.-- 001c.2333.bd5a Dell Inc
Gi3/16 --.--.--.-- 0009.7c92.7af2 Cisco Systems
Gi5/12 --.--.--.-- 0020.ac00.3fb0 INTERFLEX DATENSYSTEME GMBH
Gi4/5 --.--.--.-- 0009.4392.6db2 Cisco Systems
Gi4/6 --.--.--.-- 000b.cd39.c7c8 Hewlett Packard
Gi6/4 --.--.--.-- 0021.70d7.8d33 Dell Inc
Gi6/14 --.--.--.-- 0009.7c91.fa71 Cisco Systems
Run Code Online (Sandbox Code Playgroud)
在第一个字段上对此进行正确排序的最佳方法是什么,以便读取此示例
Gi3/2 --.--.--.-- 0024.e89b.c10e Dell Inc.
Gi3/7 --.--.--.-- 0009.4392.34f2 Cisco Systems
Gi3/16 --.--.--.-- 0009.7c92.7af2 Cisco Systems
Gi4/3 --.--.--.-- 0020.ac00.6703 INTERFLEX DATENSYSTEME GMBH
Gi4/5 …Run Code Online (Sandbox Code Playgroud) 我正在做一些byte []比较.
我试过==但这就像基本的Equals,它:
byte[] a = {1,2,3};
byte[] b = {1,2,3};
bool equals = a == b; //false
equals = a.Equals(b); //false
Run Code Online (Sandbox Code Playgroud)
我试图添加一个扩展方法,但由于重载的基类'Equals采用相同的参数,它转到基本方法而不是扩展,无论如何我可以使用Equals扩展(不要改变它的名字......)或(甚至更好)使用==运算符?
这是我实际要比较的内容:
public static bool ContentEquals(this byte[] array, byte[] bytes)
{
if (array == null || bytes == null) throw new ArgumentNullException();
if( array.Length != bytes.Length) return false;
for (int i = 0; i < array.Length; i++)
if (array[i] != bytes[i]) return false;
return true;
}
Run Code Online (Sandbox Code Playgroud) 我觉得我在用我的代码滥用DOM ...
for(var i=0; i<json.length; ++i){
var newobj = document.createElement("div");
var inner = "<img src='"+json[i].picture+"' alt='Item preview' class='icon' />";
inner += "<p>"+json[i].id+"<br />qty:"+json[i].qty;
inner += "<a href=\"javascript:clearProduct('"+json[i].id+"')\">";
inner += "<img alt='Seperator' src='images/form-sep.gif' />";
inner += "<img src='images/cross.png' alt='Remove this item.' title='Remove this item.' />";
inner += "</a></p>";
newobj.innerHTML = inner;
newobj.className = "cart_item";
$('cartitems').appendChild(newobj);
$('cartcount').innerHTML = json.length;
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?我的意思是,是的,我可以通过并为每个元素使用createElement并分别设置每个属性,但这看起来很简单.有没有更好的办法?
我有从Microsoft Word生成的html格式的大文档.它太乱了,充满了臃肿的东西(比如unknow标签,unknow名称空间等等和其他臃肿的东西)
有没有办法将其转换为普通的HTML sytax?
我有兴趣在多台服务器上分割我的网站用户数据.
例如,用户将从同一个地方登录.但登录脚本需要弄清楚用户数据所在的服务器.因此,登录脚本将向主注册表查询该用户名,并且它可能返回它在服务器B上.登录脚本然后将连接到服务器B并验证用户名/密码.那有意义吗?拥有类似主注册表的东西以解决数据所在的位置是否正常?
还 - 我已经搜索过,但我没有太多运气找到关于分片的教程/信息/策略.如果您有关于该主题的任何在线资源,我将非常感谢您,如果您愿意分享,以便我可以自学.谢谢!
我应该为我的MSc创建一个GIS应用程序,我想知道什么是最好的免费和(最好)开源技术?用于开发此类应用程序的编程语言是什么?
已知的选择是:数据库:PostgreSQL(PostGIS)(建议其他)
编程语言:PHP,Python,Java,...(建议其他)
框架:GeoDjango(如果使用Python或Jython),(建议其他)
客户端UI:JavaScript(OpenLayers),Flex,(建议其他)
服务器:Mapserver,Geoserver,Mapfish,(建议其他)
其他注意事项:Hibernate Spatial,支持移动GIS,(建议其他)
确实不是那种程度的失败.我刚从djangoproject.com完成了4部分教程,我的管理应用程序工作正常,我的入口点url(/ polls /)运行良好,除了我得到这个http响应:
没有民意调查.
即使数据库有一个注册表.使用管理员应用程序输入,该条目显示应该是这样的方式.
在本教程结束时,您可以通过将其替换为URLconf上的通用视图来更改所有硬编码视图.在所有修改之后,你的urls.py最终会像这样:
from django.conf.urls.defaults import *
from mysite.polls.models import Poll
info_dict = {
'queryset': Poll.objects.all(),
}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
(r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
url(r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results.html'), 'poll_results'),
(r'^(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
)
Run Code Online (Sandbox Code Playgroud)
使用这些通用视图,复制/粘贴我的views.py文件是没有意义的,我只会提到只有一个投票功能(因为django通用视图可以完成所有的魔术).我的假设是urls.py文件需要一些调整,或者在某些方面是错误的.为了发送"没有民意调查可用".在/ polls/url输出.我的poll_list.html文件如下所示:
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>{{ poll.question }}</li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
它将latest_poll_list变为false,这就是执行else块的原因.
你能帮我个忙吗?(我在stackoverflow上搜索了重复的问题,甚至在谷歌搜索这个问题,但我找不到任何东西).当我进入http://127.0.0.1:8000/polls时,为什么会收到此消息?
当调用始终从返回值的函数抛出的函数时,编译器经常警告并非所有控制路径都返回值.合法的.
void AlwaysThrows() { throw "something"; }
bool foo()
{
if (cond)
AlwaysThrows();
else
return true; // Warning C4715 here
}
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉编译器AlwaysThrows的功能是什么?
我知道我可以throw在函数调用后添加另一个:
{ AlwaysThrows(); throw "dummy"; }
Run Code Online (Sandbox Code Playgroud)
而且我知道我可以明确地禁用警告.但我想知道是否有更优雅的解决方案.