我试图用Automapper映射一个NetTopologySuite.Geometries.MultiPoint,但我一直收到错误消息System.ArgumentException: NetTopologySuite.Geometries.MultiPoint needs to have a constructor with 0 args or only optional args。
var config = new MapperConfiguration(cfg => {});
var mapper = config.CreateMapper();
MultiPoint mp1 = null;
MultiPoint mp2 = mapper.Map<MultiPoint>(mp1); // throws实际上,这个类型没有带0个参数的构造函数。我尝试指定如何实例化该类型:
new MapperConfiguration(cfg => {
cfg.CreateMap<MultiPoint, MultiPoint>()
.ConstructUsing(mp => new MultiPoint((Point[])mp.Geometries));
});同样的错误。为了用更简单的代码重现,我创建了一个没有0 args构造函数的类。
var config = new MapperConfiguration(cfg => { });
var mapper = config.CreateMapper();
TestCollection tc1 = null;
TestCollection tc2 = mapper.Map<TestCollection>(tc1); // throws
class Test
{
}
class TestCollection : IEnumerable<Test>
{
public TestCollection(Test[] tests) => Tests = tests;
public Test[] Tests { get; set; }
public IEnumerator<Test> GetEnumerator() => new TestCollectionEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
class TestCollectionEnumerator : IEnumerator<Test>
{
object IEnumerator.Current => Current;
public Test Current { get; }
public bool MoveNext() => false;
public void Reset() { }
public void Dispose() { }
}是bug,还是我漏掉了什么?
发布于 2021-09-03 08:36:03
我想是因为你的MultiPoint是空的。使用Nettopologysuite的多点(内部指针不能为空)。
MultiPoint mp1 = null;至
MultiPoint mp1 = NetTopologySuite.Geometries.MultiPoint.Empty;https://stackoverflow.com/questions/66538014
复制相似问题