小编hwi*_*ers的帖子

如何在脚本中要求最低版本的node.js?

我刚刚发现我编写的脚本只能在节点0.10上运行,因为它使用了readable事件.

如何在我的脚本中要求最低版本的node.js,以便用户知道他们需要升级?

node.js

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

使用CodeContracts强制正确实现INotifyPropertyChanged - "需要未经证实"

我正在寻找一种简单的方法来强制正确实现INotifyPropertyChanged,即当引发PropertyChanged时,它必须引用实际定义的属性.我尝试使用Microsoft的新CodeContract工具执行此操作,但我不断收到警告"CodeContracts:需要未经证实".这是我的代码......

public sealed class MyClass : INotifyPropertyChanged
{
    private int myProperty;
    public int MyProperty
    {
        get
        {
            return myProperty;
        }
        set
        {
            if (myProperty == value)
            {
                return;
            }

            myProperty = value;
            OnPropertyChanged("MyProperty");
        }
    }

    private void OnPropertyChanged(string propertyName)
    {
        Contract.Requires(GetType().GetProperties().Any(x => x.Name == propertyName));

        var handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
Run Code Online (Sandbox Code Playgroud)

反正有没有让这个工作?

c# inotifypropertychanged code-contracts

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

如何动态创建与另一个函数具有相同签名的函数?

我正忙于创建一个元类,该元类将类上的存根函数替换为具有正确实现的新函数。原始函数可以使用任何签名。我的问题是我不知道如何创建一个与旧函数具有相同签名的新函数。我该怎么做?

更新

这与实际问题无关,即“如何动态创建与另一个函数具有相同签名的函数?” 但我添加这个是为了说明为什么我不能使用子类。

我正在尝试在 Python 中实现类似Scala Case Classes 的东西。(不是模式匹配方面,只是自动生成的属性、eq、hash 和 str 方法。)

我想要这样的东西:

>>> class MyCaseClass():
...     __metaclass__ = CaseMetaClass
...     def __init__(self, a, b):
...         pass

>>> instance = MyCaseClass(1, 'x')
>>> instance.a
1
>>> instance.b
'x'
>>> str(instance)
MyCaseClass(1, 'x')
Run Code Online (Sandbox Code Playgroud)

据我所知,子类没有办法做到这一点。

python

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

如何使用DPAPI加密SecureString以保存到磁盘,而无需先转换为不安全的字符串?

我想使用DPAPI加密SecureString,以便将其保存到磁盘。

.net DPAPI类是ProtectedData类,但是ProtectedData.Protect具有单个重载,该重载采用字节数组。没有接受SecureString的重载。

在.NET app.config文件中的加密密码中,John Galloway通过首先将SecureString转换为不安全的字符串来利用上述重载。我想避免这种情况,因为它首先破坏了使用SecureString的目的。

该ConvertFrom-SecureString的 PowerShell命令似乎做我所需要的,因为“如果没有指定键,Windows数据保护API(DPAPI)用于加密标准字符串表示”但我不知道我怎么会使用此cmdlet直接从.net或即使这样做是一个好主意。

.net securestring

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

在node.js中,如何验证缓冲区中的UTF8数据?

我需要验证缓冲区是否包含有效的 UTF-8 数据。

\n\n

在 Python 中,我可以通过简单地尝试解码字节并检查异常来完成此操作。\n在下面的示例中,我尝试解码编码的 \'\xc2\xa2\' 的第一个字节。异常告诉我缺少字节。

\n\n
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32\nType "help", "copyright", "credits" or "license" for more information.\n>>> s = \'\xc2\xa2\'\n>>> s_bytes[:1].decode()\nTraceback (most recent call last):\n  File "<stdin>", line 1, in <module>\nUnicodeDecodeError: \'utf-8\' codec can\'t decode byte 0xc2 in position 0: unexpected end of data\n
Run Code Online (Sandbox Code Playgroud)\n\n

这种方法在 Node.js 中不起作用,因为解码更加宽容。

\n\n
> s = \'\xc2\xa2\'\n\'\xc2\xa2\'\n> s_buffer = Buffer(s)\n<Buffer c2 a2>\n> s_buffer.toString(\'utf8\', 0, 1)\n\'?\'\n>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我检查了Buffer API …

utf-8 node.js

5
推荐指数
0
解决办法
991
查看次数

ASP.net运行状况监视是否与asmx Web服务一起使用

我正在尝试使用ASP.net运行状况监视来记录来自asmx Web服务的未处理异常.我在web.config中启用了运行状况监视,但它没有记录任何内容.健康监测是否适用于asmx Web服务?我已经google了一下,似乎其他人也问了同样的问题,但从来没有得到明确的答案.

c# asp.net asmx health-monitoring

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

使用ComputedProperty是否安全?

我需要支持App Engine中的计算属性.我下载了最新的源代码版本以尝试自己实现它们.在浏览代码的过程中,我遇到了一个似乎完全符合我需要的属性类.

class ComputedProperty(Property):
  """Property used for creating properties derived from other values.

  Certain attributes should never be set by users but automatically
  calculated at run-time from other values of the same entity.  These
  values are implemented as persistent properties because they provide
  useful search keys.

  ...
  """
Run Code Online (Sandbox Code Playgroud)

它没有文件证明的问题; 我ComputedProperty在官方文档中找不到任何相关内容.

那么ComputedProperty使用安全还是有缺陷或/并且可能会发生变化?

python google-app-engine

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

有没有办法让文档字符串与它们记录的函数分开?

我正在研究一个具有许多小函数的模块,但其文档字符串往往很长.文档字符串使得模块工作变得烦人,因为我必须不断滚动一个长文档字符串来查找一些实际代码.

有没有办法让文档字符串与它们记录的函数分开?我真的希望能够在远离代码的文件末尾指定文档字符串,或者甚至更好地在单独的文件中指定.

python docstring

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