LLBLGen v5.11.1 (19-Dec-2023)
Adapter Template / .NET 6
Azure SQL Database
I have created a new TypeConverter following instructions from: https://www.llblgen.com/Documentation/5.0/SDK/gui_implementingtypeconverter.htm
Converter Purpose (Make sure empty strings or whitespace get converted to NULL when saved to the DB; When reading, convert it back to Empty String).
I dropped it in my TypeConverters folder in the LLBLGen Installation Directory.
Opened LLBLGen, went to Project Settings => Type Conversions => Selected String type
I expected the list of converters to show my new converter, but it only showed the ones that come with LLBLGen.
I followed the instructions to debug (build in debug mode with PDBs and copied into the directory, attached to the llblgen.exe and set breakpoints on the 3 methods that get called by the designer; but the breakpoints were never caught.
Do you have any advice on what I am doing wrong?
Thanks in advance!
using System;
using System.ComponentModel;
namespace My.Data.LLBL.TypeConverters
{
[Description("Ensures Emtpy String or Whitespace values are converted to NULL in the Database. Will convert NULLS from Database to string.Empty.")]
public class StringConverter : TypeConverter
{
public StringConverter() {}
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
switch (sourceType.FullName)
{
case "System.String":
return true;
default:
return false;
}
}
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
{
switch (destinationType?.FullName)
{
case "System.String":
return true;
default:
return false;
}
}
public override object ConvertFrom(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
{
if (value is not string)
throw new NotSupportedException("Conversion from a value of type '" + value.GetType().ToString() + "' to System.String isn't supported");
string toReturn = value as string ?? string.Empty;
return toReturn;
}
public override object ConvertTo(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object? value, Type destinationType)
{
if (value is not null && value is not string)
throw new NotSupportedException("Conversion from a value of type '" + value.GetType().ToString() + "' to System.String isn't supported");
if (value is not null && ((string)value).Trim() == string.Empty)
value = null;
return value as string;
}
public override object CreateInstance(ITypeDescriptorContext? context, System.Collections.IDictionary? propertyValues)
{
return string.Empty;
}
}
}