Firstly, I think you meant to use ConcurrentDictionary since you have a key/value pair Secondly, you can do it similar to ICloneable. ICloneable has a method that returns an Object instead of a T private ConcurrentDictionary Cache { get; set; } Since it's private you can manage it internally and cast it as needed. Obviously you'll have to make sure any function calls have a typeparam definition, for example: I omitted error checking on all the examples.
Public class Foo : EntityBase { ... } void DoSomething() { var someClass = Cachetypeof(Foo) as ISomeInterface someClass.Bar(); } Also, even if the property had another modifier (public, internal, protected) you could add comments to callers that the Object is a generic type of ISomeInterface where T is a EntityBase, new(). Then, they simply have to cast however they need to You can also have generic methods on the non-generic class to get the cached item as a generic type: ISomeInterface GetInstance() where T : EntityBase, new() { return Cachetypeof(T) as ISomeInterface; } void AddInstance(ISomeInterface instance) where T : EntityBase, new() { Cachetypeof(T) = instance; } void DoSomething() { var someClass = GetInstance(); someClass.Bar(); }.
Firstly, I think you meant to use ConcurrentDictionary since you have a key/value pair. Secondly, you can do it similar to ICloneable. ICloneable has a method that returns an Object instead of a T.
Private ConcurrentDictionary Cache { get; set; } Since it's private you can manage it internally and cast it as needed. Obviously you'll have to make sure any function calls have a typeparam definition, for example: //I omitted error checking on all the examples. Public class Foo : EntityBase { ... } void DoSomething() { var someClass = Cachetypeof(Foo) as ISomeInterface someClass.Bar(); } Also, even if the property had another modifier (public, internal, protected) you could add comments to callers that the Object is a generic type of ISomeInterface where T is a EntityBase, new().
Then, they simply have to cast however they need to. You can also have generic methods on the non-generic class to get the cached item as a generic type: ISomeInterface GetInstance() where T : EntityBase, new() { return Cachetypeof(T) as ISomeInterface; } void AddInstance(ISomeInterface instance) where T : EntityBase, new() { Cachetypeof(T) = instance; } void DoSomething() { var someClass = GetInstance(); someClass.Bar(); }.
See this related question: Making a generic property If you don't want MyClass to be generic, you can use two generic methods instead: private ConcurrentCollection> GetCache() { ... } private void SetCache(ConcurrentCollection> cache) { ... }.
– svick Jul 18 at 20:46 I guess I didn't address the backing storage issue in my answer. :) – Matt Smith Jul 18 at 21:06.
I'm not sure what exactly do you want to use that collection for, but one way of doing something similar would be to create a nested generic static class that holds the values: class SomeInterfaceCollection { private static class Item { public static ISomeInterface Value; } public static ISomeInterface Get() { return Item. Value; } public static void Set(ISomeInterface value) { Item. Value = value; } }.
This only makes sense for a static property. – Ben Voigt Jul 18 at 20:56 @Ben, you're right, I have fixed the code. – svick Jul 18 at 21:03.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.