• c# 返回一个对象的写法


    创建对象ViewModel:

     1 using System;
     2 
     3 namespace DevOps.Api.ViewModel
     4 {
     5     public class AppDocList
     6     {
     7         /// <summary>
     8         /// 应用ID
     9         /// </summary>
    10         public string app_id { get; set; }
    11         /// <summary>
    12         /// 文档类别(来源字典)
    13         /// </summary>
    14         public string doc_type { get; set; }
    15         /// <summary>
    16         /// 文档标题
    17         /// </summary>
    18         public string title { get; set; }
    19         /// <summary>
    20         /// 关键字
    21         /// </summary>
    22         public string keyword { get; set; }
    23         /// <summary>
    24         /// 文档内容
    25         /// </summary>
    26         public string doc_content { get; set; }
    27         /// <summary>
    28         /// 状态(1-草稿;2-已发布;3-撤回)
    29         /// </summary>
    30         public int status { get; set; }
    31         /// <summary>
    32         /// 发布人
    33         /// </summary>
    34         public string publish_by { get; set; }
    35         /// <summary>
    36         /// 发布时间
    37         /// </summary>
    38         public DateTime? publish_time { get; set; }
    39         /// <summary>
    40         /// 发布时间
    41         /// </summary>
    42         public string statusname { get; set; }
    43     }
    44 }

    api核心代码:

    var applist = new List<AppDocList>();
                foreach (var item in ids)
                {
                    applist.Add(new AppDocList
                    {
                        app_id = item.app_id,
                        doc_type = item.doc_type,
                        title = item.title,
                        keyword = item.keyword,
                        doc_content = item.doc_content,
                        statusname = (int)DocStatus.Draft == item.status ? GetEnumDesc(DocStatus.Draft) : (
                        (int)DocStatus.Published == item.status ? GetEnumDesc(DocStatus.Published) : (
                        (int)DocStatus.Withdraw == item.status ? GetEnumDesc(DocStatus.Withdraw) : "")
                        ),
                        publish_by = item.publish_by,
                        publish_time = item.publish_time
                    });
                }
                result.Data = applist;
  • 相关阅读:
    单例模式
    说说抽象类接口
    闲说多态
    理解C#中的继承
    可变个数的形参的方法
    java 关键字
    数组的常见异常
    内存的基本结构 图片
    Java中的名称命名规范:
    死锁的例子 代码练习
  • 原文地址:https://www.cnblogs.com/chenpanpan/p/14506352.html
Copyright © 2020-2023  润新知