Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 带有POCO DTO的TypeLite表对象_.net_Typelite - Fatal编程技术网

.net 带有POCO DTO的TypeLite表对象

.net 带有POCO DTO的TypeLite表对象,.net,typelite,.net,Typelite,我的DTO类具有IValidatableObject,当我尝试将它们与TypeLite一起使用时,会出现以下错误: 'System.ComponentModel.DataAnnotations.IValidatableObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.DataAnnotations, Versio

我的DTO类具有
IValidatableObject
,当我尝试将它们与TypeLite一起使用时,会出现以下错误:

'System.ComponentModel.DataAnnotations.IValidatableObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
我如何解决这个问题

这是我的tt文件TypeLite.Net4.tt:

<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="$(TargetDir)TypeLite.dll" #>
<#@ assembly name="$(TargetDir)TypeLite.Net4.dll" #>
<#@ assembly name="$(TargetDir)$(TargetFileName)" #>
<#@ import namespace="TypeLite" #> 
<#@ import namespace="TypeLite.Net4" #> 
<#@output extension=".d.ts"#>
<#@include file="Manager.ttinclude"#>
<# var manager = Manager.Create(Host, GenerationEnvironment); #>
<# 
var ts = TypeScript.Definitions()
        .WithReference("Enums.ts")
        .WithMemberFormatter((identifier) => Char.ToLower(identifier.Name[0]) + identifier.Name.Substring(1))
        .For<Models.ProjectDTO>()
        ;
#>
<#= ts.Generate(TsGeneratorOutput.Properties) #>
<# manager.StartNewFile("Enums.ts"); #>
<#= ts.Generate(TsGeneratorOutput.Enums) #>
<# manager.EndBlock(); #>
<# manager.Process(true); #>

Char.ToLower(identifier.Name[0])+identifier.Name.Substring(1))
.对于()
;
#>
以下是其中一个模型:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Models
{
    public class ProjectDTO : IValidatableObject
    {
        public Guid ProjectId { get; set; }

        [Required]
        public Guid ClientId { get; set; }
        public ClientDTO Client { get; set; }

        [Required, MaxLength(10)]
        public string Code { get; set; }

        //snipped for brevity

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (EndDate.HasValue && EndDate < StartDate)
                yield return new ValidationResult("Project end date cannot be before the start date", new[] { "EndDate" });
        }
    }

}
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
名称空间模型
{
公共类ProjectDTO:IValidatableObject
{
公共Guid项目ID{get;set;}
[必需]
公共Guid客户端ID{get;set;}
公用客户端到客户端{get;set;}
[必需,最大长度(10)]
公共字符串代码{get;set;}
//剪短
公共IEnumerable验证(ValidationContext ValidationContext)
{
if(EndDate.HasValue&&EndDate
只需在TypeLite.Net4.tt文件顶部添加这一行即可:

<#@ assembly name="System.ComponentModel.DataAnnotations.dll" #>

即:


...

此错误消息显示在何处?你能把你的DTO类和
typelite.tt
文件发布吗?如果我将
IValidatableObject
接口添加到演示项目中的一个类中,那么一切都正常……嗨@lukaskart。谢谢你的帮助!保存tt文件时,错误将出现在Visual Studio中的错误列表中。我将把其余的补充到这个问题上。
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="$(TargetDir)TypeLite.dll" #>
<#@ assembly name="$(TargetDir)TypeLite.Net4.dll" #>   
<#@ assembly name="System.ComponentModel.DataAnnotations.dll" #>
...