Prev | Current Page 699 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"

Longitude + "W";
}
else
{
Long = (double)Math.Abs(Loc.Longitude) + "E";
}
// Display lat and long as concantenated string with
// a comma as the separator
return Lat + "," + Long;
}
if (destinationType == typeof(InstanceDescriptor))
{
MemberInfo memberInfo = null;
object[] memberParameters = null;
Location Loc = (Location)value;
Type doubleType = typeof(double);
memberInfo = typeof(Location).GetConstructor(new Type[] { doubleType,
doubleType });
CHAPTER 11 ?–  DES IGN-TIME S UPPORT 541
memberParameters =
new object[] { Loc.Latitude, Loc.Longitude };
return new InstanceDescriptor(memberInfo, memberParameters);
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool CanConvertTo(ITypeDescriptorContext
context, Type destinationType)
{
if ((typeof(string) == destinationType) ||
(typeof(InstanceDescriptor) == destinationType))
{
return true;
}
else
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext
context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
else
return base.CanConvertFrom(context, sourceType);
}
}
}
When the page parser encounters a type that has a type converter associated with it via the
following syntax, it uses the type converter??™s methods to assist with parsing the property to/from a
string value:
[TypeConverter(typeof(LocationConverter))]
public class Location
{
.


Pages:
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711