コード例 #1
0
ファイル: TypeResolver.cs プロジェクト: deboe2015/Ctrip.SOA
        /// <summary>
        /// Resolves the supplied generic <paramref name="typeName"/>,
        /// substituting recursively all its type parameters., 
        /// to a <see cref="System.Type"/> instance.
        /// </summary>
        /// <param name="typeName">
        /// The (possibly generic) name of a <see cref="System.Type"/>.
        /// </param>
        /// <returns>
        /// A resolved <see cref="System.Type"/> instance.
        /// </returns>
        /// <exception cref="System.TypeLoadException">
        /// If the supplied <paramref name="typeName"/> could not be resolved
        /// to a <see cref="System.Type"/>.
        /// </exception>
        private Type ResolveGenericType(string typeName)
        {
			Guard.ArgumentNotNullOrEmpty("typeName", typeName);

            if (typeName.StartsWith(NULLABLE_TYPE))
            {
                return null;
            }
            else
            {
                GenericArgumentsInfo genericInfo = new GenericArgumentsInfo(typeName);
                Type type = null;
                try
                {
                    if (genericInfo.ContainsGenericArguments)
                    {
						type = TypeHelper.ResolveType(genericInfo.GenericTypeName);
                        if (!genericInfo.IsGenericDefinition)
                        {
                            string[] unresolvedGenericArgs = genericInfo.GetGenericArguments();
                            Type[] genericArgs = new Type[unresolvedGenericArgs.Length];
                            for (int i = 0; i < unresolvedGenericArgs.Length; i++)
                            {
								genericArgs[i] = TypeHelper.ResolveType(unresolvedGenericArgs[i]);
                            }
                            type = type.MakeGenericType(genericArgs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex is TypeLoadException)
                    {
                        throw;
                    }

					ThrowHelper.ThrowTypeLoadExcetpion(ex, "类型加载失败", typeName);
                }

                return type;
            }
        }
コード例 #2
0
        /// <summary>
        /// Resolves the supplied generic <paramref name="typeName"/>,
        /// substituting recursively all its type parameters.,
        /// to a <see cref="System.Type"/> instance.
        /// </summary>
        /// <param name="typeName">
        /// The (possibly generic) name of a <see cref="System.Type"/>.
        /// </param>
        /// <returns>
        /// A resolved <see cref="System.Type"/> instance.
        /// </returns>
        /// <exception cref="System.TypeLoadException">
        /// If the supplied <paramref name="typeName"/> could not be resolved
        /// to a <see cref="System.Type"/>.
        /// </exception>
        private Type ResolveGenericType(string typeName)
        {
            Guard.ArgumentNotNullOrEmpty("typeName", typeName);

            if (typeName.StartsWith(NULLABLE_TYPE))
            {
                return(null);
            }
            else
            {
                GenericArgumentsInfo genericInfo = new GenericArgumentsInfo(typeName);
                Type type = null;
                try
                {
                    if (genericInfo.ContainsGenericArguments)
                    {
                        type = TypeHelper.ResolveType(genericInfo.GenericTypeName);
                        if (!genericInfo.IsGenericDefinition)
                        {
                            string[] unresolvedGenericArgs = genericInfo.GetGenericArguments();
                            Type[]   genericArgs           = new Type[unresolvedGenericArgs.Length];
                            for (int i = 0; i < unresolvedGenericArgs.Length; i++)
                            {
                                genericArgs[i] = TypeHelper.ResolveType(unresolvedGenericArgs[i]);
                            }
                            type = type.MakeGenericType(genericArgs);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex is TypeLoadException)
                    {
                        throw;
                    }

                    ThrowHelper.ThrowTypeLoadExcetpion(ex, "类型加载失败", typeName);
                }

                return(type);
            }
        }