Beispiel #1
0
        public EntityTagHeaderValue CreateETag(IDictionary <string, object> properties, TimeZoneInfo timeZoneInfo = null)
        {
            if (properties == null)
            {
                throw Error.ArgumentNull(nameof(properties));
            }

            if (properties.Count == 0)
            {
                return(null);
            }

            StringBuilder builder = new StringBuilder();

            builder.Append('\"');
            bool firstProperty = true;

            foreach (object propertyValue in properties.Values)
            {
                if (firstProperty)
                {
                    firstProperty = false;
                }
                else
                {
                    builder.Append(Separator);
                }

                string str = propertyValue == null
                    ? NullLiteralInETag
                    : ConventionsHelpers.GetUriRepresentationForValue(propertyValue, timeZoneInfo);

                // base64 encode
                byte[] bytes         = Encoding.UTF8.GetBytes(str);
                string etagValueText = Convert.ToBase64String(bytes);
                builder.Append(etagValueText);
            }

            builder.Append('\"');
            string tag = builder.ToString();

            return(new EntityTagHeaderValue(tag, isWeak: true));
        }