Why so many class in framework sealed?
-
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed. How can i do with it? Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
-
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed. How can i do with it? Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
I had the same problem with SqlDataReader. I just created a new class that wrapped each SqlDataReader method and property and then inherited from my class. It kind of sucks but I don't think there is any other way.
-
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed. How can i do with it? Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
Yes it stinks. The reason for Bitmap being sealed is because it is a wrapper around GDI+ which is a native DLL. .NET doesn't support inheritence from a native image, yet anyway :rolleyes: James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971
-
I had the same problem with SqlDataReader. I just created a new class that wrapped each SqlDataReader method and property and then inherited from my class. It kind of sucks but I don't think there is any other way.
Well, the wrapper is boring but i fininally made it. I think if Microsoft holds its position on sealing their class, then it will be a good idea to design a wizard to automatively build a wrapper. Hope C#'s reflection ability will make it possible. Do you think so?
-
I wanna expand the ability of some class provided by framework like Bitmap, but I find it modified by sealed. How can i do with it? Another similar problem is when i try to inherit XmlElement, I find its construction is modified by internal. Then the compiler find it as an error. any solution to bypass?
I can't speak for them all... but some are sealed for performance reasons. and I quote from "Applied Microsoft .NET Framework Programming": " the CLR knows the exact layout of the fields defined within the String type, and the CLR accesses these feilds directly." ... If String were not sealed, "you could add your own fields, which would break the assumptions the CLR makes, In addition, you could break some assumptions that the CLR has made about String objects being immutable."
-
I can't speak for them all... but some are sealed for performance reasons. and I quote from "Applied Microsoft .NET Framework Programming": " the CLR knows the exact layout of the fields defined within the String type, and the CLR accesses these feilds directly." ... If String were not sealed, "you could add your own fields, which would break the assumptions the CLR makes, In addition, you could break some assumptions that the CLR has made about String objects being immutable."
Andy Smith wrote: and I quote from "Applied Microsoft .NET Framework Programming": " the CLR knows the exact layout Here is Mircosoft "knowing" everything again... Nick Parker