问题列表 - 第31054页

as3 停止事件传播

当我在事件侦听器中添加新的事件侦听器时,我无法让事件停止在 as3 中传播。当我不希望的时候,我的第二个事件侦听器被调用。

this.addEventListener(MouseEvent.CLICK, firstlistener);

function firstlistener(e:Event)
{
    //do stuff
    e.stopImmediatePropagation();
    this.addEventListener(MouseEvent.CLICK, secondlistener);
}
Run Code Online (Sandbox Code Playgroud)

flash actionscript-3

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

如果我重新开始,我应该从Watir-WebDriver开始吗?

我的团队有一个使用watir的自动化解决方案.事实上,我们有两个版本,一个用于我们的软件,另一个用于另一个版本.我发现改变版本的watir并不容易,所以我想为我的新项目选择合适的版本(建立一个像Jim Knowlton谈论Watir Podcast#30的探索性框架).

我们的产品支持IE和Firefox.它可以支持将来的其他浏览器,例如Chrome或Safari.虽然我们创建了一个webdriver框架来更好地访问属性,但大多数接口技术都得到了watir的支持.

所以我认为Watir Webdriver可能是我今天最好的选择.没有使用它,甚至没有用它来评论别人的快乐,我只是不确定它是否准备好了.你怎么看?

automated-tests webdriver cross-browser watir

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

CA1026(所有参数应具有默认值)和扩展方法

前提

使用带有C#可选参数的代码分析(或fxCop)时,您可以收到CA1026的警告.对此的简短原因1不是使用默认值来提供所有参数.

下面的声明正确地生成了此警告

public Color GetColor(bool red, bool blue = true, bool green = true)
Run Code Online (Sandbox Code Playgroud)

但是,有一种情况是您无法使用默认值提供所有参数,这就是扩展方法.因此,下面的声明会因为第一个参数而生成警告:

public static bool ValidateRules(this string s, Rules rules = Rules.Default)
Run Code Online (Sandbox Code Playgroud)

编译器不允许您在this参数上指定默认值,因此只有两个解决方案是:

  1. 忽略警告,我不喜欢这样做,因为它会导致不良做法.
  2. 不使用扩展方法,我不喜欢这样做,因为我发现扩展方法使代码更易读.

问题

  • 以上两个选项是解决这个问题的唯一方法吗?
  • fxCop/Code Analysis在检查中是否不正确?

  1. 长期的原因

c# extension-methods code-analysis fxcop

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

某些Python函数的.NET等价物

我试图将一些Python代码移植到.NET,我想知道在.NET中是否存在以下Python函数的等价物,或者某些具有相同功能的代码片段.

os.path.split()
os.path.basename()
Run Code Online (Sandbox Code Playgroud)

编辑

Python中的os.path.basename()返回os.path.split的尾部,而不是System.IO.Path.GetPathRoot(path)的结果

我认为以下方法创建了一个合适的os.path.split函数端口,欢迎任何调整.它遵循http://docs.python.org/library/os.path.html中对os.path.split的描述,我认为尽可能多.

    public static string[] PathSplit(string path)
    {
        string head = string.Empty;
        string tail = string.Empty;

        if (!string.IsNullOrEmpty(path))
        {
            head = Path.GetDirectoryName(path);
            tail = path.Replace(head + "\\", "");
        }

        return new[] { head, tail };
    }
Run Code Online (Sandbox Code Playgroud)

我不确定我返回头部和尾部的方式,因为我真的不想通过参数传递头部和尾部的方法.

c# python porting

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

C#通用序列化实用程序类

我有一个现有的类,用于序列化和反序列化XML中的对象.它是一个具有单个类型参数T的泛型类,其唯一约束是where T : IXmlSerializable.但是,我仍然希望能够在没有实现IXmlSerializable但具有该[Serializable]属性的类上使用此类.我怎么能这样做?

从我的通用类:

public static class XmlSerializationUtils<T> where T : IXmlSerializable
{
    public static T DeserializeXml(XmlDocument xml) { ... }
    public static XmlDocument SerializeToXml(T toSerialize) { ... }
}
Run Code Online (Sandbox Code Playgroud)

我发现了这个讨论,但没有给出解决方案,只是我做不到where T : Serializable.试图做的where T : SerializableAttribute是使Visual Studio说"不能使用密封类'System.SerializableAttribute'作为类型参数约束".

编辑:根据Stephen的回答,我删除了约束XmlSerializationUtils<T>并添加了这个静态构造函数:

static XmlSerializationUtils()
{
    Type type = typeof(T);
    bool hasAttribute = null != Attribute.GetCustomAttribute(type,
        typeof(SerializableAttribute));
    bool implementsInterface =
        null != type.GetInterface(typeof(IXmlSerializable).FullName);
    if …
Run Code Online (Sandbox Code Playgroud)

c# generics constraints xml-serialization

6
推荐指数
3
解决办法
9035
查看次数

调车场:运营商缺少参数

我正在实施分流码算法.我在检测运营商缺少参数时遇到问题.在维基百科条目是非常糟糕的这个话题,和他们的代码也崩溃了下面的例子.

例如3 - (5 + )是不正确的,因为+缺少一个参数.

就在算法到达之前),运算符堆栈包含- ( +并且操作数堆栈包含3 5.然后它是这样的:

  • +从操作员堆栈中弹出
  • 发现这+是一个二元运算符
  • 弹出两个操作数,应用运算符并将result(8)推送到操作数堆栈
  • 然后它(从堆栈中弹出匹配,然后继续

那么如何才能发现+缺少一个参数呢?额外的荣誉,如果你也更新维基百科:-)

c++ algorithm parsing wikipedia shunting-yard

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

从IntelliJ代码格式中排除页面中的部分

是否有任何可能的方法让IntelliJ-not-格式成为页面的一部分?

我正在使用XHTML和facelets,但这可以应用于任何页面.如果可以在代码中执行此操作,我也很好奇.

谢谢.

code-formatting intellij-idea java-ee

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

离线Amazon S3

所以我想尝试使用Heroku作为我的服务器,但Heroku不允许写入其文件系统.相反,我需要使用数据库和Amazon S3之类的东西来存储上传的图像等内容.

问题是我在开发时经常没有互联网访问权限.或者非常差的互联网接入.因此,为Amazon S3开发是不切实际的.是否有可以使用的离线版本,以便我的本地计算机可以充当S3云,而在测试/生产环境中,我可以使用真正的S3?

amazon-s3

9
推荐指数
2
解决办法
4394
查看次数

一段时间后重定向网站

我需要做些什么才能在网站上有一个功能,它会在3秒左右的时间内将你重定向到网站?

html redirect

124
推荐指数
5
解决办法
32万
查看次数

在FileName中摆脱多个句点的问题

我试图获取看起来像这样的文件名:
MAX_1.01.01.03.pdf看起来像Max_1010103.pdf.

目前我有这个代码:

public void Sanitizer(List<string> paths)
{
  string regPattern = (@"[~#&!%+{}]+");
  string replacement = " ";

  Regex regExPattern = new Regex(regPattern);
  Regex regExPattern2 = new Regex(@"\s{2,}");
  Regex regExPattern3 = new Regex(@"\.(?=.*\.)");
  string replace = "";

  var filesCount = new Dictionary<string, int>();
  dataGridView1.Rows.Clear();

  try
  {
    foreach (string files2 in paths)
    {
      string filenameOnly = System.IO.Path.GetFileName(files2);
      string pathOnly = System.IO.Path.GetDirectoryName(files2);
      string sanitizedFileName = regExPattern.Replace(filenameOnly, replacement);
      sanitizedFileName = regExPattern2.Replace(sanitizedFileName, replacement);
      string sanitized = System.IO.Path.Combine(pathOnly, sanitizedFileName);

      if (!System.IO.File.Exists(sanitized))
      {
        DataGridViewRow clean = new …
Run Code Online (Sandbox Code Playgroud)

c# regex

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