Beispiel #1
0
        /// <summary>
        /// Eager initialization of runtime reflection support. As part of ExecutionEnvironmentImplementation
        /// initialization it enumerates the modules and registers the ones containing EmbeddedMetadata reflection blobs
        /// in its _moduleToMetadataReader map.
        /// </summary>
        internal static void Initialize()
        {
            // Initialize Reflection.Core's one and only ExecutionDomain.
            ExecutionEnvironmentImplementation  executionEnvironment = new ExecutionEnvironmentImplementation();
            ReflectionDomainSetupImplementation setup = new ReflectionDomainSetupImplementation(executionEnvironment);

            ReflectionCoreExecution.InitializeExecutionDomain(setup, executionEnvironment);

            // Initialize our two communication with System.Private.CoreLib.
            ExecutionDomain executionDomain = ReflectionCoreExecution.ExecutionDomain;
            ReflectionExecutionDomainCallbacksImplementation runtimeCallbacks = new ReflectionExecutionDomainCallbacksImplementation(executionDomain, executionEnvironment);

            RuntimeAugments.Initialize(runtimeCallbacks);

            DefaultAssemblyNamesForGetType =
                new String[]
            {
                AssemblyBinder.DefaultAssemblyNameForGetType,
            };

            ExecutionEnvironment = executionEnvironment;

#if SUPPORT_JIT
            Internal.Runtime.TypeLoader.MethodExecutionStrategy.GlobalExecutionStrategy = new Internal.Runtime.JitSupport.RyuJitExecutionStrategy();
#endif
        }
Beispiel #2
0
        /// <summary>
        /// This eager constructor initializes runtime reflection support. As part of ExecutionEnvironmentImplementation
        /// initialization it enumerates the modules and registers the ones containing EmbeddedMetadata reflection blobs
        /// in its _moduleToMetadataReader map.
        /// </summary>
        static ReflectionExecution()
        {
            // Initialize Reflection.Core's one and only ExecutionDomain.
            ExecutionEnvironmentImplementation  executionEnvironment = new ExecutionEnvironmentImplementation();
            ReflectionDomainSetupImplementation setup = new ReflectionDomainSetupImplementation(executionEnvironment);

            ReflectionCoreExecution.InitializeExecutionDomain(setup, executionEnvironment);

            // Initialize our two communication with System.Private.CoreLib.
            ExecutionDomain executionDomain = ReflectionCoreExecution.ExecutionDomain;
            ReflectionExecutionDomainCallbacksImplementation runtimeCallbacks = new ReflectionExecutionDomainCallbacksImplementation(executionDomain, executionEnvironment);

            RuntimeAugments.Initialize(runtimeCallbacks);

#if !CORERT
            ReflectionTracingInitializer.Initialize();
#endif

            DefaultAssemblyNamesForGetType =
                new String[]
            {
                DefaultAssemblyNameForGetType,
            };

            ExecutionEnvironment = executionEnvironment;
            setup.InstallModuleRegistrationCallbacks();
        }
Beispiel #3
0
 public IObservable <T> Wrap <T>(IObservable <T> input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(input
            // TODO: To the actual wrapping with errorhandling and starting/stoping timers
            //.Catch(err => {  })
            );
 }
Beispiel #4
0
 public IObservable <bool> Wrap(Action input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(Wrap(Observable.Create <bool>((observer) => {
         input();
         observer.OnNext(true);
         observer.OnCompleted();
         return null;
     })));
 }
Beispiel #5
0
 public IObservable <T> Wrap <T>(Func <T> input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(Wrap(Observable.Create <T>((observer) => {
         T result = input();
         observer.OnNext(result);
         observer.OnCompleted();
         return null;
     })));
 }
        public sealed override Stream GetManifestResourceStream(String name)
        {
            ExecutionDomain executionDomain = this.ReflectionDomain as ExecutionDomain;

            if (executionDomain == null)
            {
                throw new PlatformNotSupportedException();
            }
            return(executionDomain.ExecutionEnvironment.GetManifestResourceStream(this, name));
        }
Beispiel #7
0
        /// <summary>
        /// Adds an action to the gamestate's queue list and will be executed on the next tick sorted by its priority(default:Priorities.PRIORITY_DEFAULT=512)
        /// and will be removed from the executionlist afterwards
        /// </summary>
        /// <param name="act"></param>
        /// <param name="priority"></param>
        /// <param name="exeType"></param>
        public void AddTick(Action act, int priority = Priorities.PRIORITY_DEFAULT, ExecutionDomain exeType = ExecutionDomain.unknown)
        {
            var envelope = new TickEnvelope()
            {
                action          = act,
                priority        = priority,
                executionDomain = exeType
            };

            OnTick.Add(envelope);
            isTickListDirty = true;
        }
Beispiel #8
0
        /// <summary>
        /// Eager initialization of runtime reflection support. As part of ExecutionEnvironmentImplementation
        /// initialization it enumerates the modules and registers the ones containing EmbeddedMetadata reflection blobs
        /// in its _moduleToMetadataReader map.
        /// </summary>
        internal static void Initialize()
        {
            // Initialize Reflection.Core's one and only ExecutionDomain.
            var executionEnvironment = new ExecutionEnvironmentImplementation();
            var setup = new ReflectionDomainSetupImplementation();

            ReflectionCoreExecution.InitializeExecutionDomain(setup, executionEnvironment);

            // Initialize our two-way communication with System.Private.CoreLib.
            ExecutionDomain executionDomain  = ReflectionCoreExecution.ExecutionDomain;
            var             runtimeCallbacks = new ReflectionExecutionDomainCallbacksImplementation(executionDomain, executionEnvironment);

            RuntimeAugments.Initialize(runtimeCallbacks);

            ExecutionEnvironment = executionEnvironment;
        }
Beispiel #9
0
 public Action Wrap(Action input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(() => {
         // TODO START TIMER
         try {
             input();
         }
         catch (Exception e) {
             UnityEngine.Debug.LogError("There was an catched exception:");
             UnityEngine.Debug.LogException(e);
         }
         finally {
             // TODO STOP TIMER
         }
     });
 }
Beispiel #10
0
 public Func <T> Wrap <T>(Func <T> input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(() => {
         // TODO START TIMER
         try {
             return input();
         }
         catch (Exception e) {
             UnityEngine.Debug.LogError("There was an catched exception:");
             UnityEngine.Debug.LogException(e);
             return default(T);
         }
         finally {
             // TODO STOP TIMER
         }
     });
 }
        /// <summary>
        /// Eager initialization of runtime reflection support. As part of ExecutionEnvironmentImplementation
        /// initialization it enumerates the modules and registers the ones containing EmbeddedMetadata reflection blobs
        /// in its _moduleToMetadataReader map.
        /// </summary>
        internal static void Initialize()
        {
            // Initialize Reflection.Core's one and only ExecutionDomain.
            ExecutionEnvironmentImplementation  executionEnvironment = new ExecutionEnvironmentImplementation();
            ReflectionDomainSetupImplementation setup = new ReflectionDomainSetupImplementation(executionEnvironment);

            ReflectionCoreExecution.InitializeExecutionDomain(setup, executionEnvironment);

            // Initialize our two communication with System.Private.CoreLib.
            ExecutionDomain executionDomain = ReflectionCoreExecution.ExecutionDomain;
            ReflectionExecutionDomainCallbacksImplementation runtimeCallbacks = new ReflectionExecutionDomainCallbacksImplementation(executionDomain, executionEnvironment);

            RuntimeAugments.Initialize(runtimeCallbacks);

            DefaultAssemblyNamesForGetType =
                new String[]
            {
                AssemblyBinder.DefaultAssemblyNameForGetType,
            };

            ExecutionEnvironment = executionEnvironment;
        }
 public ReflectionExecutionDomainCallbacksImplementation(ExecutionDomain executionDomain, ExecutionEnvironmentImplementation executionEnvironment)
 {
     _executionDomain      = executionDomain;
     _executionEnvironment = executionEnvironment;
 }
Beispiel #13
0
 public void WrapExe(Action input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     Wrap(input, executionType);
 }
Beispiel #14
0
 public T WrapExe <T>(Func <T> input, ExecutionDomain executionType = ExecutionDomain.unknown)
 {
     return(Wrap(input, executionType)());
 }
Beispiel #15
0
        /// <summary>
        /// Adds a function(returing bool) to the gamestate's queue list and will be executed on the next tick sorted by its priority(default:Priorities.PRIORITY_DEFAULT=512)
        /// as long as the function returns true the function stays in the execution-queue until it returns false
        /// </summary>
        /// <param name="func"></param>
        /// <param name="priority"></param>
        public void AddTick(Func <bool> func, int priority = Priorities.PRIORITY_DEFAULT, ExecutionDomain exeType = ExecutionDomain.unknown)
        {
            TickEnvelope envelope = new TickEnvelope()
            {
                func            = func,
                priority        = priority,
                executionDomain = exeType
            };

            OnTick.Add(envelope);
            isTickListDirty = true;
        }
Beispiel #16
0
        //
        // Main routine to resolve a typeReference.
        //
        private static RuntimeType TryResolveTypeReference(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeReferenceHandle typeReferenceHandle, ref Exception exception)
        {
            {
                ExecutionDomain executionDomain = reflectionDomain as ExecutionDomain;
                if (executionDomain != null)
                {
                    RuntimeTypeHandle resolvedRuntimeTypeHandle;
                    if (executionDomain.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle))
                    {
                        return(ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(resolvedRuntimeTypeHandle));
                    }
                }
            }

            TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
            String        name          = typeReference.TypeName.GetString(reader);
            Handle        parent        = typeReference.ParentNamespaceOrType;
            HandleType    parentType    = parent.HandleType;
            TypeInfo      outerTypeInfo = null;

            // Check if this is a reference to a nested type.

            if (parentType == HandleType.TypeDefinition)
            {
                outerTypeInfo = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, parent.ToTypeDefinitionHandle(reader));
            }
            else if (parentType == HandleType.TypeReference)
            {
                RuntimeType outerType = reflectionDomain.TryResolveTypeReference(reader, parent.ToTypeReferenceHandle(reader), ref exception);
                if (outerType == null)
                {
                    return(null);
                }
                outerTypeInfo = outerType.GetTypeInfo();   // Since we got to outerType via a metadata reference, we're assured GetTypeInfo() won't throw a MissingMetadataException.
            }
            if (outerTypeInfo != null)
            {
                // It was a nested type. We've already resolved the containing type recursively - just find the nested among its direct children.
                TypeInfo resolvedTypeInfo = outerTypeInfo.GetDeclaredNestedType(name);
                if (resolvedTypeInfo == null)
                {
                    exception = reflectionDomain.CreateMissingMetadataException(outerTypeInfo, name);
                    return(null);
                }
                return((RuntimeType)(resolvedTypeInfo.AsType()));
            }


            // If we got here, the typeReference was to a non-nested type.
            if (parentType == HandleType.NamespaceReference)
            {
                AssemblyQualifiedTypeName assemblyQualifiedTypeName = parent.ToNamespaceReferenceHandle(reader).ToAssemblyQualifiedTypeName(name, reader);
                RuntimeType runtimeType;
                exception = assemblyQualifiedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out runtimeType);
                if (exception != null)
                {
                    return(null);
                }
                return(runtimeType);
            }

            throw new BadImageFormatException(); // Expected TypeReference parent to be typeRef, typeDef or namespaceRef.
        }