问题列表 - 第43037页

如何检测T是否为IEnumerable <T2>,如果是,则获取T2的类型?

我知道这个问题,它是后续的,也是这个问题,但我不能把它们放在一起,以帮助我做我想做的事情:

我有一个泛型类型,我想检查T是否为structOR,如果它实现IEnumerable<T2>,那么我想检查T2是否struct.

到目前为止,我已经到了这里('请原谅代码,这是实验性的):

private class TestClass<T>
{
    public TestClass()
    {
        Type type = typeof(T);
        //(detecting T == IEnumerable<something> ommitted for clarity)
        Type enumerableType = type.GetInterfaces()
                .Where(t => t.IsGenericType)
                .Select(t => t.GetGenericTypeDefinition())
                .Where(t => t == typeof(IEnumerable<>))
                .FirstOrDefault();
        if(enumerableType != null) 
        {
            Type enumeratedType = type.GetGenericArguments().First();
            if(!enumeratedType.IsValueType) //throw etc...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题enumerableTypeIEnumerable<>,所以enumeratedType它出来了T,而不是我传入的任何东西(例如new TestClass<int[]>()).

c# generics reflection

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

如何在Android MapView中禁用pinch

如何在Android MapView中禁用捏合或多点触控功能?

android google-maps multi-touch

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

F#构造函数语法

当使用.net类时,有些情况下我们不需要括号来传递单个参数,例如

let foo = DirectoryInfo "boo"
Run Code Online (Sandbox Code Playgroud)

但是使用单个参数稍微复杂一些,我们确实需要括号...当这是真的时,是否有人知道解析规则?

f#

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

使用SpringJUnit4ClassRunner自定义BeanFactory?

通过创建缓存bean工厂终于解决了类型问题慢速自动装配问题.

我真的希望能够将这样的CachingByTypeBeanFactory与SpringJUnit4ClassRunner一起用于使用@Autowired运行JUnit测试.但似乎无法通过ContextLoader在应用程序上下文中更改Bean Factory.

有没有其他方法可以做到这一点?

java spring

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

在我自己的服务器上托管Private Git回购?

我正在寻找一种在我自己的服务器上托管私人git repos的方法.
我正在使用Github作为我的开源项目,但我更喜欢使用自己的服务器来存储私有git存储库.

有人可以建议我应该使用哪个脚本来实现此目的.
但Trac不是我想要的.我想要的东西,最好是基于PHP的解决方案(只是可选的)和esp.具有更简单UI的东西.

这里有任何帮助.

git

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

调试窗口小部件会导致ANR

我正在尝试调试AppWidget,但是我遇到了一个问题:D如果没有设置断点,那么小部件可以在没有ANR的情况下工作,并且命令Log.v可以完美地执行.然后我在方法的顶部放置了一个断点:

    public void onReceive(Context context, Intent intent) {
    Log.v(TAG, "onReceive 1"); // BP on this line
    super.onReceive(context, intent);
    String action = intent.getAction();

    // Checks on action and computations ...

    Log.v(TAG, "onReceive 2");
    updateWidget(context);
    Log.v(TAG, "onReceive 3");
}
Run Code Online (Sandbox Code Playgroud)

断点按预期停止执行,但随后进程终止.问题是断点(我猜xD)会导致ANR并且ActivityManager会终止进程.那是日志:

01-07 14:32:38.886: ERROR/ActivityManager(72): ANR in com.salvo.wifiwidget
01-07 14:32:38.886: INFO/Process(72): Sending signal. PID: 475 SIG: 9
......
......
01-07 14:32:38.906: INFO/ActivityManager(72): Process com.salvo.wifiwidget (pid   475) has died.
Run Code Online (Sandbox Code Playgroud)

这会导致调试停止.所以问题是:有一种方法来调试小部件而不会引起ANR?提前感谢您的答案

eclipse android android-widget

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

java引用数组中的对象

是否有一个类似的函数indexof()将搜索字符串数组(最好是未排序)的字符串并返回它的索引?(或者可能是纵坐标值?)

例如我正在尝试:

String[] colours= {"Red", "Orange", "Yellow"};

System.out.println("indexOf(Red) = " +
        colours.indexOf("Red"));
Run Code Online (Sandbox Code Playgroud)

......但没有成功.

谢谢.

AV

ps这最终需要在二维数组中工作(如果重要的话)

c++ java arrays algorithm indexing

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

键入字典键的安全性?

我打算在项目中使用多个名称索引字典.我的第一选择是使用一个string键,它只是我Value元素的Name属性.

但是,即使它们访问不同类型,这也会使字典键完全相同:

private Dictionary<string, Foo> myFoos;
private Dictionary<string, Bar> myBars;

myFoos[bar.Name];  // shouldn't be able to do this!
Run Code Online (Sandbox Code Playgroud)

我希望密钥彼此不兼容,使它们无法互相混淆:

private Dictionary<FooName, Foo> myFoos;
private Dictionary<BarName, Bar> myBars;
Run Code Online (Sandbox Code Playgroud)

由于*Name为每种Value类型创建一个类是过度的,我创建了一个Name<T>类:

public struct Name<T>
{
    public string Name;

    // for convenience, could be explicit instead
    static implicit operator string(Name<T> name)
    {
        return name.Name;
    }
}
Run Code Online (Sandbox Code Playgroud)

这会给我

private Dictionary<Name<Foo>, Foo> myFoos;
private Dictionary<Name<Bar>, Bar> myBars;
Run Code Online (Sandbox Code Playgroud)

然后我可以存储Name<Foo>实例而不是字符串.

这看起来有点笨拙,但这是迄今为止我提出的最好的 - 有关如何做得更好的任何建议吗?
这是误导,还是很棒?

c# generics dictionary

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

如何使用PyQt打印包含python的特殊字符的QString?


我没有设法简单地打印包含特殊字符的QString变量.
我总是得到一个UnicodeEncodeError:

'ascii'编解码器无法对字符进行编码....

这是我尝试过的代码没有成功:

var1 = "éé" #idem with u"éé"  
 var2 = QString (var1)  
 print var2  
 --->>> UnicodeEncodeError  
 print str(var2)  
 --->>> UnicodeEncoreError  
 var3 = QString.fromLocal8Bit (var1) #idem with fromLatin1 and fromUtf8  
 print var3  
 --->>> UnicodeEncodeError  

 codec = QTextCodec.codecForName ("UTF-8") #idem with ISO 8859-1  
 var4 = codec.toUnicode (var2.toUtf8().data()) #idem with toLatin1 instead of toUtf8  
 print var4  
 --->>> UnicodeEncodeError  
Run Code Online (Sandbox Code Playgroud)

我也试过用:

 QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8"))  
Run Code Online (Sandbox Code Playgroud)

我真的需要打印一个QString变量,而不是QByteArray或其他对象.

python qstring pyqt

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

NSAutoreleasePool EXC_BAD_ACCESS和关于Objective-C中的内存管理的问题

我很难理解NSAutoReleasePool的工作原理.

1)NSAutoReleasePool是单独跟踪每个分配还是依赖于变量?换句话说,这会泄漏内存还是释放?:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  
 NSArray* myObj = [NSObject alloc];  
 myObj = [NSObject alloc];  
 [pool release];
Run Code Online (Sandbox Code Playgroud)

2)为什么以下代码有效:

 NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];

 NSArray* myObj = [NSObject alloc];

 for(int i = 0; i < 100; i++) {
  [myObj release];
  myObj = [NSObject alloc];
 }

 [pool1 release];
Run Code Online (Sandbox Code Playgroud)

但以下给出了EXC_BAD_ACCESS [pool1 release]:

 NSAutoreleasePool *pool1 = [[NSAutoreleasePool alloc] init];

 NSArray* myObj = [NSObject alloc];

 NSAutoreleasePool *pool2 = [[NSAutoreleasePool alloc] init]; 

 for(int i = 0; i < 100; i++) {
  [myObj …
Run Code Online (Sandbox Code Playgroud)

iphone memory-management objective-c

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