Silverlight中如何自己写方法将DataTable转换为PagedCollectionView数据(动态创建类)
将DataTable转换为PagedCollectionView数据,我们可以借用DataTable的GetBindableData()方法,如下:
- DataTable dt=new DataTable();
- PagedCollectionView m_pagedCollectionView = new PagedCollectionView(dt.GetBindableData(new Connector()));
- this.daDatas.ItemsSource = m_pagedCollectionView;
问题:如果直接调用GetBindableData方法的话,我们得到的所有PagedCollectionView数据将都是string类型的,为了得到数据类型的数据,我们可以自己写转换方法
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Reflection;
- using System.Reflection.Emit;
- using System.Threading;
- using SuperMap.Web.ISDotNET6;
- using WaterWebGIS.MainFrame.BL;
- using SL40PropertyGrid;
- using System.ComponentModel;
- using Silverlight;
- using WaterWebGIS.QueryStatServiceProxy;
- using DataColumn = Silverlight.DataColumn;
- using DataRow = Silverlight.DataRow;
- using DataTable = Silverlight.DataTable;
- using FieldInfo = WaterWebGIS.QueryStatServiceProxy.FieldInfo;
- namespace WaterWebGIS.Business.DataModel
- {
- public class TypeFactory
- {
- private static List<CategoryPriorityInfo> s_categoryPriorityInfo;
- private static Dictionary<string, Type> s_dicTypes;
- private static AssemblyBuilder s_asmBuilder;
- private static ModuleBuilder s_modBuilder;
- /// <summary>
- /// 获取分类优先级信息
- /// </summary>
- public static void GetCategoryPriorityInfo()
- {
- QueryStatServiceSoapClient client = (QueryStatServiceSoapClient)WaterWebGIS.Business.Utility.CreateWebServiceObject(typeof(QueryStatServiceSoapClient), "/WS/QueryService/QueryStatService.asmx");
- client.GetCategoryPriorityAsync();
- client.GetCategoryPriorityCompleted += new EventHandler<GetCategoryPriorityCompletedEventArgs>(client_GetCategoryPriorityCompleted);
- }
- static void client_GetCategoryPriorityCompleted(object sender, GetCategoryPriorityCompletedEventArgs e)
- {
- if (e.Error == null)
- {
- s_categoryPriorityInfo = new List<CategoryPriorityInfo>();
- foreach (CategoryPriorityInfo info in e.Result)
- {
- s_categoryPriorityInfo.Add(info);
- }
- }
- }
- /// <summary>
- /// 将数据库中的基础数据类型转换为.Net框架中的数据类型
- /// </summary>
- /// <param name="dbType">将数据库中保存的类型信息转换成.net中相应的类型</param>
- public static Type ToDotNetTypeFromDBType(string dbType)
- {
- if (dbType.ToLower() == "varchar" || dbType.ToLower() == "datetime")
- {
- return typeof(System.String);
- }
- else if (dbType.ToLower() == "int")
- {
- return typeof(System.Int32);
- }
- else if (dbType.ToLower() == "float")
- {
- return typeof(System.Double);
- }
- return typeof(DBNull);
- }
- /// <summary>
- /// 生成应用程序集和模块
- /// </summary>
- private static void GenerateAssemboyAndModule()
- {
- if (s_asmBuilder == null)
- {
- AssemblyName assemblyName = new AssemblyName();
- assemblyName.Name = "DynamicORMapper";
- AppDomain thisDomain = Thread.GetDomain();
- s_asmBuilder = thisDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
- s_modBuilder = s_asmBuilder.DefineDynamicModule(assemblyName.Name);
- }
- }
- /// <summary>
- /// 创建类型
- /// </summary>
- /// <param name="modBuilder">模块生成器</param>
- /// <param name="layer">图层信息</param>
- /// <returns>类型信息</returns>
- private static Type CreateType(ModuleBuilder modBuilder, WaterWebGIS.QueryStatServiceProxy.GISLayer layer)
- {
- TypeBuilder typeBuilder = modBuilder.DefineType(layer.LayerNameEN, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout);
- CreateConstructor(typeBuilder);
- CreateProperties(typeBuilder, layer.FieldENlist);
- return typeBuilder.CreateType();
- }
- /// <summary>
- /// 创建类型
- /// </summary>
- /// <param name="modBuilder">模块生成器</param>
- /// <param name="table">DataTable信息</param>
- /// <returns>类型信息</returns>
- private static Type CreateType(ModuleBuilder modBuilder, DataTable table)
- {
- string tableName = "Table" + Environment.TickCount;
- TypeBuilder typeBuilder = modBuilder.DefineType(tableName, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout);
- CreateConstructor(typeBuilder);
- CreateProperties(typeBuilder, table.Columns);
- return typeBuilder.CreateType();
- }
- /// <summary>
- /// 创建类构造函数
- /// </summary>
- /// <param name="typeBuilder">类型生成器</param>
- private static void CreateConstructor(TypeBuilder typeBuilder)
- {
- ConstructorBuilder construtor = typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[]);
- ConstructorInfo conObj = typeof(object).GetConstructor(new Type[]);
- ILGenerator il = construtor.GetILGenerator();
- il.Emit(OpCodes.Ldarg_0);
- il.Emit(OpCodes.Call, conObj);
- il.Emit(OpCodes.Ret);
- }
- /// <summary>
- /// 创建类属性信息
- /// </summary>
- /// <param name="typeBuilder">类型生成器</param>
- /// <param name="fieldInfoCollection">图层字段集合</param>
- private static void CreateProperties(TypeBuilder typeBuilder, ObservableCollection<WaterWebGIS.QueryStatServiceProxy.FieldInfo> fieldInfoCollection)
- {
- foreach (WaterWebGIS.QueryStatServiceProxy.FieldInfo fi in fieldInfoCollection)
- {
- if (fi.IsVisible == true)
- {
- FieldBuilder fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName, ToDotNetTypeFromDBType(fi.FieldType), FieldAttributes.Private);
- PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName, PropertyAttributes.HasDefault, ToDotNetTypeFromDBType(fi.FieldType), null);
- Type[] ctorParams = new Type[] { typeof(string) };
- ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams);
- CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.FieldAlias });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- classCtorInfo = typeof(CategoryAttribute).GetConstructor(ctorParams);
- customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.Category });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- ctorParams = new Type[] { typeof(int) };
- classCtorInfo = typeof(CategoryPriorityAttribute).GetConstructor(ctorParams);
- customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { GetCategoryPriorityValueByCategoryName(fi.Category) });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
- MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr, ToDotNetTypeFromDBType(fi.FieldType), Type.EmptyTypes);
- ILGenerator ilGenerator = getMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr, null, new Type[] { ToDotNetTypeFromDBType(fi.FieldType) });
- ilGenerator = setMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldarg_1);
- ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- propertyBuilder.SetGetMethod(getMethodBuilder);
- propertyBuilder.SetSetMethod(setMethodBuilder);
- }
- }
- }
- /// <summary>
- /// 根据分类名称获取该分类的显示优先级
- /// </summary>
- /// <param name="categoryName">分类名称</param>
- /// <returns>显示优先级</returns>
- private static int GetCategoryPriorityValueByCategoryName(string categoryName)
- {
- if (s_categoryPriorityInfo != null)
- {
- foreach (CategoryPriorityInfo info in s_categoryPriorityInfo)
- {
- if (info.CategoryName == categoryName)
- {
- return info.Priority;
- }
- }
- }
- return int.MaxValue;
- }
- /// <summary>
- /// 创建类属性信息
- /// </summary>
- /// <param name="typeBuilder">类型生成器</param>
- /// <param name="dataColumnCollection">DataColumnCollection</param>
- private static void CreateProperties(TypeBuilder typeBuilder, DataColumnCollection dataColumnCollection)
- {
- foreach (DataColumn dataColumn in dataColumnCollection)
- {
- FieldBuilder fieldBuilder = null;
- if (dataColumn.DataType == typeof(DateTime))
- {
- fieldBuilder = typeBuilder.DefineField("m_" + dataColumn.ColumnName, typeof(string), FieldAttributes.Private);
- }
- else
- {
- fieldBuilder = typeBuilder.DefineField("m_" + dataColumn.ColumnName, typeof(string), FieldAttributes.Private);
- }
- PropertyBuilder propertyBuilder = null;
- if (dataColumn.DataType == typeof(DateTime))
- {
- propertyBuilder = typeBuilder.DefineProperty(dataColumn.ColumnName, PropertyAttributes.HasDefault, typeof(string), null);
- }
- else
- {
- propertyBuilder = typeBuilder.DefineProperty(dataColumn.ColumnName, PropertyAttributes.HasDefault, typeof(string), null);
- }
- Type[] ctorParams = new Type[] { typeof(string) };
- ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams);
- MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
- MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + dataColumn.ColumnName, getSetAttr, typeof(string), Type.EmptyTypes);
- ILGenerator ilGenerator = getMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + dataColumn.ColumnName, getSetAttr, null, new Type[] { typeof(string) });
- ilGenerator = setMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldarg_1);
- ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- propertyBuilder.SetGetMethod(getMethodBuilder);
- propertyBuilder.SetSetMethod(setMethodBuilder);
- }
- }
- /// <summary>
- /// 根据类名获取相应的类信息
- /// </summary>
- /// <param name="typeName">类名</param>
- /// <returns>类</returns>
- public static Type GetTypeByTypeName(string typeName)
- {
- try
- {
- if (s_dicTypes == null)
- {
- if (s_asmBuilder == null)
- {
- GenerateAssemboyAndModule();
- }
- s_dicTypes = new Dictionary<string, Type>();
- foreach (WaterWebGIS.QueryStatServiceProxy.GISLayer gisLayer in BasicGISService.GetLayers().LayerList)
- {
- try
- {
- Type type = CreateType(s_modBuilder, gisLayer);
- s_dicTypes.Add(gisLayer.LayerNameEN, type);
- }
- catch
- {
- }
- }
- }
- if (s_dicTypes.ContainsKey(typeName))
- {
- return s_dicTypes[typeName];
- }
- else
- {
- return null;
- }
- }
- catch
- {
- return null;
- }
- }
- public static object CreateObjectBaseOnLayerInfoAndObjectValue(WaterWebGIS.QueryStatServiceProxy.GISLayer gisLayer, SelectAction objectValue)
- {
- try
- {
- Type type = GetTypeByTypeName(gisLayer.LayerNameEN);
- if (type != null)
- {
- object obj = Activator.CreateInstance(type);
- if (obj != null)
- {
- foreach (WaterWebGIS.QueryStatServiceProxy.FieldInfo fi in gisLayer.FieldENlist)
- {
- string fieldValue = BasicGISService.GetLayers().GetValueFromRecord(objectValue.RecordSet, objectValue.Record, fi.FieldENName);
- object value = ConvertStringValueToSpecifyTypeValue(fieldValue, fi.FieldType);
- if (fi.FieldType == "datetime")
- {
- if (((DateTime)value) == DateTime.MinValue)
- {
- value = string.Empty;
- }
- else
- {
- value = value.ToString();
- }
- }
- if (fi.FieldType == "float")
- {
- value = Math.Round(Convert.ToDouble(value), );
- }
- PropertyInfo propertyInfo = type.GetProperty(fi.FieldENName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
- if (propertyInfo != null)
- {
- propertyInfo.SetValue(obj, value, null);
- }
- }
- }
- return obj;
- }
- return null;
- }
- catch
- {
- return null;
- }
- }
- /// <summary>
- /// 将字符串值转换成指定类型的值
- /// </summary>
- /// <returns>转换后的对象值</returns>
- private static object ConvertStringValueToSpecifyTypeValue(string value, string dbType)
- {
- if (dbType.ToLower() == "varchar")
- {
- return value;
- }
- else if (dbType.ToLower() == "int")
- {
- int temp = ;
- int.TryParse(value, out temp);
- return temp;
- }
- else if (dbType.ToLower() == "float")
- {
- float temp = ;
- float.TryParse(value, out temp);
- return temp;
- }
- else if (dbType.ToLower() == "datetime")
- {
- DateTime datetime;
- if (DateTime.TryParse(value, out datetime))
- {
- if (value != "0:00:00")
- {
- return datetime;
- }
- else
- {
- DateTime superMapDate = new DateTime(, , , , , );
- return superMapDate;
- }
- }
- else
- {
- return new DateTime();
- }
- }
- return null;
- }
- public static Type CreateTypeBaseOnDataTable(DataTable table)
- {
- if (s_asmBuilder == null)
- {
- GenerateAssemboyAndModule();
- }
- return CreateType(s_modBuilder, table);
- }
- /// <summary>
- /// 根据DataTable返回相应的对象集合
- /// </summary>
- /// <param name="table">DataTable</param>
- /// <returns>对象集合</returns>
- public static List<object> CreateObjectCollectionBaseOnDataTable(DataTable table)
- {
- if (table == null)
- {
- throw new ArgumentNullException("table不能为空!");
- }
- List<object> collection = new List<object>();
- try
- {
- Type type = CreateTypeBaseOnDataTable(table);
- if (type != null)
- {
- foreach (DataRow row in table.Rows)
- {
- object obj = Activator.CreateInstance(type);
- if (obj != null)
- {
- foreach (DataColumn column in table.Columns)
- {
- PropertyInfo propertyInfo = type.GetProperty(column.ColumnName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
- if (propertyInfo != null)
- {
- if (!string.IsNullOrEmpty(row[column.ColumnName]))
- {
- propertyInfo.SetValue(obj, ConvertStringToSpecifyType(column.DataType.FullName, row[column.ColumnName]), null);
- }
- }
- }
- }
- collection.Add(obj);
- }
- }
- return collection;
- }
- catch
- {
- return collection;
- }
- }
- private static object ConvertStringToSpecifyType(string typeName, string value)
- {
- switch (typeName)
- {
- case "System.Int32":
- //return int.Parse(value);
- return value;
- case "System.DateTime":
- DateTime? temp = DateTime.Parse(value);
- return temp.Value.ToString();
- case "System.Double":
- //return double.Parse(value);
- return value;
- case "System.Decimal":
- //return Decimal.Parse(value);
- return value;
- case "System.Byte":
- //return byte.Parse(value);
- return value;
- case "System.String":
- default:
- return value;
- }
- }
- #region 除指定列转换为string类型,其他类型按所给的数据类型进行转换
- //add by qzl @hn at20140424
- /// <summary>
- /// 除指定列转换为string类型,其他类型按所给的数据类型进行转换
- /// </summary>
- /// <param name="gisLayer">图层</param>
- /// <param name="objectValue">数据集</param>
- /// <param name="lstFiledName">转换为string类型的列</param>
- /// <returns></returns>
- public static object CreateObjectBaseOnLayerInfoAndObjectValueAndChangeText(GISLayer gisLayer, SelectAction objectValue, List<string> lstFiledName)
- {
- try
- {
- Type type = GetTypeByTypeNameToString(gisLayer.LayerNameEN, lstFiledName);
- if (type != null)
- {
- object obj = Activator.CreateInstance(type);
- if (obj != null)
- {
- foreach (FieldInfo fi in gisLayer.FieldENlist)
- {
- object value;
- if (lstFiledName.Contains(fi.FieldENName.ToLower()))
- {
- value ="******";
- }
- else
- {
- string fieldValue = BasicGISService.GetLayers().GetValueFromRecord(objectValue.RecordSet, objectValue.Record, fi.FieldENName);
- value = ConvertStringValueToSpecifyTypeValue(fieldValue, fi.FieldType);
- if (fi.FieldType == "datetime")
- {
- value = ((DateTime)value) == DateTime.MinValue ? string.Empty : value.ToString();
- }
- if (fi.FieldType == "float")
- {
- value = Math.Round(Convert.ToDouble(value), );
- }
- }
- PropertyInfo propertyInfo = type.GetProperty(fi.FieldENName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
- if (propertyInfo != null)
- {
- propertyInfo.SetValue(obj, value, null);
- }
- }
- }
- return obj;
- }
- return null;
- }
- catch
- {
- return null;
- }
- }
- /// <summary>
- /// 根据类名获取相应的类信息
- /// </summary>
- /// <param name="typeName">类名</param>
- /// <returns>类</returns>
- public static Type GetTypeByTypeNameToString(string typeName, List<string> lstFiledName)
- {
- try
- {
- if (s_dicTypes == null)
- {
- if (s_asmBuilder == null)
- {
- GenerateAssemboyAndModule();
- }
- s_dicTypes = new Dictionary<string, Type>();
- foreach (GISLayer gisLayer in BasicGISService.GetLayers().LayerList)
- {
- try
- {
- Type type = CreateTypeToString(s_modBuilder, gisLayer, lstFiledName);
- s_dicTypes.Add(gisLayer.LayerNameEN, type);
- }
- catch
- {
- }
- }
- }
- if (s_dicTypes.ContainsKey(typeName))
- {
- return s_dicTypes[typeName];
- }
- return null;
- }
- catch
- {
- return null;
- }
- }
- /// <summary>
- /// 创建类型
- /// </summary>
- /// <param name="modBuilder">模块生成器</param>
- /// <param name="layer">图层信息</param>
- /// <returns>类型信息</returns>
- private static Type CreateTypeToString(ModuleBuilder modBuilder, GISLayer layer, List<string> lstFiledName)
- {
- TypeBuilder typeBuilder = modBuilder.DefineType(layer.LayerNameEN, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout);
- CreateConstructor(typeBuilder);
- CreatePropertiesToString(typeBuilder, layer.FieldENlist, lstFiledName);
- return typeBuilder.CreateType();
- }
- /// <summary>
- /// 创建类属性信息
- /// </summary>
- /// <param name="typeBuilder">类型生成器</param>
- /// <param name="fieldInfoCollection">图层字段集合</param>
- private static void CreatePropertiesToString(TypeBuilder typeBuilder,
- IEnumerable<FieldInfo> fieldInfoCollection, List<string> lstFiledName)
- {
- foreach (FieldInfo fi in fieldInfoCollection)
- {
- if (fi.IsVisible == true)
- {
- MethodBuilder setMethodBuilder;
- MethodBuilder getMethodBuilder;
- FieldBuilder fieldBuilder;
- PropertyBuilder propertyBuilder;
- MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName |
- MethodAttributes.HideBySig;
- if (lstFiledName.Contains(fi.FieldENName.ToLower()))
- {
- fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName,
- typeof(string),
- FieldAttributes.Private);
- propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName,
- PropertyAttributes.HasDefault,
- typeof(string),
- null);
- getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr,
- typeof(string),
- Type.EmptyTypes);
- setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr,
- null,
- new Type[]
- {
- typeof(string)
- });
- }
- else
- {
- fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName,
- ToDotNetTypeFromDBType(fi.FieldType),
- FieldAttributes.Private);
- propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName,
- PropertyAttributes.HasDefault,
- ToDotNetTypeFromDBType(fi.FieldType),
- null);
- getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr,
- ToDotNetTypeFromDBType(fi.FieldType),
- Type.EmptyTypes);
- setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr,
- null,
- new Type[]
- {
- ToDotNetTypeFromDBType(
- fi.FieldType)
- });
- }
- Type[] ctorParams = new Type[] { typeof(string) };
- ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams);
- CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo,
- new object[] { fi.FieldAlias });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- classCtorInfo = typeof(CategoryAttribute).GetConstructor(ctorParams);
- customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.Category });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- ctorParams = new Type[] { typeof(int) };
- classCtorInfo = typeof(CategoryPriorityAttribute).GetConstructor(ctorParams);
- customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo,
- new object[]
- {
- GetCategoryPriorityValueByCategoryName
- (fi.Category)
- });
- propertyBuilder.SetCustomAttribute(customAttributeBuilder);
- ILGenerator ilGenerator = getMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- ilGenerator = setMethodBuilder.GetILGenerator();
- ilGenerator.Emit(OpCodes.Ldarg_0);
- ilGenerator.Emit(OpCodes.Ldarg_1);
- ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
- ilGenerator.Emit(OpCodes.Ret);
- propertyBuilder.SetGetMethod(getMethodBuilder);
- propertyBuilder.SetSetMethod(setMethodBuilder);
- }
- }
- }
- //end
- #endregion
- }
- }
Silverlight中如何自己写方法将DataTable转换为PagedCollectionView数据(动态创建类)的更多相关文章
- C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:
public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count); 将指定数目的字 ...
- 【转载】 C#中使用float.Parse方法将字符串转换为Float类型
在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为单精度Float类型就是一个常见的类型转换操作,float.Parse方法是C#中专门用来将字符串转换为float类型的,f ...
- 【转载】C#中使用float.TryParse方法将字符串转换为Float类型
在C#编程过程中,将字符串string转换为单精度float类型过程中,时常使用float.Parse方法,但float.Parse在无法转换的时候,会抛出程序异常,其实还有个float.TryPar ...
- 【转载】C#中使用double.TryParse方法将字符串转换为double类型
在C#编程过程中,将字符串string转换为double类型过程中,时常使用double.Parse方法,但double.Parse在无法转换的时候,会抛出程序异常,其实还有个double.TryPa ...
- 【转载】C#中使用double.Parse方法将字符串转换为双精度double类型
在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为双精度浮点类型double就是一个常见的类型转换操作,double.Parse方法是C#中专门用来将字符串转换为double ...
- 【转载】 C#中使用decimal.Parse方法将字符串转换为十进制decimal类型
在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为十进制decimal类型就是一个常见的类型转换操作,decimal.Parse方法是C#中专门用来将字符串转换为decima ...
- 【转载】C#中使用decimal.TryParse方法将字符串转换为十进制decimal类型
在C#编程过程中,将字符串string转换为decimal类型过程中,时常使用decimal.Parse方法,但decimal.Parse在无法转换的时候,会抛出程序异常,其实还有个decimal.T ...
- 【转载】 C#中使用int.TryParse方法将字符串转换为整型Int类型
在C#编程过程中,将字符串string转换为整型int过程中,时常使用的转换方法为int.Parse方法,但int.Parse在无法转换的时候,会抛出程序异常,其实还有个int.TryParse方法可 ...
- 【转载】C#中使用int.Parse方法将字符串转换为整型Int类型
在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为Int类型就是一个常见的类型转换操作,int.Parse方法是C#中专门用来将字符串转换为整型int的,int.Parse方 ...
随机推荐
- Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80
netstat -tulpn| grep :80 killall -9 httpd /etc/init.d/httpd start or service httpd start
- Online Procurement Auctions for Resource Pooling in Client-Assisted Cloud Storage Systems---INFOCOM 2015
[标题] [作者] [来源] [对本文评价] [why] 存在的问题 [how] [不足] assumption future work [相关方法或论文] [重点提示] [其它]
- java多线程并发编程
Executor框架 Executor框架是指java 5中引入的一系列并发库中与executor相关的一些功能类,其中包括线程池,Executor,Executors,ExecutorService ...
- 如何占用你用户的时间 and 如何提高客户的满意度 。 待续
未来的商业竞争, 可能本质上是在争取客户的时间 嗯..有不定时, 未知的奖励,游戏行业就经常使用, 比如打怪掉装备, 不一定掉什么好东西, 让人充满了期待, 玛雅宝石, 有一定的概率... 觉得公司员 ...
- selenium自动化遇见Cannot find class in classpath问题
今天遇见了Cannot find class in classpath的问题, org.testng.TestNGException: Cannot find class in classpath: ...
- js的变量声明以及变量提升
js的变量声明: js正常的变量声明就不多讲了,形如var a=1;这样的变量声明在实际开发中最常用. var a=1,b=2;这种以逗号分隔开的一次声明多个变量,其实相当于var a=1; var ...
- bootstrap如何自定义5等分
根据bootstrap源码改的1比5的栅格系统 /*5等分媒体查询样式begin*/ .col-xs-1-5,.col-sm-1-5,.col-md-1-5,.col-lg-1-5,.col-xs-4 ...
- Oracle中sys和system用户的区别
1.数据库的启动需要以SYSDBA/SYSOPER身份登录. 2.如果在同一主机上使用IPC连接到数据库使用操作系统授权,登录任何一个用户都可以拥有as sysdba和as sysoper. 3.sy ...
- python 元组 字符串 字典 列表嵌套练习题1
最近学习做的习题,直接复制过来 缩进就乱掉了,所以直接以图片方式上传,题目和答案一起
- 添加JUnit到Java Build Path
1.第一种 新建项目,点击右键,选择properties->Java Build Path->Libraries->add library->JUnit->JUnit4- ...