Пример #1
0
        /// <summary>
        /// Lookup a type by type name and assembly name. It will look for <see cref="SerializationNameAttribute"/> that match the arguments.
        /// </summary>
        /// <param name="typeName">Name of the type.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <returns>A type or null.</returns>
        public static Type GetType(string typeName, string assemblyName)
        {
            Type result;
            var  sn = new SerializationNameAttribute(typeName, assemblyName);

            lock (sReplacementTypes)
                if (sReplacementTypes.TryGetValue(sn, out result))
                {
                    return(result);
                }

            if (assemblyName == null)
            {
                return(Type.GetType(typeName));
            }

            var t = Type.GetType($"{typeName},{assemblyName}");

            if (t != null)
            {
                return(t);
            }

            return(KnownAssemblies.GetType(typeName, assemblyName));
        }
Пример #2
0
        public static RuntimeType GetType(string name, string assembly)
        {
            lock (locker)
            {
                var sn = new SerializationNameAttribute(name, assembly);
                if (typeAliases.TryGetValue(sn, out var type))
                {
                    return(GetType(type));
                }

                type = KnownAssemblies.GetType(name, assembly);
                if (type != null)
                {
                    return(GetType(type));
                }

                return(null);
            }
        }