コード例 #1
0
        private JsExpression GetScriptType(IType type, TypeContext context, Func <ITypeParameter, JsExpression> resolveTypeParameter)
        {
            string contextName = GetTypeContextShortName(context);

            if (type is ParameterizedType)
            {
                var pt = (ParameterizedType)type;
                return(JsExpression.Invocation(JsExpression.Identifier(contextName + "_$InstantiateGenericType"), new[] { new JsTypeReferenceExpression(Common.CreateMockTypeDefinition(type.Name, Common.CreateMockAssembly())) }.Concat(pt.TypeArguments.Select(a => GetScriptType(a, TypeContext.GenericArgument, resolveTypeParameter)))));
            }
            else if (type.TypeParameterCount > 0)
            {
                // This handles open generic types ( typeof(C<,>) )
                return(new JsTypeReferenceExpression(Common.CreateMockTypeDefinition(contextName + "_" + type.GetDefinition().Name, Common.CreateMockAssembly())));
            }
            else if (type.Kind == TypeKind.Array)
            {
                return(JsExpression.Invocation(JsExpression.Identifier(contextName + "_$Array"), GetScriptType(((ArrayType)type).ElementType, TypeContext.GenericArgument, resolveTypeParameter)));
            }
            else if (type.Kind == TypeKind.Anonymous)
            {
                return(JsExpression.Identifier(contextName + "_$Anonymous"));
            }
            else if (type is ITypeDefinition)
            {
                return(new JsTypeReferenceExpression(Common.CreateMockTypeDefinition(contextName + "_" + type.Name, Common.CreateMockAssembly())));
            }
            else if (type is ITypeParameter)
            {
                return(resolveTypeParameter((ITypeParameter)type));
            }
            else
            {
                throw new ArgumentException("Unsupported type + " + type);
            }
        }