コード例 #1
0
        /// <summary>
        /// Creates a remote registry wrapping the target object.
        /// </summary>
        /// <param name="instance">The PRegistryComponent instance to wrap.</param>
        internal PRemoteRegistry(object instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
            remoteComponents = new Dictionary <string, PForwardedComponent>(32);
            if (!PPatchTools.TryGetPropertyValue(instance, nameof(ModData), out
                                                 IDictionary <string, object> modData))
            {
                throw new ArgumentException("Remote instance missing ModData");
            }
            ModData = modData;
            var type = instance.GetType();

            addCandidateVersion = type.CreateDelegate <Action <object> >(nameof(
                                                                             PRegistryComponent.DoAddCandidateVersion), instance, typeof(object));
            getAllComponents = type.CreateDelegate <GetAllComponentsDelegate>(nameof(
                                                                                  PRegistryComponent.DoGetAllComponents), instance, typeof(string));
            getLatestVersion = type.CreateDelegate <GetObjectDelegate>(nameof(
                                                                           PRegistryComponent.DoGetLatestVersion), instance, typeof(string));
            if (addCandidateVersion == null || getLatestVersion == null ||
                getAllComponents == null)
            {
                throw new ArgumentException("Remote instance missing candidate versions");
            }
            getSharedData = type.CreateDelegate <GetObjectDelegate>(nameof(IPLibRegistry.
                                                                           GetSharedData), instance, typeof(string));
            setSharedData = type.CreateDelegate <SetObjectDelegate>(nameof(IPLibRegistry.
                                                                           SetSharedData), instance, typeof(string), typeof(object));
            if (getSharedData == null || setSharedData == null)
            {
                throw new ArgumentException("Remote instance missing shared data");
            }
        }
コード例 #2
0
        static UnsafeObject()
        {
            var getAddressMethod = CreateDynamicMethod <object, IntPtr>(nameof(GetAddressFromIL));
            var getObjectMethod  = CreateDynamicMethod <IntPtr, object>(nameof(GetObjectFromIL));

            BuildIL(getAddressMethod);
            BuildIL(getObjectMethod);

            _getAddress = getAddressMethod.CreateDelegate(typeof(GetAddressDelegate)) as GetAddressDelegate;
            _getObject  = getObjectMethod.CreateDelegate(typeof(GetObjectDelegate)) as GetObjectDelegate;
        }