473,387 Members | 1,464 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.

Is it possible to alias a sealed class in C#?

Good morning, afternoon or night to all,

I have developed a small library of generics whose two classes, ReadOnlyDictionary<TKey, TValue> and InvertibleReadOnlyDictionary<TKey, TValue>, are wrappers around an also generic dictionary. Now, being developing another library, I would like to define a new, non-generic class, called for example DigitMapping, of type InvertibleReadOnlyDictionary<char, int>. At first I thought about using inheritance and define it simply as DigitMapping : InvertibleReadOnlyDictionary<char, int> with a custom constructor. The problem is that I marked this last class as sealed and I don't want to mark it as not being sealed. I also don't want to do another wrapper around this class for performance reasons. Do you have any ideia as to how can I accomplish this?

Of course, I want this alias to be public, not just use it like that in my code (which would be easy with the 'using' keyword).

Thank you very much.
Apr 22 '11 #1
1 2185
hype261
207 100+
I just read that you didn't want to do another Wrapper for performance reasons so I don't think the method I list below would work. Sorry.

I believe the Decorator design pattern solves this problem. The Decorator design pattern has two purposes: To dynamically add responsibilities to an object and to add client specified embellishment of a core object by recursively wrapping it.

So instead of ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. class DigitMapping : InvertibleReadOnlyDictionary
  3. {
  4. };
  5.  
  6. it would be
  7.  
  8. class DigitMapping
  9. {
  10.  
  11. ..Same interface as InvertibleReadOnlyDictionary...
  12.  
  13. private InvertibleReadOnlyDictionary<char, int> dictionary;
  14. };
  15.  
  16.  
The methods and parameters of DigitMapping would just pass the calls to the methods of InvertibleReadOnlyDictionary. Traditionaly InvertibleReadOnlyDictionary and DigitMapping would both be derived from the same Interface, but nothing is saying you have to do that.
Apr 22 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ogled | last post by:
Hi I have a scheduler functionality that is implemented in public sealed class with static methods, and now i'd like to utilize it in a window service and have an exe file to access the...
5
by: Buddy Ackerman | last post by:
I have taken over an application that has a sealed (singleton) class for database access. I want to add a private SQLConnection class variable and open the connection it whenever it is instantiated...
5
by: ahaupt | last post by:
Hi all, Do you know if it is possible to hide class methods when the class has not been "properly" instantiated? Say in the following example, I'd like to hide or disable Drive() when the...
1
by: NetronProject | last post by:
My sealed class defines the necessary deserialization constructor: protected SomeMethod(SerializationInfo info, StreamingContext context){..} which generates the well-known warning "new...
3
by: Gugale at Lincoln | last post by:
I am using a function to get properies and property values of an object private string ObjPropVals(Object o) { Type t = o.GetType(); PropertyInfo pia = t.GetProperties(); string stra = new...
8
by: shawnz | last post by:
Is there any way to either derive a sealed class, or access private members of a sealed class? Either that, or is there a way to run internal methods in a sealed class outside the current assembly?...
0
by: Ken Varn | last post by:
I have the following code that I cannot get to compile. I get the error "A Sealed class cannot be abstract." public __value struct DVRAVIFileHeader : public ISerializable { double EventID;...
3
by: archana | last post by:
Hi all, I have created one sealed class having one constant. Can i access that constant of sealed class without creating object of that class. If yes will internally new object gets created....
5
by: D_a_n_i_e_l | last post by:
Is it possible to split a class definition over two files? Thanks.
2
by: puzzlecracker | last post by:
I see the "Warning new protected member declared in sealed class", and I understand that it makes no sense to have. I wonder why it's not prohibited altogether.
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
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...
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...
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,...

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.