public static class TypeUtils { /// <summary> /// Object 转为 强类型 /// </summary> public static T ConvertType<T>(object value) { if (value == null) return default(T); var typeConverter = TypeDescriptor.GetConverter(typeof(T)); if (typeConve
import java.math.BigDecimal; import java.math.BigInteger; public class MathUtils { public static BigDecimal getBigDecimal( Object value ) { BigDecimal ret = null; if( value != null ) { if( value instanceof BigDecimal ) { ret = (BigDecimal) value; } e
代码如下 # 将class转dict,以_开头的属性不要 def props(obj): pr = {} for name in dir(obj): value = getattr(obj, name) if not name.startswith('__') and not callable(value) and not name.startswith('_'): pr[name] = value return pr # 将class转dict,以_开头的也要 def props_with_(
需求一,将数据对象转为dict,但是不包括relation, import BaseClass #所有模型的基础类 def getDictFromObj_nr(obj): return_dict={} if isinstance(obj,BaseClass): for key in obj.__dict__ : if key.startswith('_'):continue return_dict[key]=getattr(obj,key) return return_dict 需求二,将数据对