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

Override classes/objects within a context?

Hi all!

I wondering if there is any method to override object/class within a
context, like this:

// MyNullFileInfo is derived from FileInfo

let (System.IO.FileInfo = MyNullFileInfo) {
FileInfo fi = new FileInfo(); // create a MyNullFileInfo.
fi...... //
// call some other method that use FileInfo, and they will also use
// MyNullFileInfo instead
}

Nov 16 '05 #1
2 1130
Aquila Deus wrote:
Hi all!

I wondering if there is any method to override object/class within a
context, like this:

<snip>

If I understand correctly, you're asking if you can override this kind
of statement:

SomeType x = new SomeType();

to actually produce an SomeOtherType object instead, and the answer is
yes, you do it like this:

SomeType x = new SomeOtherType();

of course, this means SomeOtherType must descend from SomeType.

Now, if I understand the full question correctly, you're asking if you
can ask methods you call from your code do the same substitution
automatically, ie. every place they do the first statement they should
do the second statement instead, then the answer is no.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vkarlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #2
Lasse Vågsæther Karlsen wrote:
Aquila Deus wrote:
Hi all!

I wondering if there is any method to override object/class within a context, like this: <snip>

If I understand correctly, you're asking if you can override this

kind of statement:

SomeType x = new SomeType();

to actually produce an SomeOtherType object instead, and the answer is yes, you do it like this:

SomeType x = new SomeOtherType();

of course, this means SomeOtherType must descend from SomeType.

Now, if I understand the full question correctly, you're asking if you can ask methods you call from your code do the same substitution
automatically, ie. every place they do the first statement they should do the second statement instead, then the answer is no.


What I want is not just substution, but some kind of dynamic-scoping
support. I'm thinking of using global delegates (and static methods to
create obj) which can be easily substituted:

DelegateTemplate<SomeType> CreateSomeType = delegate() { return new
SomeType(); }

But it would need thread/fiber-local variables (is there such thing in
..net?) and a mechanism to ensure the substitution is always restored
after the context (maybe try-finally can work).

Nov 16 '05 #3

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

Similar topics

18
by: vrillusions | last post by:
I've been using functions since I first started using php, but I've been hearing more and more about classes, which I never really looked at that much. I understand the whole OO programming...
5
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window {...
5
by: Stoyan | last post by:
Hi All, I don't understand very well this part of MSDN: "Derived classes that override GetHashCode must also override Equals to guarantee that two objects considered equal have the same hash code;...
14
by: knocte | last post by:
Hello. I have a problem with C# language. I want to define an algorithm on a static function inside an abstract class. This function calls a static variable inside the same class. Then I want to...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
7
by: fakeprogress | last post by:
For a homework assignment in my Data Structures/C++ class, I have to create the interface and implementation for a class called Book, create objects within the class, and process transactions that...
2
by: Jeff Rush | last post by:
While I have a reasonable understanding of the differences in new-style versus old-style classes, tonight while working a C extension module I realized I don't know how to indicate which style my C...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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:
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...
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...

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.