zoukankan      html  css  js  c++  java
  • c#泛型&使用示例

    附上参考学习代码

    using DbOperate.Modify;
    using Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.Http;
    using Utils.Log4net;
    using Utils.JsonXmlHelper;
    using static Model.GetUsrUserModel.OutGetUsrUserModel;
    
    
    namespace AssistServer.Controllers
    {
        public class GetUsrUserController : ApiController
        {
            /// <summary>
            /// 获取用户信息
            /// </summary>
            /// <param name="{"ActionCode":"1001","Table":[{"COMPNO":"*","USR":"0001"}]}"></param>
            /// <returns></returns>
            [TransLogFilter]
            public Object Post([FromBody]string sJson)
            {
                LogHandle.WriteLog(typeof(GetUsrUserController),1,sJson);
                InValueModel<List<GetUsrUserModel.InGetUsrUserModel.Table>> InValueModel = SerializationHelper.Deserialize<InValueModel<List<GetUsrUserModel.InGetUsrUserModel.Table>>>(sJson);
                String ActionCode = InValueModel.ActionCode.ToString();
                OutValueModel<List<Table>> OutValueModel = new OutValueModel<List<Table>>();
                List<Table> Table = new List<Table>();
                try
                {
                    String COMPNO = InValueModel.Table[0].COMPNO.ToString();
                    String USR = InValueModel.Table[0].USR.ToString();
                    String sSql = "Select CompNo,Usr,Name,Pwd From tUsrUser_App " +
                                  "Where CompNo='" + COMPNO + "' and Usr = '" + USR + "'";
                    DataTable DtHead = DbModify.GetDataTable(sSql);
                    Table = DbModify.GetDataList<Table>(sSql);
                    if (Table.Count != 0)
                    {
                        OutValueModel.RtnCode = "1";
                        OutValueModel.Msg = "获取用户信息成功";
                    }
                    else
                    {
                        OutValueModel.RtnCode = "0";
                        OutValueModel.Msg = "无此用户信息";
                    }
                    OutValueModel.Table = Table;
                }
                catch (Exception ex)
                {
                    OutValueModel.RtnCode = "-1";
                    OutValueModel.Msg = "获取用户信息失败"+ex.Message;
                }
                LogHandle.WriteLog(typeof(GetUsrUserController), 1, SerializationHelper.Serialize(OutValueModel));
                return OutValueModel;
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Model
    {
        public class InValueModel<T>
        {
    
            public String ActionCode { get; set; }
    
    
            public T Table { get; set; }
    
    
        }
    }
    using System;
    
    
    
    namespace Model
    {
        public class GetUsrUserModel
        {
            //用户信息入参
            public class InGetUsrUserModel
            {
                public class Table
                {
                    public String COMPNO { get; set; }
    
                    public String USR { get; set; }
                }
            }
            //用户信息返回结果
            public class OutGetUsrUserModel
            {
                public class Table
                {
                    public String COMPNO { get; set; }
    
                    public String USR { get; set; }
    
                    public String NAME { get; set; }
    
                    public String PWD { get; set; }
                }
            }
        }
    }
  • 相关阅读:
    hihocoder 1049 后序遍历
    hihocoder 1310 岛屿
    Leetcode 63. Unique Paths II
    Leetcode 62. Unique Paths
    Leetcode 70. Climbing Stairs
    poj 3544 Journey with Pigs
    Leetcode 338. Counting Bits
    Leetcode 136. Single Number
    Leetcode 342. Power of Four
    Leetcode 299. Bulls and Cows
  • 原文地址:https://www.cnblogs.com/guoqiang1/p/8301792.html
Copyright © 2011-2022 走看看