在保持我同事的代码甚至是自称是高级开发人员的人的同时,我经常看到以下代码:
try
{
//do something
}
catch
{
//Do nothing
}
Run Code Online (Sandbox Code Playgroud)
或者有时他们将日志信息写入日志文件,如下面的try catch块
try
{
//do some work
}
catch(Exception exception)
{
WriteException2LogFile(exception);
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道他们所做的是最佳做法吗?这让我感到困惑,因为在我看来,用户应该知道系统会发生什么.
请给我一些建议.
我正在尝试按照本指南https://angular.io/docs/ts/latest/guide/ngmodule.html引导我的Angular 2 RC5应用程序. 下面是我的代码
import { AppModuleNgFactory } from './app.module.ngfactory';
import {platformBrowser} from "@angular/platform-browser";
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译打字稿代码时,我收到以下错误
app\main.ts(1,36):错误TS2307:找不到模块'./app.module.ngfactory'.
如何生成app.module.ngfactory文件?我应该使用哪种工具?
我只是好奇.NET如何在"Any CPU"配置设置下编译源代码时定义了一个流程架构接口.我一直认为如果你在x64计算机上运行该进程,它将是一个64位进程.但是,下面的例子显示了一个完全不同的东西.
我有一个简单的控制台程序,代码如下:
static void Main(string[] args)
{
Console.WriteLine("Process Type: {0}", Environment.Is64BitProcess?"64 Bit":"32 Bit" );
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
配置设置如下:

我的处理器是64位:

最后,结果显示

你能提一些见解吗?
你能告诉我如何在Javascript中解冻一个冻结的对象,以便我能够修改它的属性吗?
var pizza = {
name: 'Peri Peri',
Topping: 'Prawn'
};
Object.freeze(pizza);
// Can't change the name of the object because it's frozen
pizza.name = 'Hawaiian';
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以订阅更改对象,即数组.我的用例如下:用户重新加载页面,需要加载整个集合,然后获取一个具有特定id的对象.据我所知,我可以创建一个这样的函数:
在构造函数中:
this.getById(id);
Run Code Online (Sandbox Code Playgroud)
而且功能
getById(id: string){
this.object = this.objectsService.getById(id);
if (this.object.name){ //check if object exist
//Do something
} else {
setTimeout(()=>{
this.getById(id)
}, 1000);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我觉得这不是最好的事情.那么,我想做的是这样的事情:
let objects = this.objectService.getObjects() // returns object that will hold the collection;
objects.subscribe((value) => {
if(value.length) {
//Do something
}
});
Run Code Online (Sandbox Code Playgroud) 我尝试在取消下面的任务时运行一个简单的例子
CancellationTokenSource tokenSource2 = new CancellationTokenSource();
CancellationToken token2 = tokenSource2.Token;
Task task2 = new Task(() =>
{
for (int i = 0; i < int.MaxValue; i++)
{
token2.ThrowIfCancellationRequested();
Thread.Sleep(100);
Console.WriteLine("Task 2 - Int value {0}", i);
}
}, token2);
task2.Start();
Console.WriteLine("Press any key to cancel the task");
Console.ReadLine();
tokenSource2.Cancel();
Console.WriteLine("Task 2 cancelled? {0}", task2.IsCanceled);
Run Code Online (Sandbox Code Playgroud)
我预计 Console.WriteLine("Task 2 cancelled? {0}", task2.IsCanceled);会打印**"Task 2 cancelled? True"**,但它打印"假".
你知道发生了什么吗?这是预期的行为吗?谢谢.
编辑:确保在调用取消请求之前未完成任务.我加了Console.ReadLine().
我正在使用MVC属性路由(MVC 5.1.2)并遇到错误:
找到了与URL匹配的多种控制器类型.如果多个控制器上的属性路由与请求的URL匹配,则会发生这种情
请求已找到以下匹配的控制器类型:FFInfo.WebUI.Areas.Admin.Controllers.HomeController FFInfo.WebUI.Areas.Admin.Controllers.SectionController
这种情况只发生在我去的时候/Admin/Sections/,我不确定为什么因为只有一条路线可以匹配该URL,任何人都可以帮我弄清楚出了什么问题?请注意这个问题是5.1.2独有的,MVC 5.0工作正常.
基础控制器:
[RouteArea("Admin")]
public class BaseController : Controller
{
}
Run Code Online (Sandbox Code Playgroud)
家庭控制器:
[RoutePrefix("")]
[Route("{action}")]
public class HomeController : BaseController
{
public ActionResult Index()
{
}
public ActionResult Updates()
{
}
[ChildActionOnly]
public PartialViewResult GetUpdatesGrid()
{
}
public ActionResult GetUpdates(JqGridRequest Request)
{
}
}
Run Code Online (Sandbox Code Playgroud)
部门控制器:
[RoutePrefix("Sections")]
[Route("{action}")]
public class SectionController : BaseController
{
[Route]
public ActionResult Sections()
{
}
[ChildActionOnly]
public PartialViewResult GetSectionsGrid()
{
}
public ActionResult GetSections(JqGridRequest Request)
{
}
public ActionResult AddSection() …Run Code Online (Sandbox Code Playgroud) 我已经INotifyPropertyChanged实现了CallerMemberName
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Run Code Online (Sandbox Code Playgroud)
因此,可以在任何属性的设置器中将OnPropertyChanged()其称为- ,它会在设置属性时通知属性更改事件。仅属性获取器不是这种情况。例如,
private DateTime _dob;
public DateTime DateOfBirth
{
get
{
return _dob;
}
private set
{
_dob = value;
OnPropertyChanged();
OnPropertyChanged("Age");
}
}
public int Age
{
get
{
return DateTime.Today.Year - _dob.Year;
}
}
Run Code Online (Sandbox Code Playgroud)
OnPropertyChanged()对于DateOfBirth可以正常使用,但是要通知Age更改,我应该记得OnPropertyChanged("Age")在的setter中进行调用DateOfBirth。我觉得这使得代码很难随时间进行维护。如果新属性取决于年龄,则还需要在DateOfBirth的设置器中进行通知。有没有更好的方法可以执行此操作而无需调用OnPropertyChanged(“ Age”)?
我有以下课程
class Animal
def move
"I can move"
end
end
class Bird < Animal
def move
super + " by flying"
end
end
class Penguin < Bird
def move
#How can I call Animal move here
"I can move"+ ' by swimming'
end
end
Run Code Online (Sandbox Code Playgroud)
如何在Penguin中调用Animal的移动方法?我不能使用super.super.move.有什么选择?
谢谢
我试图使用rubymine IDE版本7.0.2调试rails应用程序(4.03),但是当我像这样配置我的应用程序时

IDE抱怨在项目中找不到Rails Server启动程序.
请告诉我我该怎么做才能解决这个问题,请你推荐一些调试rails应用程序的方法.
请注意,使用Ruby Mine可以通过以下步骤轻松复制此错误.
使用Ruby Mine创建一个新的rails项目,例如DebuggingRails.这将生成默认文件夹和文件.此时,可以正常调试应用程序.
创建一个新文件夹让我们说服务器.
将上面生成的所有文件复制到Server文件夹,因此项目结构将是DebuggingRails\Server.
创建一个调试配置,指向DebuggingRails\Server.
尝试使用IDE调试应用程序.
出现"在项目中找不到Rails服务器启动器"消息
谢谢.
c# ×4
.net ×3
angular ×2
ruby ×2
typescript ×2
c#-5.0 ×1
debugging ×1
exception ×1
javascript ×1
object ×1
rubymine-7 ×1
rxjs ×1
try-catch ×1
wpf ×1