半城柳色半声笛

文章 评论 浏览 26

半城柳色半声笛 2024-11-10 12:17:07

为什么不定义每个方法以采用一个参数:对象数组? 方法

-(void) doSomethingWithFoo:(id) foo andBar: (id) bar;

想必您想要的是使用从数组中设置的参数来调用它的 。好吧,改为:

-(void) doSomethingWithArrayOfFooAndBar: (NSArray*) fooAndBar;

那么你的整个调度机制就变成:

[someObject performSelector:selector withObject:arrayOfObjects];

Why not define each of your methods to take one argument: the array of objects? Presumably what you want is, with with the method

-(void) doSomethingWithFoo:(id) foo andBar: (id) bar;

to invoke it with the parameters set from the array. Well, instead have:

-(void) doSomethingWithArrayOfFooAndBar: (NSArray*) fooAndBar;

then your whole dispatch mechanism just becomes:

[someObject performSelector:selector withObject:arrayOfObjects];

使用反射/内省调用具有未知数量参数的选择器

半城柳色半声笛 2024-11-10 09:39:43

在 C++ 中进行此操作的正确方法是 PIMPL 惯用法。另一种解决方案是将要隐藏的类放入嵌套命名空间中,该命名空间通常称为detail。但这并不会使它完全私有,因为用户仍然会接触到它的依赖项,并且能够直接使用它。

The right way to go about it in C++ is PIMPL idiom. Alternative solution is to put the class you want to hide into a nested namespace, which is usually called detail. But that will not make it totally private as users will still be exposed to its dependencies, and will be able to use it directly.

隐藏一个 C++标头中的类而不使用未命名的命名空间

半城柳色半声笛 2024-11-10 06:13:18

不存在功能超特征。
您必须使用隐式方法将要装饰的方法包装到自己的类中。
该类必须处理不同的方法类型。
然后你必须创建一些类来生成你的装饰方法。

或者,如果可以的话,您只需创建类似的新方法:

def myF(x:Int,y:Int)={x*y}

def myF2(x:Int,y:Int)={myDecorator(myF(x,y))}
def myDecorator[X](f:=>X)={println("entering");val ret=f();println("exiting");ret}

或尝试:

def myF_old(x:Int,y:Int)=x*y 
def paramDecorator(x:Any*):List[Any]={/*do some match operations or something*/} 
def outputDecorator(x:Any*):Any={/*do some match operations or so*/} 
def myF(x:Int,y:Int):Int={
params=paramDecorator(x,y);
val res=myF_old(params(1),params(2));
outputDecorator(res);
}

There is not a function supertrait.
You will have to wrap the method you want to decorate into an own class with an implicit.
That class gonna have to handle the different method types.
Then you have to create some class what generates your decorated method.

Or if you can you just create new methods like that:

def myF(x:Int,y:Int)={x*y}

def myF2(x:Int,y:Int)={myDecorator(myF(x,y))}
def myDecorator[X](f:=>X)={println("entering");val ret=f();println("exiting");ret}

or try:

def myF_old(x:Int,y:Int)=x*y 
def paramDecorator(x:Any*):List[Any]={/*do some match operations or something*/} 
def outputDecorator(x:Any*):Any={/*do some match operations or so*/} 
def myF(x:Int,y:Int):Int={
params=paramDecorator(x,y);
val res=myF_old(params(1),params(2));
outputDecorator(res);
}

scala:具有可变长度参数的 Function 对象的特征?

半城柳色半声笛 2024-11-10 05:10:47

由于这是一个 has_one 关联,您是否尝试过使用资源而不是资源?

resources :members do
  resource :profile
end

然后你应该能够做这样的事情:

link_to "Profile", member_profile_path(@member)

Since this is a has_one association, have you tried using resource rather than resources?

resources :members do
  resource :profile
end

You should then be able to do something like this:

link_to "Profile", member_profile_path(@member)

使用 Devise 嵌套资源 - Rails3

半城柳色半声笛 2024-11-10 04:59:28

您需要正确地为表添加别名才能获取所需的数据。此外,不应使用子查询来选择父类型,而应使用 JOIN。可能是外连接,因为您的查询意味着该表中的父子关系是可选的。

这应该适合你:

SELECT ty.id, ty.type, ty.pid, 
  if(ty.pid = 0, '-', p.type) as parent,
  ty.code, ty.description, ty.icon,
  date_format(ty.adate, '%m-%d-%Y %H:%i:%s') as adate,
  date_format(ty.edate, '%m-%d-%Y %H:%i:%s') as edate, ty.status
FROM bid_type ty
  LEFT OUTER JOIN bid_type p on p.id = ty.pid

You need to alias your tables properly to get the data you want. Also, instead of using a sub-query to select the parent type, you should use a JOIN. Probably an outer join since your query implies that the parent-child relationship in this table is optional.

This should work for you:

SELECT ty.id, ty.type, ty.pid, 
  if(ty.pid = 0, '-', p.type) as parent,
  ty.code, ty.description, ty.icon,
  date_format(ty.adate, '%m-%d-%Y %H:%i:%s') as adate,
  date_format(ty.edate, '%m-%d-%Y %H:%i:%s') as edate, ty.status
FROM bid_type ty
  LEFT OUTER JOIN bid_type p on p.id = ty.pid

如何通过MYSql查询获取父母姓名

半城柳色半声笛 2024-11-10 01:46:09

Guid.TryParse 是.NET 4 的一部分。确保您正在针对 .NET 4 进行构建和运行,并且应该没问题。

Guid.TryParse is part of .NET 4. Make sure you're both building and running against .NET 4, and it should be fine.

c# System.guid 不包含 Parse 的定义

半城柳色半声笛 2024-11-10 01:15:49

处于 TASK_INTERRUPTIBLETASK_UNINTERRUPTIBLE 状态的进程进一步细分为不同的类,每个类对应一个特定的事件。在此状态下,进程状态无法提供足够的信息来快速检索进程描述符,因此使用另一个名为 wait_queue 的进程列表。 Wait_queue 实现事件的条件等待。等待特定事件的进程被放置在适当的等待队列中。

等待队列被实现为循环列表,其元素包括指向进程的指针
描述符。等待队列列表的每个元素都是 wait_queue 类型:

struct wait_queue {  
    struct task_struct * task;  
    struct wait_queue * next;  
}; 

Processes in a TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE state are further subdivided in to different classes, each of which corresponds to a specific event. In this state, the process state does not provide enough info to retrieve the process descriptor quickly, so another list of processes called wait_queue are used. Wait_queue implements conditional waits on events. A process waiting for a specific event is placed in the proper wait queue.

Wait queues are implemented as cyclical lists whose elements include pointers to process
descriptors. Each element of a wait queue list is of type wait_queue:

struct wait_queue {  
    struct task_struct * task;  
    struct wait_queue * next;  
}; 

内核在哪里存储未运行的进程?

半城柳色半声笛 2024-11-09 23:50:13

我使用 Tomtom 从 iPhone 上的路线规划选项向我发送了一封电子邮件。该电子邮件中有一个我使用的 tomtomhome:geo 链接。
为了进行测试,我在 Mac 上的 Safari 中单击了该链接,显然没有任何反应。然后我将该链接保存为书签,该书签立即使用 MobileMe 同步到我的 iPhone。我单击 iPhone Safari 浏览器上的书签,viola Tomtom 打开,并显示以链接中的位置为中心的地图。它会弹出一个带有链接名称的气球,右箭头允许我选择第一个选项“导航到那里”

生成的链接是:

  • tomtomhome:geo:action=show&lat=26.123456&long =28.123456&name=linkname

I used Tomtom to send me an email from the route planning option on my iPhone. In that email is a tomtomhome:geo link which I used.
To test I clicked on the link on my Mac in Safari, and obviously nothing happened. Then I saved the link as a bookmark, which immediately is synced to my iPhone using MobileMe. I clicked on the bookmark on my iPhone Safari browser and viola Tomtom opens with a map centred to the location in the link. It pops up with a balloon with the links name, and an right arrow allows me to choose first option "Navigate there"

The link generated is:

  • tomtomhome:geo:action=show&lat=26.123456&long=28.123456&name=linkname

通过 URL 方案访问 TomTom 导航解决方案

半城柳色半声笛 2024-11-09 19:19:28

调用存储过程的有问题的代码:

var resultSP = db.StoredProcedure(id);

if (resultSP != null)
{
    var count = resultSP.Count();
    
    var list = resultSP.Select(x=>...);
}

已修复,使用 ToList() 存储在变量中并重用它:

var resultSP = db.StoredProcedure(id);

if (resultSP != null)
{
    var resultSP_List = resultSP.ToList();
    
    var count = resultSP_List.Count();
    
    var list = resultSP_List.Select(x=>...);
}

Problematic code calling an stored procedure:

var resultSP = db.StoredProcedure(id);

if (resultSP != null)
{
    var count = resultSP.Count();
    
    var list = resultSP.Select(x=>...);
}

Fixed, store in a variable with ToList() and reuse it:

var resultSP = db.StoredProcedure(id);

if (resultSP != null)
{
    var resultSP_List = resultSP.ToList();
    
    var count = resultSP_List.Count();
    
    var list = resultSP_List.Select(x=>...);
}

查询的结果不能被枚举多次

半城柳色半声笛 2024-11-09 11:30:35

您是否在寻找多态性

interface MyService {
   void doWork();
}

class CoolMyService {
   void doWork() { /* do something */ }
}

class AnotherMyService {
   void doWork() { /* do something else */ }
}

MyService service;
if(position == 1){ service = new CoolMyService(); }

if(position == 2){ service = new AnotherMyService() } 

service.doWork();

我不知道您的列表中有多少项,但您可以调整上面的示例以根据需要动态加载对象。请记住,您可以使用多态性和定义的接口来确保正直。然后把实际工作落实到具体实施中。

Are you looking for polymorphism?

interface MyService {
   void doWork();
}

class CoolMyService {
   void doWork() { /* do something */ }
}

class AnotherMyService {
   void doWork() { /* do something else */ }
}

MyService service;
if(position == 1){ service = new CoolMyService(); }

if(position == 2){ service = new AnotherMyService() } 

service.doWork();

I don't know how many items there are in your list, but you can adapt the example above to load objects dynamically as appropriate. Just remember that you can use polymorphism and a defined interface to ensure integrity. Then put the real work in concrete implementations.

使类可变

半城柳色半声笛 2024-11-09 11:02:56

我知道这有点旧,但是你见过 Mechanics 模块吗(http: //gallery.orchardproject.net/List/Modules/Orchard.Module.Downplay.Mechanics)?

这允许您在内容项之间创建连接。但是,它不适用于最新版本的 Orchard(我认为 >= 1.5)。如果您仍在使用 1.1,值得一试

I know this is a bit old, but have you seen Mechanics module (http://gallery.orchardproject.net/List/Modules/Orchard.Module.Downplay.Mechanics)?

This allows you to create connections between content items. However, it doesn't work with more recent versions of Orchard (I think >= 1.5). Worth a try if you are still using 1.1

多对多关系

半城柳色半声笛 2024-11-09 09:29:06

如果将年份/季度转换为十进制,并进行一些数学运算,就可以计算出差异。

class DateTimeQuarter
{
    public DateTimeQuarter(DateTime date)
    {
        Date = date;
        Quarter = date.Month / 4 + 1;
    }
    public static int operator -(DateTimeQuarter lhs, DateTimeQuarter rhs)
    {
        double value = Convert.ToDouble(
            (rhs.Date.Year - lhs.Date.Year)) + (rhs.Quarter / 10.0) - (rhs.Quarter / 10.0);
        int result = 
            (Convert.ToInt32(value) * 4) + Convert.ToInt32(value - Math.Floor(value));
        return result;
    }
    public DateTime Date { get; set; }
    public int Quarter { get; set; }
}

static void Main(string[] args)
{
    DateTimeQuarter q1 = new DateTimeQuarter(new DateTime(2006, 04, 20));
    DateTimeQuarter q2 = new DateTimeQuarter(new DateTime(2007, 12, 25));

    int quarters = q1 - q2;
}

If you convert the year / quarters to decimal, and do a little math, you can calculate the difference.

class DateTimeQuarter
{
    public DateTimeQuarter(DateTime date)
    {
        Date = date;
        Quarter = date.Month / 4 + 1;
    }
    public static int operator -(DateTimeQuarter lhs, DateTimeQuarter rhs)
    {
        double value = Convert.ToDouble(
            (rhs.Date.Year - lhs.Date.Year)) + (rhs.Quarter / 10.0) - (rhs.Quarter / 10.0);
        int result = 
            (Convert.ToInt32(value) * 4) + Convert.ToInt32(value - Math.Floor(value));
        return result;
    }
    public DateTime Date { get; set; }
    public int Quarter { get; set; }
}

static void Main(string[] args)
{
    DateTimeQuarter q1 = new DateTimeQuarter(new DateTime(2006, 04, 20));
    DateTimeQuarter q2 = new DateTimeQuarter(new DateTime(2007, 12, 25));

    int quarters = q1 - q2;
}

如何在c#中找出一个季度和另一个之间有多少个季度

半城柳色半声笛 2024-11-09 07:23:56

来自: http://api.jquery.com/val/

$('input:radio[name=bar]:checked').val();

From: http://api.jquery.com/val/

$('input:radio[name=bar]:checked').val();

ajax 与单选按钮

半城柳色半声笛 2024-11-09 04:13:47

Object 函数是一个构造函数,所有其他类型(如 Array、String、Number)都继承它。

Object function is a constructor function, all other types(like Array, String, Number) inheritate it.

JavaScript“对象”的作用是什么?功能做什么?

更多

推荐作者

寻梦旅人

文章 0 评论 0

冰美式不加糖

文章 0 评论 0

m0_51416705

文章 0 评论 0

123456wqwqwq

文章 0 评论 0

qq_R47skh

文章 0 评论 0

hs1283

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文