C#中的递归泛型类型的问题 [英] Problems with recursive generic type in c#

查看:58
本文介绍了C#中的递归泛型类型的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C#代码,可以在mono和Microsoft的.net编译器下很好地编译,但是只能在mono上运行.错误消息是(我添加了换行符)

I've got some C# code that compiles fine under both mono and the Microsoft's .net compilers, but only runs on mono. The error message is (newlines added by me)

Unhandled Exception: System.TypeLoadException:
Could not load type 'Hasse.Groups.Heavy.Product.PowerGroup`1'
from assembly 'Hasse, Version=1.0.x.y, Culture=neutral, PublicKeyToken=null'
because it has recursive generic definition.

该类型实际上有一个递归的泛型定义,所以我的问题是:为什么它与mono一起工作?[代码运行并产生预期的结果]

The type actually has a recursive generic definition, so my question is: why does it work with mono? [The code runs and produces the expected result]

完整的源代码在这里: https://github.com/miniBill/Hasse

Full source code is here: https://github.com/miniBill/Hasse

仍在崩溃的精简代码在这里:

Reduced code which still crashes is here:

public class Group<T> : IWrappableGroup<WrapperGroup<T>> {}

public class WrapperElement<T> {}

public interface IWrappableGroup<U> {}

public class WrapperGroup<T> : Group<WrapperElement<T>> {}

class MainClass {
    public static void Main(string[] args){
        var ng = new Group<object>();
    }
}

此处证明它适用于mono: http://ideone.com/ZvA3I

Here is proof that it works on mono: http://ideone.com/ZvA3I

推荐答案

这是已知问题.它可能被报告为编译器错误.

This is a known issue. It could be reported as a compiler error.

http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf (第129页)

至于在Mono中工作,就规范而言,在多个地方中断"了Mono工作.

As for working in Mono, there are several places where Mono working is "broken" as far as the specs is concerned.

(递归lambda 是适用于某些东西的另一个例子不应该的单声道)

(Recursive lambdas are another exmaple of something that works in Mono that shouldn't)

这篇关于C#中的递归泛型类型的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆