【发布时间】:2019-04-08 23:14:41
【问题描述】:
我有以下 Graphql 类型类,包括 POCO 类:Order.cs。
这里我要设置每个字段的默认值。例如对于Name,我想返回“No Name”,以防它没有返回值。如果是Created,我想默认返回今天的日期。
public class OrderType : ObjectGraphType<Order>
{
public OrderType(ICustomerService customers)
{
Field(o => o.Id);
Field(o => o.Name);
Field(o => o.Description);
Field(o => o.Created);
}
}
public class Order
{
public Order(string name, string description, DateTime created, string Id)
{
Name = name;
Description = description;
Created = created;
this.Id = Id;
}
public string Name { get; set; }
public string Description { get; set; }
public DateTime Created { get; private set; }
public string Id { get; private set; }
}
谁能帮我解决这个问题?
【问题讨论】:
标签: c# .net properties default-value