コード例 #1
0
 /// <inheritdoc/>
 ITransformationMap <TCollection, TElement> ITransformationMap <TCollection, TElement> .Link(
     string relation,
     Func <TCollection, ILinkData?> selector)
 {
     Links[relation] = new LinkInstruction <TCollection>(selector);
     return(this);
 }
コード例 #2
0
            /// <inheritdoc/>
            ITransformationMap <T> ITransformationMap <T> .Embed <TMember>(
                string relation,
                Expression <Func <T, TMember> > memberSelector,
                Func <T, TMember, ILinkData> linkSelector)
            {
                if (memberSelector is null)
                {
                    throw new ArgumentNullException(nameof(memberSelector));
                }
                if (relation is null)
                {
                    throw new ArgumentNullException(nameof(relation));
                }
                if (linkSelector is null)
                {
                    throw new ArgumentNullException(nameof(linkSelector));
                }

                switch (memberSelector.Body)
                { // todo(cosborn) Allow indexing, in the case of collections and dictionaries?
                case MemberExpression me:
                    var valueSelector = memberSelector.Compile();
                    Links[relation] = new LinkInstruction <T>(t => linkSelector(t, valueSelector(t)));
                    Embeds.Add(new MemberEmbedInstruction <T, TMember>(relation, me.Member.Name, valueSelector));
                    return(this);

                default:
                    throw new ArgumentException(MalformedValueSelector);
                }
            }
コード例 #3
0
            /// <inheritdoc/>
            ITransformationMap <T> ITransformationMap <T> .Embed <TMember>(
                string relation,
                Expression <Func <T, TMember> > memberSelector,
                Func <T, ILinkData> linkSelector)
            {
                if (memberSelector is null)
                {
                    throw new ArgumentNullException(nameof(memberSelector));
                }
                if (relation is null)
                {
                    throw new ArgumentNullException(nameof(relation));
                }
                if (linkSelector is null)
                {
                    throw new ArgumentNullException(nameof(linkSelector));
                }

                switch (memberSelector.Body)
                {
                case MemberExpression me:
                    var valueSelector = memberSelector.Compile();
                    Links[relation] = new LinkInstruction <T>(linkSelector);
                    Embeds.Add(new MemberEmbedInstruction <T, TMember>(relation, me.Member.Name, valueSelector));
                    return(this);

                default:
                    throw new ArgumentException(MalformedValueSelector);
                }
            }
コード例 #4
0
            /// <summary>Initializes a new instance of the <see cref="Builder{T}"/> class.</summary>
            /// <param name="self">
            /// A function that creates an <see cref="ILinkData"/>
            /// from a value of type <typeparamref name="T"/>.
            /// </param>
            /// <exception cref="ArgumentNullException"><paramref name="self"/> is <see langword="null"/>.</exception>
            public Builder([NotNull] Func <T, ILinkData> self)
            {
                if (self is null)
                {
                    throw new ArgumentNullException(nameof(self));
                }

                Links[Self] = new LinkInstruction <T>(self);
            }
コード例 #5
0
            /* todo(cosborn)
             * Should expressions allow indexing, in the case of collections and dictionaries?
             */

            #region Link

            /// <inheritdoc/>
            ITransformationMap <T> ITransformationMap <T> .Link(
                string relation,
                Func <T, ILinkData> selector)
            {
                if (relation is null)
                {
                    throw new ArgumentNullException(nameof(relation));
                }
                if (selector is null)
                {
                    throw new ArgumentNullException(nameof(selector));
                }

                Links[relation] = new LinkInstruction <T>(selector);
                return(this);
            }
コード例 #6
0
            /// <inheritdoc/>
            ITransformationMap <TCollection, TElement> ITransformationMap <TCollection, TElement> .Embed <TMember>(
                string relation,
                Expression <Func <TCollection, TMember> > memberSelector,
                Func <TCollection, ILinkData?> linkSelector)
            {
                switch (memberSelector.Body)
                {
                case MemberExpression me:
                    var valueSelector = memberSelector.Compile();
                    Links[relation] = new LinkInstruction <TCollection>(linkSelector);
                    Embeds.Add(new MemberEmbedInstruction <TCollection, TMember>(relation, me.Member.Name, valueSelector));
                    return(this);

                default:
                    throw new ArgumentException(MalformedValueSelector);
                }
            }
コード例 #7
0
 /// <summary>Initializes a new instance of the <see cref="Builder{T}"/> class.</summary>
 /// <param name="self">
 /// A function that creates an <see cref="ILinkData"/>
 /// from a value of type <typeparamref name="T"/>.
 /// </param>
 public Builder(Func <T, ILinkData?> self)
 {
     Links[Self] = new LinkInstruction <T>(self);
 }