Note that there are some explanatory texts on larger screens.

plurals
  1. POInvoking a generic method that returns a collection of generics without knowing what the type is? C#
    primarykey
    data
    text
    <p>I'm just having a play around with writing an ORM-type project in C#.</p> <p>Basically, I have a class structure like this:</p> <p>IDBOperation --- DBReadOperation</p> <p>DBOperationPool</p> <p>Basically, a DBReadOperation maps data from the specified database table to a class in my solution, say for example PersonDetails.</p> <p>The code to do this was taken from an external source (can't quite remember?), and basically returns a generic collection (Collection).</p> <p>My DBOperationPool needs to be able to take any number of DBReadOperation's and return results for each of them. The logic for that I have down.. but can't seem to get the code to work?</p> <p>The mapping class also is built on generics.. so how can I instantiate the mapping class to be along the lines of..</p> <pre><code>MappingClass&lt;?&gt; mappingInstance = new MappingClass&lt;?&gt;(); Collection&lt;?&gt; returnedCollection = mappingInstance.MapData(argument); </code></pre> <p>How do I (using generics, or reflection, or anything) figure out what to put where the question marks are in the above? Can it be done? I've had a search around and nothing seems to be related to this exact problem..</p> <p>Obviously, the easy route is making the pool include the type I want to map towards.. but the whole point of the pool is that I can throw DBReadOperation's at it for, say, PersonDetails, CompanyDetails, etc, and have the data mapped to where it needs to be and return the results properly for each type. With this route, I can throw any number of DBReadOperations into a pool, as long as they deal with a specific type for each DBOperationPool instance.. but thats not what I want..</p> <p>Does this make sense at all?</p> <p>Regards,</p> <p>Simon</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload