How do I reference a specific class type in C#? -


Is it possible to get a class / type reference / indicator and it is possible to get it from a particular base class?

I am writing a client library that requires conversation with the server to use an algorithm for use for communication. I want to be able to choose a subset of algorithms to use the library, I can not be fixed on the set which I initially provide (i.e. not set in any kind of factory category).

Ideally this will be done by passing a few general "algorithm" subtypes in a list of sections. I have seen the "type" object, but I have to check all the types of things, is there any way of doing this to the compiler for me? What do I want "type and algorithm"; But can not I get anything like that or is there a completely different way to do this?

An example of what I have thought so far:

  Public class algorithms {public static abstract name; } Public class client {public MyLib (type [] algorithm) {m_algorithms = algorithm; // ... get them from all algorithms ... public dialogue () {// ... Send list of algorithm names to the server ... ... create an example of algorithm by server response}}  

You can not unfortunately check that there are algorithms on all types of types. This is one of the Java (some) features that I miss about Java. However, doing some good work, which (depending on your situation) could be better than the solution you were expecting. For example:

  public class algorithm {} public class algorithm A: algorithm {} public class algorithm B: algorithm {} public interface IAlgorithmFactory {string name {get}} algorithm GetAlgorithm () ; } Public Class Algorithm Factory & lt; T & gt; : IAlgorithmFactory where T: algorithm, new () {public string name {get {return typeof (T) .name; }} Public Algorithm GetAlgorithm () {Return New T (); }} Public class client {public minus my Lib (IEnumerable & lt; IAlgorithmFactory & gt; algorithm) {// ... they all get from algorithms} Public Zero Dialog () {// ... server // Send list of algorithm names for. .. Create an example of algorithm set with server response}}  

Then you can use your customer class in this way:

  New Client ( ). MyLib (new IAlgorithmFactory [] (new algorithm factory & lt; algorithm A & gt; (), new algorithm factory & lt; algorithm b & gt; ()})  
< / Html>

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -