public Executor(DataTable dt) { this.dt = dt; if (typeof(T).IsValueType || typeof(T) == typeof(string)) { this.Entities = new List <T>(); var colIndex = 0; if (dt.Columns[0].ColumnName.ToLower() == "rownumber")//groupby...skip...take { colIndex = 1; } foreach (DataRow dr in dt.Rows) { this.Entities.Add(DataConvert.Convert <T>(dr[colIndex])); } } else if (typeof(T).Name == "IGrouping`2") {//from obj in Lovewall.Entities group obj by obj.Content into g select g; this.Entities = new List <T>(); foreach (DataRow dr in dt.Rows) { var grouping = Activator.CreateInstance(typeof(Grouping <,>).MakeGenericType(typeof(T).GetGenericArguments()), dr); this.Entities.Add((T)grouping); } } else { this.Entities = this.dt.ToEntities <T>(); } }
// Queryable's "single value" standard query operators call this method. // It is also called from QueryableTerraServerData.GetEnumerator(). public TResult Execute <TResult>(Expression expression) { //bool IsEnumerable = (typeof(TResult).Name == "IEnumerable`1"); var obj = DataQueryContext.Execute <TResult>(expression); var resultType = typeof(TResult); if (resultType.IsValueType || resultType == typeof(string)) { return(DataConvert.Convert <TResult>(obj));//例如求平均数,TResult可能是double,而实际得到的结果为int,int不能直接强制转换为double. } return((TResult)obj); }
public object Invoke(string MethodName, Dictionary <string, object> Args) { System.Reflection.MethodInfo method = this.ProxyType.GetMethod(MethodName); System.Reflection.ParameterInfo[] parameters = method.GetParameters(); object[] convertedArgs = null; if (parameters != null && parameters.Length != 0) { convertedArgs = new object[parameters.Length]; for (int count = 0; count < parameters.Length; count++) { string name = parameters[count].Name; if (!Args.ContainsKey(name) || Args[name] == null) { convertedArgs[count] = null; } else if (Args[name].GetType() == parameters[count].ParameterType) { convertedArgs[count] = Args[name]; } else { try { convertedArgs[count] = DataConvert.Convert(Args[name], parameters[count].ParameterType, true); } catch (Exception ex) { throw new Exception( string.Format( "Call web service exception. Parameter type dismatched. " + "Url={0}, ClassName={1}, MethodName={2}. " + "The type of parameter \"{3}\" is {4} and value is {5}.", this.Url, this.ClassName, MethodName, name, parameters[count].ParameterType, Args[name]), ex); } } } } return(method.Invoke(this.ProxyObject, convertedArgs)); }
void test() { //设置转换源数据url,67数据为区简单要素类 string SrcUrl = @"D:\武汉地质调查中心---矿产资源潜力评价项目\广西壮族自治区\铝土矿种潜力评价图库\DZ_成矿地质背景\CJGZ_预测工作区沉积建造构造图\JWMAP_经纬坐标图件\MDZCJGZDFSPX_扶绥-凭祥预测工作区沉积建造构造图\LDLYAAB002.WT"; //目的数据的名称 string DesSFname = "convertsfcls"; SFeatureCls decsfc = null; Server Svr = null; DataBase GDB = null; Svr = new Server(); Svr.Connect("MapGISLocal", "", ""); GDB = Svr.OpenGDB("test"); decsfc = new SFeatureCls(GDB); //创建区简单要素类目的数据 decsfc.Create(DesSFname, GeomType.Pnt, 0, 0, null); //设置转换类型 DataConvert dataConvert = new DataConvert(); dataConvert.SetOption(ConvertOptionType.OPT_6TO7, 0); //打开源数据和目的数据 if (dataConvert.OpenSource(SrcUrl) > 0 && dataConvert.OpenDestination(decsfc) > 0) { //转换数据 bool rtn = dataConvert.Convert() > 0; if (rtn) { MessageBox.Show("数据迁移成功"); } else { MessageBox.Show("数据转换失败"); } dataConvert.Close(); decsfc.Close(); } }