Пример #1
0
        internal static bool InAsyncMethod(Expression value)
        {
            INodeWithBody ancestor = value.GetAncestor <BlockExpression>();

            if (ancestor == null)
            {
                ancestor = value.GetAncestor <Method>();
            }
            return(ContextAnnotations.IsAsync(ancestor));
        }
Пример #2
0
        public static bool TryCreate(TypeSystemServices tss, Method method, IType genericArg,
                                     out AsyncMethodBuilderMemberCollection collection)
        {
            if (ContextAnnotations.IsAsync(method))
            {
                var returnType = (IType)method.ReturnType.Entity;
                if (returnType == tss.VoidType)
                {
                    return(TryCreateVoid(tss, out collection));
                }
                if (returnType == tss.TaskType)
                {
                    return(TryCreateTask(tss, out collection));
                }
                if (returnType.ConstructedInfo != null &&
                    returnType.ConstructedInfo.GenericDefinition == tss.GenericTaskType)
                {
                    return(TryCreateGenericTask(tss, genericArg, out collection));
                }
            }

            throw CompilerErrorFactory.InvalidAsyncType(method.ReturnType);
        }