Пример #1
0
        private static object StrngToObject(string tablename, string keyvalue, string sqlconnestring)
        {
            var db       = sqlconnestring.GetSqlSugarContext();
            var jobj     = JObject.Parse(keyvalue);
            var colsinfo = db.DbMaintenance.GetColumnInfosByTableName(tablename, false);
            var newtype  = TypeCreator.NewClassBulder(tablename);

            foreach (var col in colsinfo)
            {
                col.PropertyType = db.DBTypeStringToCShapType(col);
                newtype.AddProperityName(col.DbColumnName, col.PropertyType, col.IsNullable, null);
            }
            var dbobjecttype = CSScript.Evaluator.CompileCode(newtype.ToString()).GetType("css_root+" + tablename);
            var setting      = new JsonSerializerSettings();

            setting.NullValueHandling    = NullValueHandling.Ignore;
            setting.DefaultValueHandling = DefaultValueHandling.Ignore;
            var dbobject = JsonConvert.DeserializeObject(keyvalue, dbobjecttype, setting);

            return(dbobject);
        }