Class Limiting and Archetypes
<p>I'm trying to create a function in C# which will allow me to, when called, return a reference to a given class type.  The only types of functions like this that I have seen are in UnrealScript and even then the functionality is hard coded into its compiler.  I'm wondering if I can do this in C#.  Here's what I mean (code snippet from UnrealScript source):</p>

<pre><code>native(278) final function actor Spawn
(
    class&lt;actor&gt;      SpawnClass,
    optional actor   SpawnOwner,
    optional name     SpawnTag,
    optional vector   SpawnLocation,
    optional rotator  SpawnRotation
);
</code></pre>

<p>Now in UScript you would call it like this...</p>

<pre><code>local ActorChild myChildRef; //Ref to ActorChild which Extends 'actor'
myChildRef = Spawn(class'ActorChild' ...);  //rest of parameters taken out
myChildRef.ChildMethod();  //method call to method existing inside class 'ActorChild'
</code></pre>

<p>Which will return a reference to an object of class 'ActorChild' and set it to variable 'myChildRef.'  I need to do something similar within C#.</p>

<p>I've looked into Generics but it seems that to use them, I need create an instace of the class where my function lies and pass the 'generic' parameter to it.  This isn't very desirable however as I won't need to use the 'Spawn' function for certain classes but I would still need to add the generic parameter to the class whenever I use it.</p>

<p>I guess a simplified question would be, how can I return a type that I do not know at compile time and when the different classes could be far too many to trap.</p>

<p>Pseudo-Code (sticking to UScript class names, i.e. Actor):</p>

<pre><code>//Function Sig
public class&lt;Actor&gt; Create(class&lt;Actor&gt; CreatedClass)
{
    return new CreatedClass;
}

//Function call
ActorChild myChild = Create(class'ActorChild');
</code></pre>

<p>Any ideas?</p>

<p>EDIT: I would like to avoid explicit typecasts that would occur from the class calling Created.  If I can typecast to the desired object within the Created method and return the 'unknown type' whatever that may be, I would be extremely happy.</p>

<p>EDIT 2:  Thanks for your answers.</p>
