将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数据(动态创建类)的更多相关文章

  1. C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:

    public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count); 将指定数目的字 ...

  2. 【转载】 C#中使用float.Parse方法将字符串转换为Float类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为单精度Float类型就是一个常见的类型转换操作,float.Parse方法是C#中专门用来将字符串转换为float类型的,f ...

  3. 【转载】C#中使用float.TryParse方法将字符串转换为Float类型

    在C#编程过程中,将字符串string转换为单精度float类型过程中,时常使用float.Parse方法,但float.Parse在无法转换的时候,会抛出程序异常,其实还有个float.TryPar ...

  4. 【转载】C#中使用double.TryParse方法将字符串转换为double类型

    在C#编程过程中,将字符串string转换为double类型过程中,时常使用double.Parse方法,但double.Parse在无法转换的时候,会抛出程序异常,其实还有个double.TryPa ...

  5. 【转载】C#中使用double.Parse方法将字符串转换为双精度double类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为双精度浮点类型double就是一个常见的类型转换操作,double.Parse方法是C#中专门用来将字符串转换为double ...

  6. 【转载】 C#中使用decimal.Parse方法将字符串转换为十进制decimal类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为十进制decimal类型就是一个常见的类型转换操作,decimal.Parse方法是C#中专门用来将字符串转换为decima ...

  7. 【转载】C#中使用decimal.TryParse方法将字符串转换为十进制decimal类型

    在C#编程过程中,将字符串string转换为decimal类型过程中,时常使用decimal.Parse方法,但decimal.Parse在无法转换的时候,会抛出程序异常,其实还有个decimal.T ...

  8. 【转载】 C#中使用int.TryParse方法将字符串转换为整型Int类型

    在C#编程过程中,将字符串string转换为整型int过程中,时常使用的转换方法为int.Parse方法,但int.Parse在无法转换的时候,会抛出程序异常,其实还有个int.TryParse方法可 ...

  9. 【转载】C#中使用int.Parse方法将字符串转换为整型Int类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为Int类型就是一个常见的类型转换操作,int.Parse方法是C#中专门用来将字符串转换为整型int的,int.Parse方 ...

随机推荐

  1. 关于mac地址的一点感想

    因为怕mac地址冲突导致环路影响,所以修改了本地设备的mac地址.地址修改为 77:77:77:00:22:11, 结果导致 wlan0 下发不下来. 查看配置选项/etc/config/wirele ...

  2. [转] Gvim for windows中块选择的方法

    在gvim(windows版)中,块选择的快捷键不是<Ctrl-v>,此快捷键为粘贴. 一般的选择模式为:v(小写),此时会显示:可视. 行选择模式为:V(大写),此时会显示:可视-行. ...

  3. C# 语言规范_版本5.0 (第18章 不安全代码)

    1. 不安全代码 **(注:此章对于跨多语言编程开发非常重要,如遇异常无法完成跨语言,建议使用此种方式.) 如前面几章所定义,核心 C# 语言没有将指针列入它所支持的数据类型,从而与 C 和 C++ ...

  4. ng-Directive

    伪代码: var myModule = angular.module(...); myModule.directive('namespaceDirectiveName', function facto ...

  5. 解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误

    修改Web.config,增加requestValidationMode="2.0"属性值 <system.web> <httpRuntime requestVa ...

  6. MyBatis中update的使用

    当你传入所需要修改的值为一个实体对象时,可能只改动了其中部分的值.那么其他值需要做一个判断是否为空值的操作. XXXmapper.xml <update id="updateMembe ...

  7. WEB 技术分类 Javascript DOM(Element Node) BOM

    Web technology for developers   Web 技术文档 备注:本文介绍web technology的分类,各自职责,因为之前一直就没有搞明白各种技术.各种名词究竟是属于哪个范 ...

  8. CSS 选择器之基本选择器 属性选择器 伪类选择器

    CSS 选择器 常见的选择器列表图 CSS选择器笔记 基本选择器 通配符选择器(*) 元素选择器(E) 类选择器(.className)    所有浏览器都支持类选择器,但多类选择器(.classNa ...

  9. 二十九、oracle 触发器

    一.触发器简介 触发器的定义就是说某个条件成立的时候,触发器里面所定义的语句就会被自动的执行.因此触发器不需要人为的去调用,也不能调用.然后,触发器的触发条件其实在你定义的时候就已经设定好了.这里面需 ...

  10. 将可执行exe文件注册成windows服务

    要把应用程序添加为服务,你需要两个小软件:Instsrv.exe和Srvany.exe.Instsrv.exe可以给系统安装和删除服务,Srvany.exe可以让程序以服务的方式运行.这两个软件都包含 ...