小编Sve*_*enL的帖子

什么是is-operator的好用法

什么是了就是运营商的使用情况如何?

下面用于转换的构造不是推荐的方法,实际上所有文档都喜欢使用空检查的as-operator.

if(obj is SomeClass)
{
  SomeClass some = (SomeClass)obj;
  ....
}
Run Code Online (Sandbox Code Playgroud)

确定这是(非常小的)性能提升,有些甚至提到了胎面安全性.是的,这是真的......

那么,为什么我们有is-operator?
"as-operator with a null-check"在哪里不起作用或不是可行的方法?
通过使用is-operator来限制您声明的范围是否有优势?

c#

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

xsl:sort,为什么不工作?

我正在尝试使用xslt生成html页面(使用VS 2010作为编辑器和'编译器/转换器').大多数这种方法效果很好并生成有效的xhtml,但是当尝试<xsl:sort />在订单的帮助下生成排序列表时,根本不会受到影响.我已经看到它有效,但在尝试确定我的问题并在下面创建示例代码时,我的<xsl:sort />工作都没有.

拜托,谁可以告诉我我的错误.

以下是我的示例文件.

sample.xml中

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl" ?>
<people>
    <person name="Jack" age="12">
        <adress>First road</adress>
    </person>
    <person name="Bob" age="8">
        <adress>Third road</adress>
    </person>
    <person name="Peter" age="20">
        <adress>Second road</adress>
    </person>
    <person name="Juli" age="65">
        <adress>Last road</adress>
    </person>
    <person name="Abbot" age="21">
        <adress>No road</adress>
    </person>
</people>
Run Code Online (Sandbox Code Playgroud)

sample.xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

    <xsl:output
        method="xml"
        omit-xml-declaration="yes" indent="yes"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <title>Sample</title>

                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> …
Run Code Online (Sandbox Code Playgroud)

xml xslt

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

"范围''引用的'System.Boolean'类型的"变量",但未在Expression中定义

我正在尝试为(在运行时)为所有类型的委托创建包装器创建一个方法.这样可以创建一种灵活的注入额外日志记录的方法(在本例中).在第一步中,我尝试围绕给定的input-argument 创建try-catch包装.

try
{
  Console.WriteLine(....);
  // Here the original call
  Console.WriteLine(....);
}
catch(Exception ex)
{
  Console.WriteLine(.....);
}
Run Code Online (Sandbox Code Playgroud)

我正在使用泛型方法调用CreateWrapper2(见下文)

private static readonly MethodInfo ConsoleWriteLine = typeof(Console).GetMethod("WriteLine", new[] { typeof(string), typeof(object[]) });

private static MethodCallExpression WriteLinExpression(string format, params object[] args)
{
    Expression[] expressionArguments = new Expression[2];
    expressionArguments[0] = Expression.Constant(format, typeof(string));
    expressionArguments[1] = Expression.Constant(args, typeof(object[]));

    return Expression.Call(ConsoleWriteLine, expressionArguments);
}

public T CreateWrapper2<T>(T input)
{
    Type type = typeof(T);

    if (!typeof(Delegate).IsAssignableFrom(type))
    {
        return input;
    }

    PropertyInfo methodProperty = type.GetProperty("Method");
    MethodInfo …
Run Code Online (Sandbox Code Playgroud)

c# expression

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

标签 统计

c# ×2

expression ×1

xml ×1

xslt ×1