小编Ter*_*nce的帖子

NavigationService.navigate空引用异常

我正在学习WP编码,我遇到了无法解决的问题:/

try
 {
    NavigationService.Navigate(new Uri("/edit.xaml", UriKind.Relative));
 }
 catch (Exception ex)
 {
     MessageBox.Show(ex.Message.ToString(),"Error!",MessageBoxButton.OK);
 }
Run Code Online (Sandbox Code Playgroud)

edit.xaml与MainPage.xaml位于同一目录中

它抛出"NullReferenceException"

c# windows-phone-7

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

如何为每个匹配生成唯一Guids

我正在尝试编写一个在找到匹配项时生成新GUID的脚本.我的问题是我一直为所有匹配生成相同的GUID.如何在不为所有匹配项生成相同GUID的情况下执行此操作?

$testString = @"
    [assembly: Guid Should Replace]
    [assembly: Guid Should Replace]    
    [assembly: Guid Should Replace]
"@
    #expected output
    #[assembly: "unique guid"]


    function ReplaceWithNewGuid {
        param($content)
        $retval = ($content -ireplace '(?m)(\[assembly: Guid.*$)+', "[assembly: Guid(`"$([guid]::NewGuid())`"]`)")
        return $retval
    }

    ReplaceWithNewGuid($testString)
Run Code Online (Sandbox Code Playgroud)

实际输出示例:

[议会:Guid("29e784aa-ba4a-4a45-85b8-d6b52916b539"])

[议会:Guid("29e784aa-ba4a-4a45-85b8-d6b52916b539"])

[议会:Guid("29e784aa-ba4a-4a45-85b8-d6b52916b539"])

更新

@Mathias R. Jessen的答案帮助我得到了我需要的东西.我想我可以在powershell中使用.net框架库来实现这一点但是,这可以按预期工作.

function ReplaceWithNewGuid {
    param($content)
    $retval = [regex]::Replace($testString, '(?m)(\[assembly: Guid.*$)+', {param($m) return "[assembly: Guid(`""+ (New-Guid).Guid + "`")]"}, 'IgnoreCase')
    return $retval
}
Run Code Online (Sandbox Code Playgroud)

regex powershell guid

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

C#中的自动生成

试图围绕perl的Autovivification并根据它听起来的样子,它似乎与C#中的动态类似,因为动态对象直到运行时才被分配类型,或者我完全不在这里.如果是这样,那么我是否可以在C#中建立一个有意义的理念?

编辑
好吧所以我显然已经离开了.因此,作为2部分问题的第二部分,在C#中有什么概念上可比的吗?要明确我正在寻找一个与Autovivification相当的C#概念.不必完全相同,但在概念上足够接近才有意义.正如我所说的那样,我绝不是任何想象中的perl黑客或蟒蛇黑客,但我熟悉基于c语言的C,C++,C#,java,javascript.我正在考虑C#的动态,但是现在我正在考虑根据这里的信息进行延迟加载,如果这有帮助....

c# perl dynamic .net-4.0 autovivification

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

不知道为什么我的div没有显示验证消息

Ello堆栈,Cant似乎弄清楚为什么在验证字段后我的div中没有​​显示任何文本.这是我的代码.我知道验证正在运行但是,我不确定为什么我的验证消息没有显示在div中.

<html>
<head>
    <script src="Scripts/jquery-1.5.2.js" type="text/javascript"></script>
    <script src="http://localhost:62147/Scripts/jquery.validate.js" type="text/javascript"></script>
    <script type="text/javascript">
        "use strict";
        $(document).ready(function () {

            $("#testerbtn").bind("click", function () {
                alert("onclick is fired");
                $("#myform").validate({
                    errorLabelContainer: $("#Errors"),
                    rules: {
                        textToVal: { required: true }
                    },
                    messages: {
                        textToVal: "the field is required! nub~!"
                    }
                });
                alert("validation should have happend.");

            })
        });

    </script>
    <title>Test Page</title>
</head>
<body>
    <form id = "myform" action="htmlPage1.htm">
         <div id="Errors"></div>
        <div>
            <input type="text" id="textToVal"  value="" />
            <input type="button" id="testerbtn"  value="Tester" />
        </div>
    </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html jquery jquery-validate

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