Ive wrote a few Extension\Helper methods for converting data from a database into a business object of the same type.
For example I have AsId(); which converts\casts a string to an int.
However, when I come to bolt on one of my Extension methods I am unable to, I want AsId(); added like so
CustomerId = reader["CustomerId"].AsId();
But when I use try to access the method from intellisense it only gives me the common base types ie ToString() etc.
How can I get intellisense to pick up my set of Extension methods? ive seen it done before but cant work out how to do it...
Loading
VulpesPosted Feb 28, 2012, 10:28 AM
A 'using' directive then needs to be added to bring the namespace into scope.
From your description, I would guess that the signature of the AsId() method looks like this:
public static int AsId(this string s)
{
// code
}
If so and it's in scope, then it should show up in intellisense as soon as you type a dot after ToString().
As reader["CustomerId"] returns an object it will certainly need to have ToString() applied to it before you can parse it to an int.
VulpesPosted Feb 29, 2012, 4:37 AM
However, you'd need to wrap the call in a try/catch in case some object is passed in which can't be converted to an int.
Jignesh TrivediPosted Feb 28, 2012, 10:58 PM
can we use
public static int AsId(this object s)
{
//our code.
}
because reader["CustomerId"] is object type.
correct me if i am wrong.
Guest UserPosted Feb 28, 2012, 9:38 AM
Unfortunately adding the ToString().AsId() didnt work : (
the code example I am referencing shows it is possible like so
CustomerId = reader["CustomerId"].AsId();
By pressing the dot after ["CustomerId"] in the reference code works fine!? but in my code it doesnt.
Ive checked reference assemblies etc and everything is like for like...
VulpesPosted Feb 28, 2012, 8:49 AM