ServiceStack /types/csharp 在 v5.7 中生成无效的属性签名
ServiceStack /types/csharp generating invalid attribute signatures in v5.7
在我们升级到 ServiceStack v5.7 时,/types/csharp
处的 NativeTypesService 生成的文件现在生成无效代码。我们正在使用 ASP.Net(非核心),.Net Framework 4.7.2。
具体来说,References
和StringLength
属性是使用命名参数生成的,导致在包含在客户端项目(使用相同版本的ServiceStack)中时出现错误:
error CS1729: 'StringLengthAttribute' does not contain a constructor that takes 0 arguments
error CS7036: There is no argument given that corresponds to the required formal parameter 'type' of 'ReferencesAttribute.ReferencesAttribute(Type)'
我已经检查了 CSharpGenerator
的相关位的 blame history,但多年来没有任何变化。我很茫然。
我们如何使用 /types/csharp
NativeTypesService 端点生成有效代码?
我在下面创建了一个最小的示例项目来说明这一点。所有 ServiceStack 库都是 v5.7(文本、接口等)。当我们仅将核心 ServiceStack
降级到 v5.6 时,会生成预期的输出。
v5.6 签名
namespace TestTypes
{
[Route("/Child")]
public partial class Child
{
public virtual int Id { get; set; }
[References(typeof(TestTypes.Parent))]
public virtual int ParentId { get; set; }
}
[Route("/Parent")]
public partial class Parent
{
public virtual int Id { get; set; }
[StringLength(100)]
public virtual string Name { get; set; }
}
}
v5.7 签名
namespace TestTypes
{
[Route("/Child")]
public partial class Child
{
public virtual int Id { get; set; }
[References(Type=typeof(TestTypes.Parent))]
public virtual int ParentId { get; set; }
}
[Route("/Parent")]
public partial class Parent
{
public virtual int Id { get; set; }
[StringLength(MaximumLength=100)]
public virtual string Name { get; set; }
}
}
示例项目
public class AppHost : AppHostBase
{
public AppHost() : base("Test", typeof(MyService).Assembly) { }
public override void Configure(Container container) { }
}
public class MyService : Service
{
public object Get(Parent request) { return null; }
public object Get(Child request) { return null; }
}
[Route("/Parent")]
public class Parent
{
[PrimaryKey]
public int Id { get; set; }
[StringLength(100)]
public string Name { get; set; }
}
[Route("/Child")]
public class Child
{
[PrimaryKey]
public int Id { get; set; }
[References(typeof(Parent))]
public int ParentId { get; set; }
}
这个问题现在应该已经用最新的 v5.8 Release of ServiceStack 解决了。
在我们升级到 ServiceStack v5.7 时,/types/csharp
处的 NativeTypesService 生成的文件现在生成无效代码。我们正在使用 ASP.Net(非核心),.Net Framework 4.7.2。
具体来说,References
和StringLength
属性是使用命名参数生成的,导致在包含在客户端项目(使用相同版本的ServiceStack)中时出现错误:
error CS1729: 'StringLengthAttribute' does not contain a constructor that takes 0 arguments
error CS7036: There is no argument given that corresponds to the required formal parameter 'type' of 'ReferencesAttribute.ReferencesAttribute(Type)'
我已经检查了 CSharpGenerator
的相关位的 blame history,但多年来没有任何变化。我很茫然。
我们如何使用 /types/csharp
NativeTypesService 端点生成有效代码?
我在下面创建了一个最小的示例项目来说明这一点。所有 ServiceStack 库都是 v5.7(文本、接口等)。当我们仅将核心 ServiceStack
降级到 v5.6 时,会生成预期的输出。
v5.6 签名
namespace TestTypes
{
[Route("/Child")]
public partial class Child
{
public virtual int Id { get; set; }
[References(typeof(TestTypes.Parent))]
public virtual int ParentId { get; set; }
}
[Route("/Parent")]
public partial class Parent
{
public virtual int Id { get; set; }
[StringLength(100)]
public virtual string Name { get; set; }
}
}
v5.7 签名
namespace TestTypes
{
[Route("/Child")]
public partial class Child
{
public virtual int Id { get; set; }
[References(Type=typeof(TestTypes.Parent))]
public virtual int ParentId { get; set; }
}
[Route("/Parent")]
public partial class Parent
{
public virtual int Id { get; set; }
[StringLength(MaximumLength=100)]
public virtual string Name { get; set; }
}
}
示例项目
public class AppHost : AppHostBase
{
public AppHost() : base("Test", typeof(MyService).Assembly) { }
public override void Configure(Container container) { }
}
public class MyService : Service
{
public object Get(Parent request) { return null; }
public object Get(Child request) { return null; }
}
[Route("/Parent")]
public class Parent
{
[PrimaryKey]
public int Id { get; set; }
[StringLength(100)]
public string Name { get; set; }
}
[Route("/Child")]
public class Child
{
[PrimaryKey]
public int Id { get; set; }
[References(typeof(Parent))]
public int ParentId { get; set; }
}
这个问题现在应该已经用最新的 v5.8 Release of ServiceStack 解决了。