473,379 Members | 2,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Extention method return types

I'm do meore and more with extention methods, totally cool. They are making
life much easier for IU developers. I'm trying to add a return type of struct
to a asp.net DropDownList of type struct. The idea is that if the conversion
to say Int32 failed and a default value was used i can also return a
Pass/Fail bool, int code to let the developer know that it failed or the
reason for the failure.

Where should the struse be defined for the return type? It's a simple
question, but i really don't know the answer.

Has anyone else done this and do you know and artical or have an example.

thanks!!!
--
Share The Knowledge. I need all the help I can get and so do you!
Aug 1 '08 #1
4 1251
On Aug 1, 3:12*pm, Yankee Imperialist Dog
<YankeeImperialist...@discussions.microsoft.comwro te:
I'm do meore and more with extention methods, totally cool. They are making
life much easier for IU developers. I'm trying to add a return type of struct
to a asp.net DropDownList of type struct. The idea is that if the conversion
to say Int32 failed and a default value was used i can also return a
Pass/Fail bool, int code to let the developer know that it failed or the
reason for the failure.

Where should the struse be defined for the return type? It's a simple
question, but i really don't know the answer.

Has anyone else done this and do you know and artical or have an example.
A few questions:
1) Why do you want it to be a struct?
2) Why do you want to use a code for the failure instead of a message?

As for where the type is defined - anywhere, basically. An extension
method is just a normal static method with some extra syntactic sugar,
so the normal rules apply.

Jon
Aug 1 '08 #2
I appreciate the very prompt reply!
1. I would like two values returned, would a class be a better choice?
1.a I can call two seprate extention methods for valueexists then ToInt32,
but i may also want to retrun the reason like it's empty, it's null, it's
just not there.

2. Then in the class file that defines the methods for the name space would
make sense?
--
Share The Knowledge. I need all the help I can get and so do you!
"Jon Skeet [C# MVP]" wrote:
On Aug 1, 3:12 pm, Yankee Imperialist Dog
<YankeeImperialist...@discussions.microsoft.comwro te:
I'm do meore and more with extention methods, totally cool. They are making
life much easier for IU developers. I'm trying to add a return type of struct
to a asp.net DropDownList of type struct. The idea is that if the conversion
to say Int32 failed and a default value was used i can also return a
Pass/Fail bool, int code to let the developer know that it failed or the
reason for the failure.

Where should the struse be defined for the return type? It's a simple
question, but i really don't know the answer.

Has anyone else done this and do you know and artical or have an example.

A few questions:
1) Why do you want it to be a struct?
2) Why do you want to use a code for the failure instead of a message?

As for where the type is defined - anywhere, basically. An extension
method is just a normal static method with some extra syntactic sugar,
so the normal rules apply.

Jon
Aug 1 '08 #3
Yankee Imperialist Dog <Ya******************@discussions.microsoft.com>
wrote:
I appreciate the very prompt reply!
1. I would like two values returned, would a class be a better choice?
Either would be okay, but class is a better "default choice". Unles
you've got a reason to make it a value type, I'd stick with a class.
1.a I can call two seprate extention methods for valueexists then ToInt32,
but i may also want to retrun the reason like it's empty, it's null, it's
just not there.
Returning a reason is fine, but a string tends to be easier to
understand than an integer.
2. Then in the class file that defines the methods for the name space would
make sense?
No, the class which defines the extension methods has to be a static
class, but you could do it in the same namespace.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Aug 1 '08 #4
noted as for the text, i wanted to keep this example simple for an answer.
Thanks you , you answered my question.
Very appreciated
--
Share The Knowledge. I need all the help I can get and so do you!
"Jon Skeet [C# MVP]" wrote:
Yankee Imperialist Dog <Ya******************@discussions.microsoft.com>
wrote:
I appreciate the very prompt reply!
1. I would like two values returned, would a class be a better choice?

Either would be okay, but class is a better "default choice". Unles
you've got a reason to make it a value type, I'd stick with a class.
1.a I can call two seprate extention methods for valueexists then ToInt32,
but i may also want to retrun the reason like it's empty, it's null, it's
just not there.

Returning a reason is fine, but a string tends to be easier to
understand than an integer.
2. Then in the class file that defines the methods for the name space would
make sense?

No, the class which defines the extension methods has to be a static
class, but you could do it in the same namespace.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Aug 1 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
1
by: Carl Ogawa | last post by:
How do I make .cgi extention work? I installed ActivePerl 5.8. My CGI scripts work fine with .PL extention but not .CGI extention although I associated CGI extention as exactly same as PL...
3
by: Tuvas | last post by:
I have been writing a program that is designed to return an 8 byte string from C to Python. Occasionally one or more of these bytes will be null, but the size of it will always be known. How can I...
18
by: Daniel Gustafsson | last post by:
Hi there, hmm, I've just started with C# and I'm experimenting with method overloading. It seems like it's not possible to override method using return types, only parameters. Is that by design,...
3
by: Paul Michaud | last post by:
Consider the following: Class A { .... } Class B:A { ....
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
by: godfather96 | last post by:
I am using a web control called eXml which is an extention to ms xml web control which supports xslt 2.0 when trying to group elements i receive the following error: group-by is not a valid...
5
by: Krustov | last post by:
I have the following list of image files . When searching the latest (numbered file) in this particular case its background_4.*** and its a .jpg file - but - the latest file in the list could...
9
by: VK | last post by:
<OT>I am finishing TransModal 0.1 so planning to move it from alpha to beta stage.<OT> Besides that I am planning to write an introductory to inheritance schema currently used in Javascript...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.