/// <summary>
        /// Translate a KeySegment
        /// </summary>
        /// <param name="segment">the segment to Translate</param>
        /// <returns>Defined by the implementer.</returns>
        public override string Translate(KeySegment segment)
        {
            Debug.Assert(segment != null, "segment != null");
            List <KeyValuePair <string, object> > keys = segment.Keys.ToList();

            StringBuilder builder = new StringBuilder();

            KeySerializer.AppendKeyExpression(builder, new Collection <KeyValuePair <string, object> >(keys), p => p.Key, p => p.Value);

            return(builder.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of <see cref="SerializedEntityKey"/> for the given properties and values.
        /// </summary>
        /// <param name="keySerializer">The key serializer to use.</param>
        /// <param name="absoluteServiceUri">The absolute service URI.</param>
        /// <param name="entitySetName">Name of the entity set.</param>
        /// <param name="keyProperties">The key properties.</param>
        /// <param name="getPropertyValue">The callback to get each property's value.</param>
        /// <param name="editLinkSuffix">The suffix to append to the edit-link, or null.</param>
        /// <returns>A serialized-key instance.</returns>
        internal static SerializedEntityKey Create(
            KeySerializer keySerializer,
            Uri absoluteServiceUri,
            string entitySetName,
            ICollection <ResourceProperty> keyProperties,
            Func <ResourceProperty, object> getPropertyValue,
            string editLinkSuffix)
        {
            SimpleLazy <string> lazyRelativeIdentity = new SimpleLazy <string>(() =>
            {
                var builder = new StringBuilder();
                builder.Append(entitySetName);
                keySerializer.AppendKeyExpression(builder, keyProperties, p => p.Name, getPropertyValue);
                return(builder.ToString());
            });

            return(new LazySerializedEntityKey(lazyRelativeIdentity, absoluteServiceUri, editLinkSuffix));
        }
 /// <summary>
 /// Creates an instance of <see cref="SerializedEntityKey"/> for the given properties and values.
 /// </summary>
 /// <param name="keySerializer">The key serializer to use.</param>
 /// <param name="absoluteServiceUri">The absolute service URI.</param>
 /// <param name="entitySetName">Name of the entity set.</param>
 /// <param name="keyProperties">The key properties.</param>
 /// <param name="getPropertyValue">The callback to get each property's value.</param>
 /// <param name="editLinkSuffix">The suffix to append to the edit-link, or null.</param>
 /// <returns>A serialized-key instance.</returns>
 internal static SerializedEntityKey Create(
     KeySerializer keySerializer, 
     Uri absoluteServiceUri,
     string entitySetName, 
     ICollection<ResourceProperty> keyProperties,
     Func<ResourceProperty, object> getPropertyValue, 
     string editLinkSuffix)
 {
     SimpleLazy<string> lazyRelativeIdentity = new SimpleLazy<string>(() =>
     {
         var builder = new StringBuilder();
         builder.Append(entitySetName);
         keySerializer.AppendKeyExpression(builder, keyProperties, p => p.Name, getPropertyValue);
         return builder.ToString();
     });
         
     return new LazySerializedEntityKey(lazyRelativeIdentity, absoluteServiceUri, editLinkSuffix);
 }