Пример #1
0
        internal PRemoteComponent(object wrapped)
        {
            this.wrapped = wrapped ?? throw new ArgumentNullException(nameof(wrapped));
            if (!PPatchTools.TryGetPropertyValue(wrapped, nameof(Version), out Version
                                                 version))
            {
                throw new ArgumentException("Remote component missing Version property");
            }
            this.version = version;
            // Initialize
            var type = wrapped.GetType();

            doInitialize = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent.
                                                                           Initialize), wrapped, typeof(Harmony));
            if (doInitialize == null)
            {
                throw new ArgumentException("Remote component missing Initialize");
            }
            // Bootstrap
            doBootstrap = type.CreateDelegate <InitializeDelegate>(nameof(PForwardedComponent.
                                                                          Bootstrap), wrapped, typeof(Harmony));
            doPostInitialize = type.CreateDelegate <InitializeDelegate>(nameof(
                                                                            PForwardedComponent.PostInitialize), wrapped, typeof(Harmony));
            getData = type.CreateGetDelegate <object>(nameof(InstanceData), wrapped);
            setData = type.CreateSetDelegate <object>(nameof(InstanceData), wrapped);
            process = type.CreateDelegate <ProcessDelegate>(nameof(PForwardedComponent.
                                                                   Process), wrapped, typeof(uint), typeof(object));
        }
Пример #2
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");
            }
        }