加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 扩展方法不起作用(快速图表序列化)

发布时间:2020-12-15 04:12:18 所属栏目:百科 来源:网络整理
导读:Error: The type arguments for method GraphMLExtensions.SerializeToGraphMLTVertex,TEdge,TGraph(TGraph, XmlWriter) cannot be inferred from the usage. using System.Xml;using QuickGraph;using QuickGraph.Serialization; var g = new AdjacencyGrap

Error: The type arguments for method
GraphMLExtensions.SerializeToGraphML<TVertex,TEdge,TGraph>(TGraph,
XmlWriter)
cannot be inferred from the usage.

using System.Xml;
using QuickGraph;
using QuickGraph.Serialization;    

var g = new AdjacencyGraph<string,Edge<string>>();

.... add some vertices and edges ....

using (var xwriter = XmlWriter.Create("somefile.xml"))
  g.SerializeToGraphML(xwriter);

代码是从QuickGraph的文档中复制的.但是,当我明确地写它时,它有效:

using (var xwriter = XmlWriter.Create("somefile.xml"))
   GraphMLExtensions.SerializeToGraphML<string,Edge<string>,AdjacencyGraph<string,Edge<string>>>(g,xwriter);

编辑:我看到了一些相关的问题,但它们对我来说太先进了.我只是担心使用它.我做错了什么还是文件?

解决方法

Am I doing something wrong or it’s the documentation?

问题不在于扩展方法.问题在于,当您使用完整的静态方法路径时,您明确地提供泛型类型参数,而使用扩展方法则根本不提供任何参数.

实际错误与编译器无法为您推断所有泛型类型参数这一事实有关,并且需要通过显式传递它们来获得帮助.

这将有效:

using (var xwriter = XmlWriter.Create("somefile.xml"))
{
    g.SerializeToGraphML<string,Edge<string>>>(xwriter);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读