相关疑难解决方法(0)

$ .noop()在jQuery 1.4中的真正用途是什么?

关于jQuery 1.4的发行说明,我来了acrosss $.noop(),它是:

描述:一个空函数.(在1.4中添加)

当你希望传递一个什么都不做的函数时,可以使用这个空函数.

也许我在这里遗漏了一些深刻的东西,但究竟是什么实际使用传递空函数?

代码示例赞赏.

javascript jquery no-op jquery-1.4

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

C#:在类实例化上创建一个do-nothing Action

我有一个类,用户可以将Action传入(或不传递).

public class FooClass<T> : BaseClass<T>
{
    public FooClass()
        : this((o) => ()) //This doesn't work...
    {
    }

    public FooClass(Action<T> myAction)
        : base(myAction)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)


基本上,我不能将null传递给我的基类Action.但是,与此同时,我不想强​​迫我的用户传入Action.相反,我希望能够动态创建"无所事事"动作.

c# lambda delegates action

7
推荐指数
2
解决办法
8979
查看次数

如何从配置文件重构高度重复的读取部分

我需要将配置文件的多个部分转换为字典.这些词典的值有不同的类型.以下两个类可以工作,但它们几乎完全相同:

public class IntConfigSection
{
    private static readonly ILog Log = LogManager.GetLogger(typeof(IntConfigSection));
    public static Dictionary<String, int> LoadSection(string sectionName)
    {
        var ret = new Dictionary<String, int>();
        try
        {
            var offsetsHash = (Hashtable)ConfigurationManager.GetSection(sectionName);
            foreach (DictionaryEntry entry in offsetsHash)
            {
                ret.Add((String)entry.Key, int.Parse((String)entry.Value));
            }
        }
        catch(Exception e)
        {
            Log.ErrorFormat("LoadSection:" + e);
        }
        return ret;
    }
}

public class StringConfigSection
{
    private static readonly ILog Log = LogManager.GetLogger(typeof(StringConfigSection));
    public static Dictionary<String, String> LoadSection(string sectionName)
    {
        var ret = new Dictionary<String, String>();
        try
        {
            var offsetsHash …
Run Code Online (Sandbox Code Playgroud)

c# configuration refactoring templates

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