Exemple #1
0
        /// <summary>
        /// Used to manually specify a networking implementation provider in case
        /// either zero or more than one class is marked with [AutoInstall].
        /// </summary>
        public static void Install <TProvider>()
            where TProvider : NetProvider, new()
        {
            if (_sProvider != null)
            {
                throw new InvalidOperationException("Networking driver already installed.");
            }

            _sProvider = new TProvider();
        }
Exemple #2
0
        /// <remarks>
        /// Searches for a provider marked with [AutoInstall]. Aborts if more
        /// than one is found.
        /// </remarks>
        static NetProvider()
        {
            ConstructorInfo found = null;

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.IsAbstract)
                {
                    continue;
                }
                if (!type.HasAttribute <AutoInstallAttribute>(false))
                {
                    continue;
                }

                var ctor = type.GetConstructor(new Type[0]);
                if (ctor == null)
                {
                    continue;
                }

                // Abort if more than one is found
                if (found != null)
                {
                    return;
                }

                found = ctor;
            }

            if (found == null)
            {
                return;
            }

            _sProvider = (NetProvider)found.Invoke(new object[0]);
        }