小编Hao*_*Hao的帖子

Java中是否提供C#样式对象初始值设定项

像这个?http://weblogs.asp.net/dwahlin/archive/2007/09/09/c-3-0-features-object-initializers.aspx

Person p = new Person()
{
    FirstName = "John",
    LastName = "Doe",
    Address = new Address()
    {
        Street = "1234 St.",
        City = "Phoenix"
    }
};
Run Code Online (Sandbox Code Playgroud)

java

46
推荐指数
4
解决办法
2万
查看次数

如何在Visual Studio中设置默认的双击操作?

双击时,如何使Visual Studio默认为"查看源" Form1.cs.我更喜欢将View Source设置为双击而不是View Designer.

defaultview visual-studio

45
推荐指数
2
解决办法
9963
查看次数

为什么List <T>不是线程安全的?

从以下网站:

http://crfdesign.net/programming/top-10-differences-between-java-and-c

不幸的是,List<>它不是线程安全的(C#ArrayList和Java Vector是线程安全的).C#也有一个Hashtable; 通用版本是:

什么使List<T>线程不安全?它是.NET框架工程师的实现问题吗?或者泛型不是线程安全的吗?

.net generics thread-safety

42
推荐指数
3
解决办法
3万
查看次数

协议缓冲区的速度有多快或多快?

.NET协议缓冲区是否比Remoting(SerializationFormat.Binary)更轻/更快?是否会以语言/框架术语为其提供一流的支持?即它是否像Remoting/WebServices一样透明地处理?

c# remoting protocol-buffers

34
推荐指数
2
解决办法
2万
查看次数

如何从表单标记之外的按钮手动触发AngularJS验证?

鉴于此代码:

<div ng-controller="MyCtrl">
    <form ng-submit="onSubmitted()">

    Header inputs:
        <input type="name" ng-model="sample" required/>
        <input type="name" ng-model="sampleX" required/>

        <input type="submit" value="This submit triggers validation. But I wanted to put this button at the end of the page"/>
    </form>

    <hr/>

    Some other form here. Think line items

    <hr />
    <a class="btn" ng-click="/* what could should be put here, so this can trigger the firt form's validation, then submit? */">Wanted this submit button to trigger the validation+submit on the form in which this button doesn't …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs

26
推荐指数
1
解决办法
3万
查看次数

防止PostgreSQL中的递归触发器

如何防止触发器的递归执行?假设我想在账户图表上构建一个"树形"描述.所以我所做的是当插入/更新新记录时,我更新了父记录down_qty,因此这将以递归方式触发更新触发器.

现在,我的代码还可以 - 我把它放在UPDATE触发器的第一行:

-- prevents recursive trigger
if new.track_recursive_trigger <> old.track_recursive_trigger then
    return new;
end if;
Run Code Online (Sandbox Code Playgroud)

当我需要更新父记录的数量时,这是我的触发器的示例代码:

update account_category set 
    track_recursive_trigger = track_recursive_trigger + 1, -- i put this line to prevent recursive trigger
    down_qty = down_qty - (old.down_qty + 1)
where account_category_id = m_parent_account;
Run Code Online (Sandbox Code Playgroud)

我想如果PostgreSQL中有一种方法可以检测递归触发而不引入一个类似于MSSQL的新字段trigger_nestlevel.

[编辑]

我在树内循环,我需要将down_qty每个account_category回到它的根部.例如,我插入一个新的账户类别,它需要递增down_qty其父的account_category,同样,当我更改帐户类别的父母account_category,我需要递减down_qtyaccount_category的早先父account_category.虽然我认为它可以,但我不是让PostgreSQL做递归触发器.我之前使用的是MSSQL,其中触发递归深度级别仅限于16级别.

postgresql recursion

23
推荐指数
2
解决办法
1万
查看次数

是否有一般方法来检测属性的类型是否是可枚举类型?

鉴于这种:

class InvoiceHeader {
    public int InvoiceHeaderId { get; set; }
    IList<InvoiceDetail> LineItems { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我目前正在使用此代码来检测类是否具有集合属性:

void DetectCollection(object modelSource)
{       
    Type modelSourceType = modelSource.GetType();
    foreach (PropertyInfo p in modelSourceType.GetProperties())
    {
        if (p.PropertyType.IsGenericType &&  p.PropertyType.GetGenericTypeDefinition() == typeof(IList<>))
        {
            System.Windows.Forms.MessageBox.Show(p.Name);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

是否有一般方法来检测LineItems是否是可枚举类型?有些将使用其他可枚举类型(例如ICollection),而不是IList.

c#

20
推荐指数
1
解决办法
2万
查看次数

如何在Objective-C中实例化一个不从NSObject继承的类

鉴于这种:

Person.h:

@interface Person 
{
}
- (void) sayHello;
@end
Run Code Online (Sandbox Code Playgroud)

Person.m:

#import "Person.h"

@implementation Person 

- (void)sayHello 
{
    printf("%s", "Steve");
}

@end
Run Code Online (Sandbox Code Playgroud)

你如何实例化这个人?我试过这个:

Person *p = [Person new];
Run Code Online (Sandbox Code Playgroud)

这不起作用,也不是这样的:

Person *p = [Person alloc];
Run Code Online (Sandbox Code Playgroud)

[UPDATE]

我忘了告诉,我已经尝试从NSObject继承,新的和alloc工作.我只是好奇我们是否可以实例化一个不从NSObject继承的类?

class objective-c instantiation

17
推荐指数
1
解决办法
5569
查看次数

如何在AngularJS中手动触发表单的提交?

我有一个我希望嵌套的表单,但由于HTML无法接受嵌套表单,因此无法实现.有没有办法可以在AngularJS的第一个表单上手动调用提交(触发验证,例如需要)?

这是代码的样子:

<div ng-conroller="ContactController">

    <form ng-submit="saveHeaderAndDetail()">
        <label for="Description">Description</label>
        <input type="text" ng-model="Description" required/> 

        <input type="text" style="visibility:hidden" />
    </form>

    <form ng-submit="addToDetail()">
    ... 
    </form>

    <input type="button" 
        ng-click="what code could trigger the first form's submit?"/>

</div>
Run Code Online (Sandbox Code Playgroud)

顺便说一下,如果有帮助,两种形式都在一个控制器下

javascript angularjs

17
推荐指数
2
解决办法
3万
查看次数

WebStorm + Typescript:如何在没有参考路径的情况下使用?

在Visual Studio中,可以使用内部模块而无需包含/// <reference path="..." />标记.
如何在WebStorm 10中实现同样的目标?

另一个问题是,如何让WebStorm将打包输入项目?WebStorm 10将输入放在缓存文件夹中.

webstorm typescript

16
推荐指数
1
解决办法
1万
查看次数