问题列表 - 第40003页

Web应用程序的GetEntryAssembly

Assembly.GetEntryAssembly()不适用于Web应用程序.

但是......我真的需要这样的东西.我使用了一些在Web和非Web应用程序中使用的深层嵌套代码.

我目前的解决方案是浏览StackTrace以找到第一个被调用的程序集.

/// <summary>
/// Version of 'GetEntryAssembly' that works with web applications
/// </summary>
/// <returns>The entry assembly, or the first called assembly in a web application</returns>
public static Assembly GetEntyAssembly()
{
    // get the entry assembly
    var result = Assembly.GetEntryAssembly();

    // if none (ex: web application)
    if (result == null)
    {
        // current method
        MethodBase methodCurrent = null;
        // number of frames to skip
        int framestoSkip = 1;


        // loop until we cannot got further in …
Run Code Online (Sandbox Code Playgroud)

c# reflection code-generation assemblies stack-frame

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

如何在java中对JSON对象进行排序?

我一直在寻找一段时间,想要一种方法来排序这样的JSON对象:

{"results": [
  {
    "layerId": 5,
    "layerName": "Pharmaceutical Entities",
    "attributes": {
      "OBJECTID": "35",
      "FACILITYTYPE": "Pharmacy",
      "FACILITYSUBTYPE": "24 Hr Pharmacy",
      "COMMERCIALNAME_E": "SADD MAARAB PHARMACY"
      },
    "geometryType": "esriGeometryPoint",
   },
  {
    "layerId": 5,
    "layerName": "Pharmaceutical Entities",
    "attributes": {
      "OBJECTID": "1",
      "FACILITYTYPE": "Pharmacy",
      "FACILITYSUBTYPE": "24 Hr Pharmacy",
      "COMMERCIALNAME_E": "GAYATHY HOSPITAL  PHARMACY"
    },
    "geometryType": "esriGeometryPoint",
  },
     {
    "layerId": 5,
    "layerName": "Pharmaceutical Entities",
    "attributes": {
      "OBJECTID": "255",
      "FACILITYTYPE": "Pharmacy",
      "FACILITYSUBTYPE": "24 Hr Pharmacy",
      "COMMERCIALNAME_E": "AL DEWAN PHARMACY"
      },
    "geometryType": "esriGeometryPoint",
   }
]}
Run Code Online (Sandbox Code Playgroud)

并按"COMMERCIALNAME_E"的值按字母顺序排序:

{"results": [
   { …
Run Code Online (Sandbox Code Playgroud)

java json

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

番石榴:如何结合过滤和转换?

我有一个字符串的集合,我想将它转换为字符串集合全部为空或null删除字符串,其他所有字符串都被修剪.

我可以分两步完成:

final List<String> tokens =
    Lists.newArrayList(" some ", null, "stuff\t", "", " \nhere");
final Collection<String> filtered =
    Collections2.filter(
        Collections2.transform(tokens, new Function<String, String>(){

            // This is a substitute for StringUtils.stripToEmpty()
            // why doesn't Guava have stuff like that?
            @Override
            public String apply(final String input){
                return input == null ? "" : input.trim();
            }
        }), new Predicate<String>(){

            @Override
            public boolean apply(final String input){
                return !Strings.isNullOrEmpty(input);
            }

        });
System.out.println(filtered);
// Output, as desired: [some, stuff, here]
Run Code Online (Sandbox Code Playgroud)

但是有没有一种将这两种行为合并为一步的番石榴方式?

java guava

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

jquery serialize和encodeURIComponent

我需要URI编码一个表单输入,然后用一堆隐藏的输入序列化并发送到PHP文件..是否有可能以某种方式将encodeURIComponent组合到这一行?:

var landingCreate = $(this).serialize();
Run Code Online (Sandbox Code Playgroud)

更新:

例如这样做:

var landingCreate = $(this).serialize()+"&enc="+encodeURIComponent($('input[name=\'longform\']').val());
Run Code Online (Sandbox Code Playgroud)

并输入网址:

http://www.smashingmagazine.com/2008/10/13/pricing-tables-showcase-examples-and-best-practices/
Run Code Online (Sandbox Code Playgroud)

进入文本框,返回URL不变..不应该将所有破折号和斜线等转换为十六进制代码吗?

UPDATE

这是完整的代码.

<form id="createTokenLanding">
    <input type="text" name="longform" />
    <input type="hidden" name="domain" value="<?php echo rawurlencode($_SERVER['HTTP_HOST']); ?>" />
    <input type="hidden" name="useragent" value="<?php echo rawurlencode($_SERVER['HTTP_USER_AGENT']); ?>" />
    <input type="hidden" name="ip" value="<?php echo rawurlencode($_SERVER['REMOTE_ADDR']); ?>" />
    <input type="hidden" name="cookieuser" value="<?php echo rawurlencode($_COOKIE['littlr_user']); ?>" />
    <input type="submit" name="submit" value="Shorten" />
</form>

<div id="result">
123
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $.ajaxSetup ({ cache: false });
        $('#createTokenLanding').submit(function() {
            var landingCreate = $('#createTokenLanding').serialize();
            $.ajax({
                url: …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery

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

如何获取最新的标签名称?

如何获取当前分支的最新标签名称(如版本)?

git

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

JSON序列化一个DOM元素

如果我做:

var el =
{
   o : document.createElement("iframe")
}

var fs = JSON.stringify(el);

and then I try to access with

var ofs = JSON.parse(fs);
Run Code Online (Sandbox Code Playgroud)

ofs.o 包含一个空对象而不是iframe元素为什么?

javascript json

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

隐藏除一个div及其子元素之外的所有元素

如何使用jquery隐藏除一个div及其子元素之外的所有元素?

jquery hide

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

在新选项卡中打开时,nerdtree自动对焦到文件

我在Linux上使用NerdTree.在使用't'在新选项卡中打开文件后,我想从书呆子树缓冲区跳转到文件缓冲区.我需要一直按"Ctrl + W + W".

有关如何在创建新缓冲区后让vi执行CWW的任何想法.

Sairam

vim nerdtree

21
推荐指数
2
解决办法
8024
查看次数

boost :: shared_ptr和动态强制转换

我使用shared_ptr基类的问题,我似乎无法在解除引用它时调用派生类的方法.我相信代码会比我更冗长:

class Base : public boost::enable_shared_from_this<Base>
{
  public:
    typedef  boost::shared_ptr<BabelNet> pointer;
};

class Derived : public Base
{
  public:
     static pointer  create()
                {
                        return pointer(new Derived);
                }
     void             anyMethod()
     {
        Base::pointer foo = Derived::create();
        // I can't call any method of Derived with foo
        // How can I manage to do this ?
        // is dynamic_cast a valid answer ?
        foo->derivedMethod(); // -> compilation fail
     }

};
Run Code Online (Sandbox Code Playgroud)

c++ boost dynamic-cast boost-smart-ptr

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

轨道单元测试是否应该命中数据库?

我一直在为我的rails应用程序编写测试.我使用TestUnit进行单元测试和功能测试.我也使用黄瓜进行GUI测试.

但是我发现http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database说单元测试最好不要打到数据库.

我同意击中数据库需要相当长的时间.我已经使用spork来减少环境负荷.

在测试rails应用程序时,最佳做法是什么?

testing unit-testing ruby-on-rails

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