sqlsugar 基於SugarParameter數組傳參頻繁 封裝一個方法


/// <summary>
        /// 返回基於該對象的SugarParameters的數組
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public static SugarParameter[] GetParameter<T>(T Info) where T : class
        {
            Type type = typeof(T);
            object obj = Activator.CreateInstance(type);
            // 獲取所有屬性。
            PropertyInfo[] properties = type.GetProperties();
            SugarParameter[] arParms = new SugarParameter[properties.Length];
            for (int i = 0; i < properties.Length; i++)
            {
                arParms[i] = new SugarParameter($"@{properties[i].Name}", properties[i].GetValue(Info));
            }
            return arParms;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM