/// <summary> /// 构造函数 /// </summary> /// <param name="id">参数序号,从0开始</param> /// <param name="name">参数名</param> /// <param name="collectionType">集合类型,是CollectionType的枚举类型:None,List,Set,Map等</param> /// <param name="parameterType">参数的基本数据类型</param> /// <param name="structName">当参数的类型为Struct时,此名称有意义</param> public DynParameter(short id, string name, CollectionType collectionType, DynType parameterType, string structName) { _id = id; _name = name; _collectionType = collectionType; _dynType = parameterType; _structName = structName; _direction = ParameterDirection.Input; }
/// <summary> /// 构造函数 /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="collectionType"></param> /// <param name="propertyType"></param> /// <param name="structName"></param> public DynProperty(short id, string name, CollectionType collectionType, DynType propertyType, string structName) { _id = id; _name = name; _collectionType = collectionType; _dynType = propertyType; _structName = structName; _isArray = false; }
public static object GetTrueType(object value, DynType dynType) { switch (dynType) { case DynType.Void: return(null); case DynType.Bool: return(Convert.ToBoolean(value)); case DynType.Byte: return(Convert.ToByte(value)); case DynType.Double: return(Convert.ToDouble(value)); case DynType.I16: return(Convert.ToInt16(value)); case DynType.I32: return(Convert.ToInt32(value)); case DynType.I64: return(Convert.ToInt64(value)); case DynType.String: return(Convert.ToString(value)); case DynType.Struct: return(value); case DynType.DateTime: return(Convert.ToDateTime(value)); case DynType.Binary: return(value); case DynType.Decimal: return(Convert.ToDecimal(value)); default: return(null); } }
/// <summary> /// Set the property value /// </summary> /// <param name="propertyName"></param> /// <param name="propertyValue"></param> public void SetPropertyValue(DynProperty property, object propertyValue) { if (propertyValue != null) { CollectionType collectionType = property.CollectionType; DynType dynType = property.DynType; string structName = property.StructName; bool isCorrectType = false; #region 类型判断 switch (collectionType) { case CollectionType.None: switch (dynType) { case DynType.Void: break; case DynType.Bool: isCorrectType = propertyValue is Boolean; break; case DynType.Byte: isCorrectType = propertyValue is Byte; break; case DynType.Double: isCorrectType = propertyValue is Double || propertyValue is Single || propertyValue is Int64 || propertyValue is Int32 || propertyValue is UInt32 || propertyValue is UInt16 || propertyValue is Int16; break; case DynType.Decimal: isCorrectType = propertyValue is Decimal || propertyValue is Double || propertyValue is Single || propertyValue is Int64 || propertyValue is Int32 || propertyValue is UInt32 || propertyValue is UInt16 || propertyValue is Int16; break; case DynType.I16: isCorrectType = propertyValue is Int16; break; case DynType.I32: isCorrectType = propertyValue is Int32 || propertyValue is UInt16 || propertyValue is Int16; break; case DynType.I64: isCorrectType = propertyValue is Int64 || propertyValue is Int32 || propertyValue is UInt32 || propertyValue is UInt16 || propertyValue is Int16; break; case DynType.String: isCorrectType = propertyValue is String; break; case DynType.DateTime: isCorrectType = propertyValue is DateTime; break; case DynType.Struct: isCorrectType = propertyValue is DynObject; break; case DynType.Binary: isCorrectType = propertyValue is byte[]; break; default: break; } break; case CollectionType.List: switch (dynType) { case DynType.Void: break; case DynType.Bool: isCorrectType = propertyValue is List <Boolean>; break; case DynType.Byte: isCorrectType = propertyValue is List <Byte>; break; case DynType.Double: isCorrectType = propertyValue is List <Double>; break; case DynType.Decimal: isCorrectType = propertyValue is List <Decimal>; break; case DynType.I16: isCorrectType = propertyValue is List <Int16>; break; case DynType.I32: isCorrectType = propertyValue is List <Int32>; break; case DynType.I64: isCorrectType = propertyValue is List <Int64>; break; case DynType.String: isCorrectType = propertyValue is List <String>; break; case DynType.DateTime: isCorrectType = propertyValue is List <String>; break; case DynType.Struct: isCorrectType = propertyValue is List <DynObject>; break; default: break; } break; case CollectionType.Set: break; case CollectionType.Map: isCorrectType = propertyValue is Dictionary <string, object>; break; default: break; } #endregion if (isCorrectType) { _propertyValues[property.Name] = propertyValue; } else { string msg = string.Format("属性{0}应该是{1}:{2}类型,而把{3}类型赋给它", property.Name, Enum.GetName(typeof(CollectionType), collectionType), Enum.GetName(typeof(DynType), dynType), propertyValue.GetType().ToString()); throw new ApplicationException(msg); } } else { SetDefaultValue(property); } }
public void SetParameterValue(string paramName, object paramValue) { if (_dynMethod.ContainsParameter(paramName)) { DynParameter dynParameter = _dynMethod.GetParameter(paramName); CollectionType collectionType = dynParameter.CollectionType; DynType dynType = dynParameter.DynType; string structName = dynParameter.StructName; if (paramValue != null) { bool isCorrectType = false; #region 类型判断 switch (collectionType) { case CollectionType.None: switch (dynType) { case DynType.Void: break; case DynType.Bool: isCorrectType = paramValue is Boolean; break; case DynType.Byte: isCorrectType = paramValue is Byte; break; case DynType.Double: isCorrectType = paramValue is Double || paramValue is Single || paramValue is Int64 || paramValue is Int32 || paramValue is UInt32 || paramValue is UInt16 || paramValue is Int16; break; case DynType.Decimal: isCorrectType = paramValue is Decimal || paramValue is Double || paramValue is Single || paramValue is Int64 || paramValue is Int32 || paramValue is UInt32 || paramValue is UInt16 || paramValue is Int16; break; case DynType.I16: isCorrectType = paramValue is Int16; break; case DynType.I32: isCorrectType = paramValue is Int32 || paramValue is UInt16 || paramValue is Int16; break; case DynType.I64: isCorrectType = paramValue is Int64 || paramValue is Int32 || paramValue is UInt32 || paramValue is UInt16 || paramValue is Int16; break; case DynType.String: isCorrectType = paramValue is String; break; case DynType.DateTime: isCorrectType = paramValue is DateTime; break; case DynType.Struct: isCorrectType = paramValue is DynObject; break; case DynType.Binary: isCorrectType = paramValue is byte[]; break; default: break; } break; case CollectionType.List: switch (dynType) { case DynType.Void: break; case DynType.Bool: isCorrectType = paramValue is List <Boolean>; break; case DynType.Byte: isCorrectType = paramValue is List <Byte>; break; case DynType.Double: isCorrectType = paramValue is List <Double>; break; case DynType.Decimal: isCorrectType = paramValue is List <Decimal>; break; case DynType.I16: isCorrectType = paramValue is List <Int16>; break; case DynType.I32: isCorrectType = paramValue is List <Int32>; break; case DynType.I64: isCorrectType = paramValue is List <Int64>; break; case DynType.String: isCorrectType = paramValue is List <String>; break; case DynType.DateTime: isCorrectType = paramValue is List <String>; break; case DynType.Struct: isCorrectType = paramValue is List <DynObject>; break; default: break; } break; case CollectionType.Set: break; case CollectionType.Map: isCorrectType = paramValue is Dictionary <string, object>; break; default: break; } #endregion if (isCorrectType) { _paramsValues[paramName] = paramValue; } else { string msg = string.Format("参数{0}应该是{1}:{2}类型,而把{3}类型赋给它", paramName, Enum.GetName(typeof(CollectionType), collectionType), Enum.GetName(typeof(DynType), dynType), paramValue.GetType().ToString()); throw new ApplicationException(msg); } } else { //赋默认值 //SetDefaultValue(dynParameter); } } else { throw new ApplicationException(string.Format("方法{0}中,不包含参数{1}", _dynMethod.Name, paramName)); } }