小编fej*_*ese的帖子

如何枚举传递的方法参数

可以枚举被调用的方法参数类型/信息,如下所示:

private void SomeMethod(int thisValue, string thatValue)
{
  StackTrace stackTrace = new StackTrace();
  foreach (ParameterInfo pInfo in stackTrace.GetFrame(0).GetMethod().GetParameters())
  {
    string name = pInfo.Name;
    string type = pInfo.GetType().ToString();
  }
}
Run Code Online (Sandbox Code Playgroud)

但有没有办法得到每个参数的实际对象?

编辑:我的目标是枚举所有参数并获取它们的值.使用LinQ表达式,可以获得如下参数值:

private void SomeMethod(int thisValue, string thatValue)
{
  object valueOfThis = GetParameterValue(() => thisValue);
  object valueOfThat = GetParameterValue(() => thatValue);
}
private object GetParameterValue<T>(Expression<Func<T>> expr)
{
  var body = ((MemberExpression)expr.Body);
  return ((FieldInfo)body.Member).GetValue(((ConstantExpression)body.Expression).Value);
}
Run Code Online (Sandbox Code Playgroud)

但我想做的是:

foreach (fooObject o in thisMethod.GetParameterObjects())
{
  object someValue = GetParameterValue(() => fooObject);
}
Run Code Online (Sandbox Code Playgroud)

因此,有一个通用的方法来收集所有参数及其值.

c# reflection

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

JUnit:检查是否调用了void方法

我有一个非常简单的文件监视器类,如果文件已更改,则每2秒检查一次,如果是,onChange则调用方法(void).有没有一种简单的方法来检查onChange方法是否在单元测试中被调用?

码:

public class PropertyFileWatcher extends TimerTask {
    private long timeStamp;
    private File file;

    public PropertyFileWatcher(File file) {
        this.file = file;
        this.timeStamp = file.lastModified();
    }

    public final void run() {
        long timeStamp = file.lastModified();

        if (this.timeStamp != timeStamp) {
            this.timeStamp = timeStamp;
            onChange(file);
        }
    }

    protected void onChange(File file) {
        System.out.println("Property file has changed");
    }
}
Run Code Online (Sandbox Code Playgroud)

测试:

@Test
public void testPropertyFileWatcher() throws Exception {
    File file = new File("testfile");
    file.createNewFile();
    PropertyFileWatcher propertyFileWatcher = new PropertyFileWatcher(file);

    Timer …
Run Code Online (Sandbox Code Playgroud)

java junit

11
推荐指数
2
解决办法
4万
查看次数

无法动态设置setVisibility()参数

我正在尝试设置按钮的可见性,如下所示:

public Bundle setActivityState(Bundle bundle){
    startBtn = (Button) findViewById(R.id.startSensorsBtn);

    startBtn.setVisibility(
            getVisibilityState(bundle, PersistanceConstants.START_BTN_STATE)
    );          

    return bundle;
}

public int getVisibilityState(Bundle bundle, String keyName){
    if (bundle.getInt(keyName) == View.VISIBLE){
        return View.VISIBLE;
    } else if (bundle.getInt(keyName) == View.INVISIBLE){
        return View.INVISIBLE;
    } else if (bundle.getInt(keyName) == View.GONE){
        return View.GONE;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是我收到了错误:

Must be one of: View.VISIBLE, View.INVISIBLE, View.GONE less... (Ctrl+F1) 
Reports two types of problems:
- Supplying the wrong type of resource identifier. For example, when calling Resources.getString(int id), you should be …
Run Code Online (Sandbox Code Playgroud)

java android view

10
推荐指数
2
解决办法
2983
查看次数

从非ssl端口8080重定向到ssl端口8443

我试图将非SSL端口8080上的流量重定向到SSL端口8443(在Jboss 4.2.3.GA版本上),但它无法正常工作.当我在这个端口上访问我的webapplication时,它会停留在该端口上并显示页面.这是我在server.xml文件中的配置

<Connector port="8080" address="${jboss.bind.address}"    
     maxThreads="250" maxHttpHeaderSize="8192"
     emptySessionPath="true" protocol="HTTP/1.1"
     enableLookups="false" redirectPort="8443" acceptCount="100"
     connectionTimeout="20000" disableUploadTimeout="true"/>

<!-- Define a SSL HTTP/1.1 Connector on port 8443
     This connector uses the JSSE configuration, when using APR, the 
     connector should be using the OpenSSL style configuration
     described in the APR documentation -->

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
           maxThreads="150" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS" keystoreFile="conf/sds/keystore"/>
Run Code Online (Sandbox Code Playgroud)

这是web.xml配置

<security-constraint>
  <web-resource-collection>
    <web-resource-name>SUCTR</web-resource-name>
    <url-pattern>/*</url-pattern>      
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

我尝试使用默认端口80和443,并使用url-pattern中的特定路径,但仍然无法正常工作.我不确定我在这里做错了什么,请你指点我正确的方向.

谢谢.

ssl jboss redirect

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

jQuery使用参数绑定和取消绑定事件

我试图将事件绑定到textbox包含参数的事件.以下看起来好像应该这样做,但每次页面加载时,它都会被执行.

jQuery(function(){
    jQuery('#textbox').bind('click', EventWithParam('param'));
});
Run Code Online (Sandbox Code Playgroud)

每次页面加载时都会使用该参数调用该事件.这可能不起作用,因为不支持带参数的事件.如果是这样,还有另一条路线吗?

jquery bind unbind

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

可以在phpunit的类级别使用@group注释

我正在尝试探索在类级别上使用@group@author注释的可能性,以便我可以为特定的人分配某种所有权.另外,有了这个,我计划对事物进行宏观管理,例如:如果我想要运行一个或多个类(完整地),我可以将它们的组指定为ABC,然后使用--groups选项.

目前,我认为@groups@author仅用于测试用例级别,而不是测试级别.我认为一个类可能有数百个测试用例,写作@author或者@group非常繁琐.并且在将来,如果所有权发生变化,我们需要在任何地方更改注释属性.因此,有没有办法@group在课堂上指定或类似的东西?

php phpunit annotations

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

为什么我的PHP cron脚本不会播放声音?

我正在制作一个小型应用程序按时间表响铃,可以从网站上更新.一切都运行良好,除了作为cron作业安排的脚本在脚本运行时不会播放声音.我已经向脚本添加了输出管道和echo命令,以验证cron是否正在运行它,但播放声音的部分不起作用.从CLI手动运行时,脚本按预期工作.

该脚本根据时间表提取一天中每个时段的时间和声音文件,然后将与声音文件关联的时间与当前时间进行比较 - 如果匹配,它将

exec("/usr/bin/aplay /var/www/site/".$soundfile);
Run Code Online (Sandbox Code Playgroud)

然后Cron计划在上学期间每分钟运行一次这个脚本:

* 8-16 * 1-6,9-12 1-5 root /usr/bin/php -f /var/www/site/scripts/playsound.php > /dev/null
Run Code Online (Sandbox Code Playgroud)

同样,如果我在安排声音时手动运行脚本,声音将通过连接的扬声器播放.当我有测试代码回显到屏幕或输出到输入的文件时,cron会将输出转储到文件中,确认它按计划运行脚本.它只是不会播放脚本的声音部分.

我检查了所有权限,因为其他一切正常,它们似乎是准确的.我甚至可以编写一个简单的BASH脚本来让Cron按计划播放声音,因此系统似乎有正确的组成员资格来访问脚本和声音文件.我已经转出exec()shell_exec(),仅使用命令以及绝对路径的命令审判,cron作业计划以root身份运行.仍然无法弄清楚为什么这个小功能不幸对这个程序的成功如此重要将无法奏效.

任何意见是极大的赞赏.

php linux audio bash cron

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

用空格分割字符串

我有一个字符串,里面有两个单词:

猫狗

我怎么能把这些分开,所以我得到:

Str1 = CatStr2 = Dog

请注意这是针对VB6的.

string vb6

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

谷歌浏览器 - 在哪里获得所有的注册政策标志?

在一些银行,政府谷歌Chrome浏览器受到当地政策的影响,因此当我们到现场时,我们的稳定应用程序不再起作用.

由于没有关于本地注册机构变更的详细文档,人们浪费了数月来解决银行,政府区域中的一些小问题.

任何人都可以列出整个注册价值的神秘之处,这使得谷歌浏览器的修改,例如我看到有人禁用网络摄像头,禁用麦克风,禁用触摸屏等等(有一个巨大的设置,但没有身体记录它们,我们可以有他们都扔在这里?).

windows policy google-chrome

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

使用 post 参数导航到 Javascript 中的新 URL

我想知道是否有任何方法可以使用带有 POST 参数的JavaScript导航到新 URL 。

我知道使用 GET 您可以使用以下方法在 URL 上附加一个参数字符串 window.location.replace()

但是有什么方法可以使用 POST 来隐藏参数。还是用jQuery

javascript ajax jquery post

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

标签 统计

java ×2

jquery ×2

php ×2

ajax ×1

android ×1

annotations ×1

audio ×1

bash ×1

bind ×1

c# ×1

cron ×1

google-chrome ×1

javascript ×1

jboss ×1

junit ×1

linux ×1

phpunit ×1

policy ×1

post ×1

redirect ×1

reflection ×1

ssl ×1

string ×1

unbind ×1

vb6 ×1

view ×1

windows ×1