Exemplo n.º 1
0
        //
        // One time initialization to supply the information needed to initialize the default domain and the  
        // the execution environment.
        //
        // Remarks:
        //   This design intentionally restricts you to one ExecutionEnvironment per side-by-side runtime in a process.
        //   Aside from the dubious value of allowing multiple executionEnvironments, there is no good way to
        //   for this scenario:
        //
        //            typeof(Foo).GetTypeInfo()
        //
        //   to "lookup" a domain in order to map the RuntimeTypeHandle to a specific ExecutionEnvironment.
        //
        public static void InitializeExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
        {
            ExecutionDomain executionDomain = new ExecutionDomain(executionDomainSetup, executionEnvironment);
            //@todo: This check has a race window but since this is a private api targeted by the toolchain, perhaps this is not so critical.
            if (_executionDomain != null)
                throw new InvalidOperationException(); // Multiple Initializes not allowed.
            _executionDomain = executionDomain;

            ReflectionCoreCallbacks reflectionCallbacks = new ReflectionCoreCallbacksImplementation();
            ReflectionAugments.Initialize(reflectionCallbacks);
            return;
        }
Exemplo n.º 2
0
        private static void CheckIsAssignableFrom(ExecutionEnvironment executionEnvironment, Type dstType, Type srcType)
        {
            // byref types do not have a TypeHandle so we must treat these separately.
            if (dstType.IsByRef && srcType.IsByRef)
            {
                if (!dstType.Equals(srcType))
                    throw new ArgumentException(SR.Arg_DlgtTargMeth);
            }

            // Enable pointers (which don't necessarily have typehandles). todo:be able to handle intptr <-> pointer, check if we need to handle
            // casts via pointer where the pointer types aren't identical
            if (dstType.Equals(srcType))
            {
                return;
            }

            // If assignment compatible in the normal way, allow
            if (executionEnvironment.IsAssignableFrom(dstType.TypeHandle, srcType.TypeHandle))
            {
                return;
            }

            // they are not compatible yet enums can go into each other if their underlying element type is the same
            // or into their equivalent integral type
            Type dstTypeUnderlying = dstType;
            if (dstType.GetTypeInfo().IsEnum)
            {
                dstTypeUnderlying = Enum.GetUnderlyingType(dstType);
            }
            Type srcTypeUnderlying = srcType;
            if (srcType.GetTypeInfo().IsEnum)
            {
                srcTypeUnderlying = Enum.GetUnderlyingType(srcType);
            }
            if (dstTypeUnderlying.Equals(srcTypeUnderlying))
            {
                return;
            }

            throw new ArgumentException(SR.Arg_DlgtTargMeth);
        }
Exemplo n.º 3
0
 internal ExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
 {
     ExecutionEnvironment = executionEnvironment;
     ReflectionDomainSetup = executionDomainSetup;
 }
Exemplo n.º 4
0
 internal ExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
     : base(executionDomainSetup, 0)
 {
     this.ExecutionEnvironment = executionEnvironment;
 }
Exemplo n.º 5
0
 internal ExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
 {
     ExecutionEnvironment  = executionEnvironment;
     ReflectionDomainSetup = executionDomainSetup;
 }
Exemplo n.º 6
0
 internal ExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
     : base(executionDomainSetup, 0)
 {
     this.ExecutionEnvironment = executionEnvironment;
 }
        //
        // One time initialization to supply the information needed to initialize the default domain and the
        // the execution environment.
        //
        // Remarks:
        //   This design intentionally restricts you to one ExecutionEnvironment per side-by-side runtime in a process.
        //   Aside from the dubious value of allowing multiple executionEnvironments, there is no good way to
        //   for this scenario:
        //
        //            typeof(Foo).GetTypeInfo()
        //
        //   to "lookup" a domain in order to map the RuntimeTypeHandle to a specific ExecutionEnvironment.
        //
        public static void InitializeExecutionDomain(ReflectionDomainSetup executionDomainSetup, ExecutionEnvironment executionEnvironment)
        {
            ExecutionDomain executionDomain = new ExecutionDomain(executionDomainSetup, executionEnvironment);

            //@todo: This check has a race window but since this is a private api targeted by the toolchain, perhaps this is not so critical.
            if (_executionDomain != null)
            {
                throw new InvalidOperationException(); // Multiple Initializes not allowed.
            }
            _executionDomain = executionDomain;

            ReflectionCoreCallbacks reflectionCallbacks = new ReflectionCoreCallbacksImplementation();

            ReflectionAugments.Initialize(reflectionCallbacks);
            return;
        }