コード例 #1
0
        public async static Task <bool> TryMergeAsync <TSource, TTarget>(this JObject jObject, Mapping <TSource[], IList <TTarget> > mapping, Func <TSource, TTarget, Task> asyncMerge)
            where TTarget : class, new()
        {
            var token = jObject[mapping.Field];

            if (token == null)
            {
                return(false);
            }

            var sources = token.Values <TSource>().ToArray();

            mapping[sources] = await Task.WhenAll(
                sources
                .Select(async s =>
            {
                var t = new TTarget();
                await asyncMerge(s, t);
                return(t);
            }));

            return(true);
        }
コード例 #2
0
 static JTask Optional <TSource, TTarget>(this JTask jTask, Mapping <TSource, TTarget> mapping, Func <TSource, TTarget> conversion)
 {
     jTask.TryConvert(mapping, conversion);
     return(jTask);
 }
コード例 #3
0
        public async static Task <bool> TryMergeAsync <TSource, TTarget>(this JObject jObject, Mapping <TSource, TTarget> mapping, Func <TSource, TTarget, Task> asyncMerge)
            where TTarget : class
        {
            var token = jObject[mapping.Field];

            if (token == null)
            {
                return(false);
            }

            var source = token.Value <TSource>();
            var target = mapping[source];

            if (target == null)
            {
                target = mapping[token.Value <TSource>()] = Activator.CreateInstance <TTarget>();
            }

            await asyncMerge(source, target);

            return(true);
        }
コード例 #4
0
        //public static JTask Optional<T>(this JTask jTask, Expression<Func<JObject[], IList<T>>> mapping, Action<JObject, T> merge)
        //    where T : class, new() =>
        //    jTask.Optional<JObject, T>(mapping, merge);

        static JTask Optional <TSource, TTarget>(this JTask jTask, Mapping <TSource[], IList <TTarget> > mapping, Action <TSource, TTarget> merge)
            where TTarget : class, new()
        {
            jTask.TryMerge(mapping, merge);
            return(jTask);
        }
コード例 #5
0
        public static async Task <bool> TryConvertAsync <TSource, TTarget>(this JObject jObject, Mapping <TSource[], IList <TTarget> > mapping, Func <TSource, Task <TTarget> > asyncConversion)
        {
            var token = jObject[mapping.Field];

            if (token == null)
            {
                return(false);
            }

            mapping[token.Values <TSource>().ToArray()] = await Task.WhenAll(
                token.Values <TSource>()
                .Select(v => asyncConversion(v)));

            return(true);
        }
コード例 #6
0
        public static async Task <bool> TryConvertAsync <TSource, TTarget>(this JObject jObject, Mapping <TSource, TTarget> mapping, Func <TSource, Task <TTarget> > asyncConversion)
        {
            var token = jObject[mapping.Field];

            if (token == null)
            {
                return(false);
            }

            mapping[token.Value <TSource>()] = await asyncConversion(token.Value <TSource>());

            return(true);
        }
コード例 #7
0
ファイル: OptionalArrayCoercions.cs プロジェクト: he-dev/JMap
 static JTask Optional <TSource, TTarget>(this JTask jTask, Mapping <TSource[], IList <TTarget> > mapping)
 {
     jTask.TryCoerce(mapping);
     return(jTask);
 }