.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

TypeConverter & Ctype

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

What is the difference between creating a TypeConverter and then converting an object to different type and using directly CType.

For example, what is the differece between these two:

1. Getting TypeConverter for a bitmap object and then converting it to byte[]

2. Directly using Ctype function to convert bitmap to byte[]

May sound basic, but pls help!!!!

View Complete Post

More Related Resource Links

CTYPE woes



I'm getting the old "Object reference not set to an instance of an object" error on this code:

nonqueryCommand.Parameters.Add("@comment", SqlDbType.VarChar, 500)

nonqueryCommand.Parameters("@comment").Value = CType(FormView1.Row.FindControl("CommentsLabel"), TextBox).Text

"CommentsLabel" is a textbox, despite it's name (and I've tried the CTYPE ot Label too).


Any ideas?



WF4.0 Custom Activity - Property Editor or TypeConverter



As part of my custom activity development, I have a requirement to change the value of one property acording to another property's value.

For example, I have two properties- Position and Qualification in my custom activity. Once I select a position, the qualification should change according to the selected position value. Both, Position and Qualification  are string properties and the value of Position is populated with a TypeConverter. 

I tried with TypeConverter for Qualification property too. Issue is how to refresh the Qualification values on change of Position property?

I tried with PropertyEditor also. But not sure how to pass the data from my ActivityDesigner to PropertyEditor. I am handling the ModelItem.PropertyChanged event and getting the Qualification values. How to pass this values either to my TypeConverter or to My PropertyEditor?

PropertyEditor Code is as follows


Ctype(sender, integer)


This is an ugly cast, but the code for this solution is already in a bad place, and it's not my job to fix. I'm curious if there is a way to determine whether a cast will be valid prior to casting.

Dim size As Integer = CType(sender, Integer)

'If cast was successful
'pass size to DAL
'if not pass something else

How to make the XML serializer use the TypeConverter?


Hello everyone:

I'm in trouble.  I have a class named Money and represents exactly that:  Money.  Money in any currency.  I love it because I can add and subtract money objects and always get a correct result regardless of the differences in currency.  I also love it because its ToString() method returns the value properly formatted with the expected currency symbol.

Now today I want to serialize Money objects into XML.  I went ahead and provided a type converter that can convert to and from a string of the form "value ISOCode".  Examples:  "100 USD", "500 CRC", "30 MXN", "50 EUR".  The value part is expected to be serialized using the invariant culture.  I think this would be the best option for serialization.

The problem I have is that the XmlSerializer will not use the type converter.  Instead it will serialize the class as usual, property by property and put it as a child node of the containing class.

How can I make the XmlSerializer serialize Money objects as string using the provided type converter?  Note that IXmlSerializer is not an option because I want the Money class to be serialized as an attri

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend