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

Reflection, Custom Attributes, Inheritance Advice Needed

Lee
I need to implement a custom ToString method for derived classes.

The method should return a string that is the result of concatenating the
results of a ToString on each of the fields in the class. Individual fields
can specify a custom attribute [Format=string] to allow for custom
formatting of values.

I think I know enough to implement this but if someone already has a sample
of something similar I would appreciate it.

My questions are these:

1. Once I create the method, how do I share it?
2. Can I put this in a base class and inherit this implementation?
3. Would inheritance be easier if the method name was not ToString but
perhaps Format?
4. What must I do to insure the fields are concatenated in the order they
are specified in the source?

TIA

Lee
Nov 17 '05 #1
1 1548
On Sat, 24 Sep 2005 08:18:58 GMT, "Lee"
<fl***********@nospam.yahoo.com> wrote in
<SZ***************@newssvr29.news.prodigy.net>:
I need to implement a custom ToString method for derived classes.

The method should return a string that is the result of concatenating the
results of a ToString on each of the fields in the class. Individual fields
can specify a custom attribute [Format=string] to allow for custom
formatting of values.

I think I know enough to implement this but if someone already has a sample
of something similar I would appreciate it.

My questions are these:

1. Once I create the method, how do I share it?
What do you mean by "share"? You can make it public so that any class
with an instance of your derived class can access it.
2. Can I put this in a base class and inherit this implementation?
Yes, but remember that C# only supports single inheritance, so you
can't do something convenient like stick in in a utility class and
then inherit it whereever you need it.
3. Would inheritance be easier if the method name was not ToString but
perhaps Format?
Probably not.
4. What must I do to insure the fields are concatenated in the order they
are specified in the source?


That I'm not sure about.
--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research
Nov 17 '05 #2

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

Similar topics

5
by: Frazer | last post by:
hi could any one tell me which real life senarios reflection can be used in ? thnx
1
by: Hari | last post by:
Hello, I am quite new to C# and when reading over a couple of books discovered the presence of reflection and attributes. While, I do understand them a little, it would be great if I could know...
5
by: Wiktor Zychla | last post by:
Hello, I still have some problems with custom attributes and I ask someone for a helpful hand. In the appendix is the trivial ILAsm code with single custom attribute. The code compiles OK but...
2
by: Tilted | last post by:
As I'm not working on many c# projects at the moment I thought I'd spend some time investigating the subject line. Getting quite close to a conclusion, it works, it's a little slow (but still in...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
1
by: Good Enchiladas | last post by:
Is it possible to determine a method's own attributes from within the method without hardcoding the name of the method as a constant within the method? Please tell me if it is possible and how it...
2
by: Philip Limbeck | last post by:
Hi, I am currently stuck with a problem concerning reflection. We have to remove a Custom class attribute from an instance before giving the instance to another subsystem. Is this possible...
15
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.