c#中递归泛型类型的问题

Problems with recursive generic type in c#(c#中递归泛型类型的问题)

本文介绍了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.

该类型实际上有一个递归泛型定义,所以我的问题是:为什么它适用于单声道?[代码运行并产生预期结果]

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

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

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>();
    }
}

这是它在单声道上工作的证据: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.

(递归 lambdas 是另一个适用的例子不应该的单声道)

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

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

本文标题为:c#中递归泛型类型的问题

基础教程推荐