Replace a framework class

  • Thread starter Thread starter e-mre
  • Start date Start date
E

e-mre

Is is possible to replace a framework class for my application?

Let's say that I want to add a new property to the System.Data.Dataset
class. I can do that by extending the class. But I also want my new class to
replace the default System.Data.Dataset class in the framework. Whenever
System.Data.Dataset is referenced in my application, the reference should
point the my extended DataSet class. Other classes and procedures that are
already using System.Data.Dataset class should now start using my class.

Java guys say that they can do this by copying the source code of the
required class into the project, making the changes on the source and
compiling it into the application package. Is this possible for dotNET?

e-mre
 
To my knowledge, no. And it doesn't seem like a good idea, anyway, to hijack
a class like this. As a matter of principle, other developers should have
the choice of which class they wish to use. As a matter of policy, if your
company is requiring everyone to use the new DataSet class, that's something
that will have to be enforced by other means.
 
Hi E-mre,

As for .NET framework's fundamental class library, it doesn't support
manually customization or replacement. This is because framework class
library is deployed with the .net framework CLR runtime, and all these
class library assemblies are compiled with a specified strong-name
identity. Therefore, you can not build a custom assembly to replace any one
of the fundamental class library. So far, if you want some customization on
some functionality, you may try creating a derived class from built-in
one(if supported) and use your own derived classes in application code.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
Extending an already existing class is a solution but it will not solve
every case.

Let's say that I have a extended a class, say DataSet, and named it
MyDataSet.

The new class MyDataSet will have all the functionality of the DataSet class
but will take place in a completely different namespace. I can use MyDataSet
class in my code. But existing code in the .NET framework or in other third
party code that refer to the DataSet class will still refer to the same
class. MyDataSet class will be left out of the loop.

Perhaps DataSet class is a bad example for the case but I hope you get the
picture. Any suggested solution for this?

Emre
 
The problem with what you want to do is that consumers of the underlying
class, in your example - DataSet, expect it to behave in a particular way.
If you override one of DataSet's members or properties and change the
behavior, you risk breaking someone else's code and the end user nor the
other developer will ever figure out why.

This issue has come up over and over in the history of the PC. For example,
there is a bug in the original IBM PC BIOS Int 10 video interface. That bug
is now a feature and still exists in all Int 10 BIOS handlers. A more
recent example is that the Vista development team found a bug in XP's disk
caching. During testing, they found that there are commercial applications
that take advantage of this bug for performance reasons. As a result, Vista
has a user configurable switch that emulates this bug, at the risk of data
integrity. (See the April 2007 TechNet article for the Vista/XP issue as
well as a similar issue between Windows 3.11 and Win95.)

Mike Ober.
 
I agree, changing a class in the Framework in a way that will effect all
other applications that use the framework is a bad idea. But replacing the
class with an effect range of a single application, which is my application,
would be quite useful.

As I mentioned before, Java guys say that, in Java you can do that by
placing the new implementation of the class in your code. The class is
replaced only in your application. Other applications are not affected.

Now I am convinced that there is not a feature nor a workaround to achieve
this behaviour, but I still believe it would be cool to have it.

Emre
 
hi,
why don't you inherit from DataSet and whenever you get a DataSet from a
third-party class, you can just call a custom constructor that accepts a
DataSet to build your custom one... here's an example because I'm not sure
if my explanation is clear :

you have the following:

public class MyDataSet : DataSet
{
public MyDataSet(DataSet otherDataSet)
{
// Some code
}
}

then in your code somewhere :

MyDataSet mds = new MyDataSet(ThirdPartyClass.GetDataSet());

I hope it helps

ThunderMusic
 
Back
Top