gpt4 book ai didi

c# - 如何检查 T4 模板文件中实体属性的数据类型

转载 作者:太空狗 更新时间:2023-10-29 17:48:43 26 4
gpt4 key购买 nike

我正在 EF 4.0 中自定义我的 .tt 文件。现在,作为 f 部分自定义,如果属性类型为 Nullable<System.DateTime>,我需要在 POCO 类生成中向属性添加一些代码。或 System.DateTime .我无法找到用于比较的正确语法。

我在 .tt 文件中有以下代码。

foreach (EdmProperty edmProperty in entity.Properties.Where(p => p.TypeUsage.EdmType is PrimitiveType && p.DeclaringType == entity))
{
bool isDefaultValueDefinedInModel = (edmProperty.DefaultValue != null);
//Here I need to check whether my edmProperty is Nullable<System.DateTime> or System.DateTime, so that I can insert custom code.
}

请帮忙。

最佳答案

  if (((PrimitiveType)edmProperty.TypeUsage.EdmType).
PrimitiveTypeKind == PrimitiveTypeKind.DateTime && edmProperty.Nullable)

关于c# - 如何检查 T4 模板文件中实体属性的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4966358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com