473,394 Members | 1,746 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,394 software developers and data experts.

The Opposite of IFormattable

Dear C# Sages,

For my own persistence purposes I need to be able to load an object from
some source and re-fit it with its value that's represented as a string.

Many objects support "Parse" which takes a string input and sets the value
for the object. However, I can't find a way to "pre-identify" those objects
with the same ease I can do the opposite: ask an object if it's IFormattable
so that I can invoke its "ToString" method. Am I doomed to use reflection to
actually ask each object i come across if it has a "Parse" method that has a
string as paramter? Isn't there some "uber-Interface" this adheres to?

am I missing something?

Thanks
- Ron
Aug 17 '06 #1
4 1383
You can *always* invoke the ToString method, which is a method of the base
class Object.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Ron M. Newman" <co**********@confideltial.comwrote in message
news:ue**************@TK2MSFTNGP05.phx.gbl...
Dear C# Sages,

For my own persistence purposes I need to be able to load an object from
some source and re-fit it with its value that's represented as a string.

Many objects support "Parse" which takes a string input and sets the value
for the object. However, I can't find a way to "pre-identify" those
objects with the same ease I can do the opposite: ask an object if it's
IFormattable so that I can invoke its "ToString" method. Am I doomed to
use reflection to actually ask each object i come across if it has a
"Parse" method that has a string as paramter? Isn't there some
"uber-Interface" this adheres to?

am I missing something?

Thanks
- Ron

Aug 17 '06 #2
well, not always: it wont always give me a "high fidelity" string I can
persist and then re-load. (Image objects for instance).

But in any case, I was talking about the other way around, a
"FromString" - -- the "Parse" method which doesn't seem to come from an
interface but rather embedded in various classes which IMHO is a design
oversight by MS.

Ron

"Kevin Spencer" <uc*@ftc.govwrote in message
news:Ok**************@TK2MSFTNGP06.phx.gbl...
You can *always* invoke the ToString method, which is a method of the base
class Object.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Ron M. Newman" <co**********@confideltial.comwrote in message
news:ue**************@TK2MSFTNGP05.phx.gbl...
>Dear C# Sages,

For my own persistence purposes I need to be able to load an object from
some source and re-fit it with its value that's represented as a string.

Many objects support "Parse" which takes a string input and sets the
value for the object. However, I can't find a way to "pre-identify" those
objects with the same ease I can do the opposite: ask an object if it's
IFormattable so that I can invoke its "ToString" method. Am I doomed to
use reflection to actually ask each object i come across if it has a
"Parse" method that has a string as paramter? Isn't there some
"uber-Interface" this adheres to?

am I missing something?

Thanks
- Ron


Aug 17 '06 #3
Ron,

If you build a new class, should the ToString method always be declared
overridden from object in a method (what is not always the fact and than you
get back only object information)

If it is overloaded can be dependable from the class, when it is overloaded
that can be done with everything. In the String class one of those has the
IFormatProvider, but how it works is completely dependend from how the
builder of the class has used the overriding and possible the overloading.

In normal OOP programming there should in my opinion be no reason to use
late binding, therefore no reason to find out what members an object has and
how they are implemented with reflection.

Cor

"Ron M. Newman" <co**********@confideltial.comschreef in bericht
news:ue**************@TK2MSFTNGP05.phx.gbl...
Dear C# Sages,

For my own persistence purposes I need to be able to load an object from
some source and re-fit it with its value that's represented as a string.

Many objects support "Parse" which takes a string input and sets the value
for the object. However, I can't find a way to "pre-identify" those
objects with the same ease I can do the opposite: ask an object if it's
IFormattable so that I can invoke its "ToString" method. Am I doomed to
use reflection to actually ask each object i come across if it has a
"Parse" method that has a string as paramter? Isn't there some
"uber-Interface" this adheres to?

am I missing something?

Thanks
- Ron

Aug 18 '06 #4
What are your requirements? Most classes dont' translate from strings well,
if at all. What sort of string would resolve to a Socket instance, for
example? There are very few types, and most of them are Value Types, that
can be parsed from strings. Other than that, you might benefit from using
XML Serialization, again, according to your requirements.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Ron M. Newman" <co**********@confideltial.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
well, not always: it wont always give me a "high fidelity" string I can
persist and then re-load. (Image objects for instance).

But in any case, I was talking about the other way around, a
"FromString" - -- the "Parse" method which doesn't seem to come from an
interface but rather embedded in various classes which IMHO is a design
oversight by MS.

Ron

"Kevin Spencer" <uc*@ftc.govwrote in message
news:Ok**************@TK2MSFTNGP06.phx.gbl...
>You can *always* invoke the ToString method, which is a method of the
base class Object.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Ron M. Newman" <co**********@confideltial.comwrote in message
news:ue**************@TK2MSFTNGP05.phx.gbl...
>>Dear C# Sages,

For my own persistence purposes I need to be able to load an object from
some source and re-fit it with its value that's represented as a string.

Many objects support "Parse" which takes a string input and sets the
value for the object. However, I can't find a way to "pre-identify"
those objects with the same ease I can do the opposite: ask an object if
it's IFormattable so that I can invoke its "ToString" method. Am I
doomed to use reflection to actually ask each object i come across if it
has a "Parse" method that has a string as paramter? Isn't there some
"uber-Interface" this adheres to?

am I missing something?

Thanks
- Ron



Aug 18 '06 #5

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

Similar topics

4
by: comp.lang.php | last post by:
Hi. Relative php newbie but longtime coder in other langs. Environment: PHP4. Looking for a language construct or function that gives the opposite of array(), example: function xyz($fmt,...
22
by: achrist | last post by:
The yield statement looks to be a big step toward some kind of lightweight concurrency-oriented programming in python. Is there any similarly nice way to do the opposite of yield, just sit around...
15
by: Greg Schmidt | last post by:
We all know that one trick in dealing with old browsers is to add extra bits of content with class="old", where old is defined as display:none in a style sheet that is @imported so that old...
2
by: ormy28 | last post by:
I really need some help with the following problem if anyone would be willing. I need a list box to list the opposite of what appears in a query. Heres the details: My database is for a...
5
by: Tony | last post by:
Hi, I am looking for the opposite of wm_close, I assume it's possibly wm_open but no info comes up with that term. so, what is the opposite of WM_Close Any ideas welcome Tony
9
by: pranav.choudhary | last post by:
Hi I am new to python. I wanted to know if there is an opposite of "import"
11
by: igor.tatarinov | last post by:
Given a bunch of arrays, if I want to create tuples, there is zip(arrays). What if I want to do the opposite: break a tuple up and append the values to given arrays: map(append, arrays, tupl)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.