如果您有一个名为“ User”的类和另一个扩展为“ User”的名为“ Admin”的类,并且您希望Admin继承User的所有属性,则__construct方法除外。
class User {
private $name;
function __construct($name) {
$this->name = $name;
}
}
Run Code Online (Sandbox Code Playgroud)
和
class Admin extends User {
private $authorization;
function __construct($name,$authorization) {
$this->name = $name;
$this->authorization = $authorization;
}
}
Run Code Online (Sandbox Code Playgroud)
它是否正确?管理员会否覆盖用户的构造方法?如果扩展类具有相同的方法名,我认为它是无效的。我是否完全错过了课堂扩展的要点?
我正在尝试在std :: list上进行双循环以对每对元素进行操作.但是,我在初始化第二个迭代器时遇到了一些麻烦.我想写的代码是:
for(std::list<int>::iterator i = l.begin(); i != l.end(); ++i) {
for(std::list<int>::iterator j = i+1; j != l.end(); ++j) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为列表迭代器不是随机访问,所以你不能做+1.但是我在寻找一个简洁的选择方面遇到了一些麻烦; 编译器对std::list<int>::iterator j(i)++;我有一些希望似乎并不高兴.实现我想要的东西似乎我将不得不有一些尴尬的额外增量,这将不太适合for循环的结构.
有明显的替代方案(例如使用矢量!)但在我看来应该有一些合理利落的方式来做这个,我现在还没有看到.
在此先感谢任何帮助:)
我有一个从字符串到整数的映射.要将此映射存储在MySQL数据库中,我创建了下表:
CREATE TABLE map(
Argument TEXT NOT NULL,
Image INTEGER NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
我为参数选择了TEXT类型,因为它的长度是不可预测的,目前最长的记录有2290个字符,平均长度是88个字符.
在我遇到性能问题后,我尝试在Argument列上添加索引,但发现我必须指定长度,所以为了避免这种限制,我添加了一个新的整数列,其中包含参数列值的哈希值(md5或其他).
ALTER TABLE map ADD COLUMN ArgumentHash INTEGER;
Run Code Online (Sandbox Code Playgroud)
和综合指数
CREATE INDEX argument_index USING HASH ON map(ArgumentHash, Argument(80));
Run Code Online (Sandbox Code Playgroud)
从那时起,性能问题就消失了.我想问一下解决这个问题是否正确.
我有期望几个属性由Ninject 2被注入的方法属性,但userSession并jobRepository都上来为空:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class JobAttribute : ActionFilterAttribute {
[Inject]
private IUserSession userSession;
[Inject]
private IJobRepository jobRepository;
public override void OnActionExecuting(ActionExecutingContext filterContext) {
var filter = new JobFilter(userSession, jobRepository);
filter.OnActionExecuting(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud)
这是控制器中的方法:
[AcceptGet, Job]
public ActionResult Dimensions(Job job) {
return View(job.Building);
}
Run Code Online (Sandbox Code Playgroud)
我知道我的设置有效,因为如果我在控制器上使用构造函数注入,则会注入控制器的参数.虽然需要使用属性注入,但这对属性没有多大帮助.我在这里错过了什么吗?
以下是Global.asax.cs的相关部分:
public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication {
protected override void OnApplicationStarted() {
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
...snip...
protected override IKernel CreateKernel() {
return new StandardKernel(
new RepositoryConfiguration(),
new AuthenticationModule(),
new …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc ninject property-injection actionfilterattribute
我正在使用Windows 7 Ultimate 64位版本和带有Android插件的Eclipse 3.5.每次我创建一个新项目并尝试发布它时,我都会收到如下错误:
[2010-02-15 22:48:10 - EPG3]Uploading EPG3.apk onto device 'emulator-5554' [2010-02-15 22:48:15 - EPG3]Failed to upload EPG3.apk on device 'emulator-5554' [2010-02-15 22:48:15 - EPG3]java.io.IOException: Unable to upload file: timeout [2010-02-15 22:48:15 - EPG3]Launch canceled!
模拟器工作得很好,adb可以看到它,我甚至可以从它进行logcat,但是它不能从中推送或拉出任何东西.logcat中没有任何内容表明模拟器甚至收到任何命令.如果我打开或关闭防火墙,或者我尝试调用adb install来绕过插件,则无关紧要.即使是空白的应用也没有任何作用.
有任何想法吗?
我想从文件中获取电话号码.我知道数字有不同的形式,我可以处理一个,但不知道如何获得统一的正则表达式.例如
xxx-xxx-xxxx
(xxx)xxx-xxxx
xxx xxx xxxx
xxxxxxxxxx
我只能一起处理1,2和4
grep '[0-9]\{3\}[ -]\?[0-9]\{3\}[ -]\?[0-9]\{4\}' file
Run Code Online (Sandbox Code Playgroud)
是否有任何一个正则表达式可以处理所有这四种形式?
我有一个仅在视图中使用的常量,但它在不同的地方以不同的方式使用.它是一个选项名称数组,用于选择框,但我也在其他视图中使用它来查看是否在此数组中找到字符串,并相应地做出响应.
处理此问题以保持干燥的最佳方法是什么?
我最初在帮助器中创建了一个常量,但在视图中似乎无法访问.
我已经切换到在帮助器中创建一个方法,除了返回常量之外什么都不做.然而,这似乎违背了Rails的精神,因为现在基本上我使用的是较低的常量.
我当然可以把它放在一个模型中,但它与任何模型都没有任何关系.
在Interface Builder.app(以及其他一些可可应用程序)中,当您将可拖动项目拖出窗口时,图像拖动具有非常漂亮/性感的变形拖动图像效果.
例如在Interface Buildler.app中:
注意:当您将项目拖出"库调色板"窗口时,它会从原始列表项的图像变形为拖动项目图标的图像.
我使用普通的Cocoa NSDragSource/NSDragDestination工具在我的应用程序中完全实现了拖放.
但是,在拖动时我无法找到用于执行此图像变形的钩子.我通过覆盖返回初始拖动图像
-[NSView dragImage:at:offset:event:pasteboard:source:slideBack:]
Run Code Online (Sandbox Code Playgroud)
但这只是在阻力开始时调用.
如何表示您想要替换当前拖动图像(理想情况下使用性感变形效果).
我有一大堆带有sql命令的文件,我被要求从文件中提取所有数据库表名如何使用grep和sed来解析文件并在文本文件中创建唯一表名列表. .每行一个?
所有名称似乎都以"db_"开头,这很方便!
什么是使用grep和sed一起拉出表名的最佳方法?
我需要以编程方式下载大文件,然后再进行处理.最好的方法是什么?由于文件很大,我想要特定的时间等待,以便我可以强行退出.
我知道WebClient.DownloadFile().但似乎没有办法确定等待一段时间以便强行退出.
try
{
WebClient client = new WebClient();
Uri uri = new Uri(inputFileUrl);
client.DownloadFile(uri, outputFile);
}
catch (Exception ex)
{
throw;
}
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用命令行实用程序(wget)下载文件并使用ProcessStartInfo触发命令并使用Process'WellForExit(int ms)强制退出.
ProcessStartInfo startInfo = new ProcessStartInfo();
//set startInfo object
try
{
using (Process exeProcess = Process.Start(startInfo))
{
//wait for time specified
exeProcess.WaitForExit(1000 * 60 * 60);//wait till 1m
//check if process has exited
if (!exeProcess.HasExited)
{
//kill process and throw ex
exeProcess.Kill();
throw new ApplicationException("Downloading timed out");
}
}
}
catch (Exception ex)
{
throw;
} …Run Code Online (Sandbox Code Playgroud)