mercredi 26 septembre 2018

How to assign abstract object to Reflection.Emit derived one

Hello i am facing the following problem:

I have an abstract class which has to be somehow initialized before i can call one of its async methods in which its fields are assigned:

class Dependency {}

abstract class Relay : Abs.Api.IAll {

        private Dependency dep;

        public static async Task<Relay> RunAsync(Dependency _dep) {
            Relay daemon = // [ Reflection.Emit derived object]
            await daemon.InternalConnectAsync(port);
            return daemon;
        }
        private async Task InternalConnectAsync(Dependency _dep) {
            //async code//
            this.dep=_dep;
        }
    }
class AutoGeneratedRelay : Relay {
}

As you can see the Dependency object dep is initialized after i have a concrete object derived from Relay.
The problem is that this object daemon will be assigned to a derived object obtained via Reflection.Emit ,in our case AutoGeneratedRelay.I am creating a derived class with reflection and i want to fetch it and assign the base object daemon.

Aucun commentaire:

Enregistrer un commentaire