LLBLGen 关于类型转换
关于类型转换的问题,在MS的MSDN上也有提到过,但是LLBLGen 要有一个现在的DLL才可以在设计状态下使用。我们只是自己写写一个DLL了,在安装目录下:\Program Files (x86)\Solutions Design\LLBLGen Pro v2.6 Demo\TypeConverters,我们只要把我写自己写好的DLL放在这里,就可以使用了。
比如一些字段我们为nvchar(1),我们存的是Y,N,那你当然是想把它转成bool型了。只有绑定了这个问题才可以解决checkbox的问题。
代码也不难,我就直接给出来了
namespace CRD.TypeConverters
{
[Description("Converter with as core type System.Boolean, for mapping a field with a .NET type System.Boolean onto a string database field")]
public class BooleanStringConverter : TypeConverter
{
/// <summary>
/// Initializes a new instance of the <see cref="BooleanStringConverter"/> class.
/// </summary>
public BooleanStringConverter()
{
}
/// <summary>
/// Returns whether this converter can convert an object of the given type to the type of this converter (Boolean).
/// </summary>
/// <param name="context">Ignored</param>
/// <param name="sourceType">A <see cref="T:System.Type"/> that represents the type you want to convert from.</param>
/// <returns>
/// <see langword="true "/>if this converter can perform the conversion; otherwise, <see langword="false"/>.
/// </returns>
/// <remarks>Accepted types are: String</remarks>
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
// any integer type is accepted. No fractional types like float/double.
switch (sourceType.FullName)
{
case "System.String":
return true;
default:
return false;
}
}
/// <summary>
/// Returns whether this converter can convert the object to the specified type.
/// </summary>
/// <param name="context">Ignored</param>
/// <param name="destinationType">A <see cref="T:System.Type"/> that represents the type you want to convert to.</param>
/// <returns>
/// <see langword="true "/>if this converter can perform the conversion; otherwise, <see langword="false"/>.
/// </returns>
/// <remarks>Accepted types are: String. True will be converted to 1, false will be
/// converted to 0.</remarks>
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
// any integer type is accepted. No fractional types like float/double.
switch (destinationType.FullName)
{
case "System.String":
return true;
default:
return false;
}
}
/// <summary>
/// Converts the given object to the type of this converter (Boolean).
/// </summary>
/// <param name="context">Ignored</param>
/// <param name="culture">Ignored</param>
/// <param name="value">The <see cref="T:System.Object"/> to convert.</param>
/// <returns>
/// An <see cref="T:System.Object"/> that represents the converted value, which is of type boolean.
/// </returns>
/// <exception cref="T:System.NotSupportedException">The conversion could not be performed.</exception>
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
bool toReturn = true;
switch (value.GetType().FullName)
{
case "System.String":
toReturn = ((string)value == "Y");
break;
case "System.DBNull":
toReturn = false;
break;
default:
throw new NotSupportedException("Conversion from a value of type '" + value.GetType().ToString() + "' to System.Boolean isn't supported");
}
return toReturn;
}
/// <summary>
/// Converts the given value object to the specified type
/// </summary>
/// <param name="context">Ignored</param>
/// <param name="culture">Ignored</param>
/// <param name="value">The <see cref="T:System.Object"/> to convert.</param>
/// <param name="destinationType">The <see cref="T:System.Type"/> to convert the <paramref name="value"/> parameter to.</param>
/// <returns>
/// An <see cref="T:System.Object"/> that represents the converted value. The value will be 1 if <paramref name="value"/> is true, otherwise 0
/// </returns>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="destinationType"/> parameter is <see langword="null"/>.</exception>
/// <exception cref="T:System.NotSupportedException">The conversion could not be performed.</exception>
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (value == null)
{
throw new ArgumentNullException("value", "Value can't be null");
}
if (!(value is bool))
{
throw new ArgumentException("Value isn't of type boolean", "value");
}
if ((bool)value)
{
switch (destinationType.FullName)
{
case "System.String":
return (string)"Y";
case "System.DBNull":
return (string)"N";
default:
throw new NotSupportedException("Conversion to a value of type '" + destinationType.ToString() + "' isn't supported");
}
}
else
{
switch (destinationType.FullName)
{
case "System.String":
case "System.DBNull":
return (string)"N";
default:
throw new NotSupportedException("Conversion to a value of type '" + destinationType.ToString() + "' isn't supported");
}
}
}
/// <summary>
/// Creates an instance of the Type that this <see cref="T:System.ComponentModel.TypeConverter"/> is associated with (bool)
/// </summary>
/// <param name="context">ignored.</param>
/// <param name="propertyValues">ignored.</param>
/// <returns>
/// An <see cref="T:System.Object"/> of type bool. It always returns 'true' for this converter.
/// </returns>
public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
{
return true;
}
}
}
我这里只举一个的类型写法,至于其它的我就上传了。下载
至于它的解释网上看看就可以了,我就不费话了。
转载于:https://www.cnblogs.com/heyu5220/archive/2009/12/03/1616126.html
LLBLGen 关于类型转换相关推荐
- java基本类型转换,随记
java基本类型转换: double double 转 long double random = Math.round(Math.random()*10000); long l = new Doubl ...
- Go 知识点(12) — 类型转换以三方库 cast
类型转换在编程语言中是很常见的操作,在 Go 语言中其类型转换有下面一些注意点. 1. 整数类型之间的转换 对于整数类型转换,原则上目标类型的取值范围要包含被转换值,也就是说要转换类型的值取值范围要小 ...
- 数据类型转换pytorch
du = torch.ones([2,2]) a = np.array([[1,2],[3,4]],dtype=np.float32) b = torch.from_numpy(a)#数据类型是不变的 ...
- tf.cast()数据类型转换
tf.cast()函数的作用是执行 tensorflow 中张量数据类型转换,比如读入的图片如果是int8类型的,一般在要在训练前把图像的数据格式转换为float32. cast定义: cast(x, ...
- Java中如何实现Date与String之间的数据类型转换
String 数据类型转换成 Date String inputDate = "2021-04-11";Date outputDate = null;SimpleDateForma ...
- Java基本数据之间的类型转换
Java 数据类型及类型转换 基本数据类型:共八种: 复合类型:字符串(String),数组(array),类(Class),接口(Interface)等等: 其中个人常用的有:int,boolean ...
- 自动类型转换和强制类型转换
自动类型转换: 在Java中,任何情况下,整数类型的字面值默认当成int类型处理 小容量可以自动转换成大容量,这种操作被称为自动类型转换 容量大小的定义: 容量大小不是指数据类型的字节数,而是指这个数 ...
- Java 数据类型转换
学而时习之,温故而知新. 数据类型转换,先放一张图,了解数据类型 简单数据类型之间的转换又可以分为: 1 低级到高级的自动类型转换 2 级到低级的强制类型转换 3 包装类过渡类型转换. (有时候我们有 ...
- Java基础语法(一)注释,关键字,常量,变量,数据类型,标识符,数据类型转换...
从今天开始,记录学习Java的过程.要学习Java首先得有环境,至于环境的安装我就不说了,百度有很多教程,比如:http://jingyan.baidu.com/article/20095761904 ...
最新文章
- 重庆python就业工资待遇-重庆达内毕业的Python学员都在做什么?能拿多少工资?...
- jmeter压测过程中内存溢出
- 每日一小练——按字典顺序列出全部子集
- WWW超文本源码浏览器
- matlab var std,Matlab var std cov 函数解析
- 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重定向
- oracle DB死锁
- 自动驾驶车辆转向控制(通过支持转角控制的EPS实现角速度控制)
- shell按照时间排序_初识Shell(3)
- 第jiu届蓝桥杯单片机省赛真题_2018第九届蓝桥杯省赛真题 C语言B组 第二题
- MariaDB数据库导出导入
- no zuo no die 歌
- weedfs php,Weed-FS之Volume数据迁移
- hpe服务器中ilo的作用,产品技术-HPE iLO-新华三集团-H3C
- ElasticSearch系列——Kibana,核心概念
- win10安装docker导致virtualbox无法启动问题解决
- 光伏扶贫项目指标下达 如何严把光伏质量关?
- STM32L系列简介
- bzoj-1565 植物大战僵尸
- 欧盟将制定新物联网安全规定