Exemple #1
0
        public static bool IsTypeAwaitable(Type type, out CoercedAwaitableInfo info)
        {
            if (AwaitableInfo.IsTypeAwaitable(type, out var directlyAwaitableInfo))
            {
                info = new CoercedAwaitableInfo(directlyAwaitableInfo);
                return(true);
            }

            info = default(CoercedAwaitableInfo);
            return(false);
        }
Exemple #2
0
        public NonEscapedString MethodEscaped(MethodInfo method)
        {
            var    @public = WrapKeyword("public");
            var    async   = string.Empty;
            string @return;

            var isAwaitable = CoercedAwaitableInfo.IsTypeAwaitable(method.ReturnType, out var coercedAwaitableInfo);

            if (isAwaitable)
            {
                async = WrapKeyword("async");
                var asyncResultType = coercedAwaitableInfo.AwaitableInfo.ResultType;

                @return = WrapType("Task") + WrapIdentifier("<") + WrapType(asyncResultType) + WrapIdentifier(">");
            }
            else
            {
                @return = WrapType(method.ReturnType);
            }

            var name = method.Name;

            string paramType = null;
            string paramName = null;

            var @params = method.GetParameters();

            if (@params.Length == 1)
            {
                var firstParam     = @params[0];
                var firstParamType = firstParam.ParameterType;
                paramType = WrapType(firstParamType);
                paramName = firstParam.Name;
            }

            var paramString = paramType == null ? "();" : $"({paramType} {paramName});";

            var outputString = @public + " " + (string.IsNullOrEmpty(async) ? "" : async + " ") + @return + " " + name +
                               paramString;

            return(new NonEscapedString(outputString));
        }