zoukankan      html  css  js  c++  java
  • 泛型约束通过反射获取相关值、属性名、属性类型

    public class SpliceSqlWhere     {

              public static string GetSqlWhere(T t)

          {

                   PropertyInfo[] pInfo = t.GetType().GetProperties();                 

         List list = new List();                 

         for (int i = 0; i < pInfo.Length; i++)                 

        {                     

          ObjectParameter para = new ObjectParameter();                     

          para.Type = pInfo[i].PropertyType.Name;                     

          para.Name = pInfo[i].Name;                     

          para.Value = pInfo[i].GetValue(t);                     

          list.Add(para);                 

        }

          }

    }

     class ObjectParameter     {        

      public string Type { get; set; }       

        public string Name { get; set; }        

      public object Value { get; set; }    

    }

  • 相关阅读:
    LeetCode15 3Sum
    LeetCode10 Regular Expression Matching
    LeetCode20 Valid Parentheses
    LeetCode21 Merge Two Sorted Lists
    LeetCode13 Roman to Integer
    LeetCode12 Integer to Roman
    LeetCode11 Container With Most Water
    LeetCode19 Remove Nth Node From End of List
    LeetCode14 Longest Common Prefix
    LeetCode9 Palindrome Number
  • 原文地址:https://www.cnblogs.com/hongfu/p/4323739.html
Copyright © 2011-2022 走看看