private static IEnumerable <KeyValuePair <string, object> > ParseETagValue(IList <ResourceProperty> etagProperties, string ifMatchHeaderValue) { bool flag; if (ifMatchHeaderValue == "*") { return(WebUtil.EmptyKeyValuePairStringObject); } string stringToUnescape = ifMatchHeaderValue.Substring("W/\"".Length, (ifMatchHeaderValue.Length - "W/\"".Length) - 1); KeyInstance instance = null; Exception innerException = null; try { flag = KeyInstance.TryParseNullableTokens(Uri.UnescapeDataString(stringToUnescape), out instance); } catch (DataServiceException exception2) { flag = false; innerException = exception2; } if (!flag) { throw DataServiceException.CreatePreConditionFailedError(System.Data.Services.Strings.Serializer_ETagValueDoesNotMatch, innerException); } if (instance.PositionalValues.Count != etagProperties.Count) { throw DataServiceException.CreatePreConditionFailedError(System.Data.Services.Strings.Serializer_ETagValueDoesNotMatch); } KeyValuePair <string, object>[] pairArray = new KeyValuePair <string, object> [etagProperties.Count]; for (int i = 0; i < pairArray.Length; i++) { ResourceProperty property = etagProperties[i]; object targetValue = null; string text = (string)instance.PositionalValues[i]; if (text != "null") { try { flag = WebConvert.TryKeyStringToPrimitive(text, property.Type, out targetValue); } catch (OverflowException exception3) { flag = false; innerException = exception3; } if (!flag) { throw DataServiceException.CreatePreConditionFailedError(System.Data.Services.Strings.Serializer_ETagValueDoesNotMatch, innerException); } } pairArray[i] = new KeyValuePair <string, object>(etagProperties[i].Name, targetValue); } return(pairArray); }
/// <summary>Tries to convert values to the keys of the specified type.</summary> /// <param name="type">Type with key information for conversion.</param> /// <returns>true if all values were converted; false otherwise.</returns> internal bool TryConvertValues(ResourceType type) { Debug.Assert(type != null, "type != null"); Debug.Assert(!this.IsEmpty, "!this.IsEmpty -- caller should check"); Debug.Assert(type.KeyProperties.Count == this.ValueCount, "type.KeyProperties.Count == this.ValueCount -- will change with containment"); if (this.namedValues != null) { for (int i = 0; i < type.KeyProperties.Count; i++) { ResourceProperty property = type.KeyProperties[i]; object unconvertedValue; if (!this.namedValues.TryGetValue(property.Name, out unconvertedValue)) { return(false); } string valueText = (string)unconvertedValue; object convertedValue; if (!WebConvert.TryKeyStringToPrimitive(valueText, property.Type, out convertedValue)) { return(false); } this.namedValues[property.Name] = convertedValue; } } else { Debug.Assert(this.positionalValues != null, "positionalValues != null -- otherwise this is Empty"); for (int i = 0; i < type.KeyProperties.Count; i++) { string valueText = (string)this.positionalValues[i]; object convertedValue; if (!WebConvert.TryKeyStringToPrimitive(valueText, type.KeyProperties[i].Type, out convertedValue)) { return(false); } this.positionalValues[i] = convertedValue; } } return(true); }
internal bool TryConvertValues(ResourceType type) { if (this.namedValues != null) { for (int i = 0; i < type.KeyProperties.Count; i++) { object obj2; object obj3; ResourceProperty property = type.KeyProperties[i]; if (!this.namedValues.TryGetValue(property.Name, out obj2)) { return(false); } string text = (string)obj2; if (!WebConvert.TryKeyStringToPrimitive(text, property.Type, out obj3)) { return(false); } this.namedValues[property.Name] = obj3; } } else { for (int j = 0; j < type.KeyProperties.Count; j++) { object obj4; string str2 = (string)this.positionalValues[j]; if (!WebConvert.TryKeyStringToPrimitive(str2, type.KeyProperties[j].Type, out obj4)) { return(false); } this.positionalValues[j] = obj4; } } return(true); }