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

VulpesRank #55 · 29.2K reputationPosted Feb 28, 2012, 5:28 AM EST
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.
VulpesRank #55 · 29.2K reputationPosted Feb 28, 2012, 3:49 AM EST
Guest UserRank #4,868 · 321 reputationPosted Feb 28, 2012, 4:38 AM EST
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...
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 28, 2012, 5:58 PM EST
can we use
public static int AsId(this object s)
{
//our code.
}
because reader["CustomerId"] is object type.
correct me if i am wrong.
VulpesRank #55 · 29.2K reputationPosted Feb 28, 2012, 11:37 PM EST
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.