src/Shared/EntityFramework/Infrastructure/Annotations/IndexAnnotationSerializer.cs
/// <summary>
///     Deserializes the given string back into an <see cref="IndexAnnotation" /> object.
/// </summary>
/// <param name="name">The name of the annotation that is being deserialized.</param>
/// <param name="value">The string to deserialize.</param>
/// <returns>The deserialized annotation value.</returns>
/// <exception cref="FormatException">If there is an error reading the serialized value.</exception>
Deserializes the given string back into an  object.
Deserializes the given string back into an object .
public virtual object Deserialize(string name, string value)
        {
            Check.NotEmpty(name, "name");
            Check.NotEmpty(value, "value");
            value = value.Trim();
            if (!value.StartsWith("{", StringComparison.Ordinal)
                || !value.EndsWith("}", StringComparison.Ordinal))
            {
                throw BuildFormatException(value);
            }
            var indexes = new List<IndexAttribute>();
            var indexStrings = _indexesSplitter.Split(value).Select(s => s.Trim()).ToList();
            indexStrings[0] = indexStrings[0].Substring(1);
            var lastIndex = indexStrings.Count - 1;
            indexStrings[lastIndex] = indexStrings[lastIndex].Substring(0, indexStrings[lastIndex].Length - 1);
            foreach (var indexString in indexStrings)
            {
                var indexAttribute = new IndexAttribute();
                if (!string.IsNullOrWhiteSpace(indexString))
                {
                    foreach (var indexPart in _indexPartsSplitter.Split(indexString).Select(s => s.Trim()))
                    {
                        if (indexPart.StartsWith("Name:", StringComparison.Ordinal))
                        {
                            var indexName = indexPart.Substring(5).Trim();
                            if (string.IsNullOrWhiteSpace(indexName)
                                || !string.IsNullOrWhiteSpace(indexAttribute.Name))
                            {
                                throw BuildFormatException(value);
                            }
                            indexAttribute.Name = indexName.Replace(@"\,", ",").Replace(@"\{", "{");
                        }
                        else if (indexPart.StartsWith("Order:", StringComparison.Ordinal))
                        {
                            int order;
                            if (!int.TryParse(indexPart.Substring(6).Trim(), out order)
                                || indexAttribute.Order != -1)
                            {
                                throw BuildFormatException(value);
                            }
                            indexAttribute.Order = order;
                        }
                        else if (indexPart.StartsWith("IsClustered:", StringComparison.Ordinal))
                        {
                            bool isClustered;
                            if (!bool.TryParse(indexPart.Substring(12).Trim(), out isClustered)
                                || indexAttribute.IsClusteredConfigured)
                            {
                                throw BuildFormatException(value);
                            }
                            indexAttribute.IsClustered = isClustered;
                        }
                        else if (indexPart.StartsWith("IsUnique:", StringComparison.Ordinal))
                        {
                            bool isUnique;
                            if (!bool.TryParse(indexPart.Substring(9).Trim(), out isUnique)
                                || indexAttribute.IsUniqueConfigured)
                            {
                                throw BuildFormatException(value);
                            }
                            indexAttribute.IsUnique = isUnique;
                        }
                        else
                        {
                            throw BuildFormatException(value);
                        }
                    }
                }
                indexes.Add(indexAttribute);
            }
            return new IndexAnnotation(indexes);
        }
public virtual object Deserialize ( string name , string value ) { Check . NotEmpty ( name , " " ) ; Check . NotEmpty ( value , " " ) ; value = value . Trim ( ) ; if ( ! value . StartsWith ( " " , StringComparison . Ordinal ) || ! value . EndsWith ( " " , StringComparison . Ordinal ) ) { throw BuildFormatException ( value ) ; } var indexes = new List < IndexAttribute > ( ) ; var indexStrings = _indexesSplitter . Split ( value ) . Select ( s => s . Trim ( ) ) . ToList ( ) ; indexStrings [ 0 ] = indexStrings [ 0 ] . Substring ( 1 ) ; var lastIndex = indexStrings . Count - 1 ; indexStrings [ lastIndex ] = indexStrings [ lastIndex ] . Substring ( 0 , indexStrings [ lastIndex ] . Length - 1 ) ; foreach ( var indexString in indexStrings ) { var indexAttribute = new IndexAttribute ( ) ; if ( ! string . IsNullOrWhiteSpace ( indexString ) ) { foreach ( var indexPart in _indexPartsSplitter . Split ( indexString ) . Select ( s => s . Trim ( ) ) ) { if ( indexPart . StartsWith ( " " , StringComparison . Ordinal ) ) { var indexName = indexPart . Substring ( 5 ) . Trim ( ) ; if ( string . IsNullOrWhiteSpace ( indexName ) || ! string . IsNullOrWhiteSpace ( indexAttribute . Name ) ) { throw BuildFormatException ( value ) ; } indexAttribute . Name = indexName . Replace ( @"\," , " " ) . Replace ( @"\{" , " " ) ; } else if ( indexPart . StartsWith ( " " , StringComparison . Ordinal ) ) { int order ; if ( ! int . TryParse ( indexPart . Substring ( 6 ) . Trim ( ) , out order ) || indexAttribute . Order != - 1 ) { throw BuildFormatException ( value ) ; } indexAttribute . Order = order ; } else if ( indexPart . StartsWith ( " " , StringComparison . Ordinal ) ) { bool isClustered ; if ( ! bool . TryParse ( indexPart . Substring ( 12 ) . Trim ( ) , out isClustered ) || indexAttribute . IsClusteredConfigured ) { throw BuildFormatException ( value ) ; } indexAttribute . IsClustered = isClustered ; } else if ( indexPart . StartsWith ( " " , StringComparison . Ordinal ) ) { bool isUnique ; if ( ! bool . TryParse ( indexPart . Substring ( 9 ) . Trim ( ) , out isUnique ) || indexAttribute . IsUniqueConfigured ) { throw BuildFormatException ( value ) ; } indexAttribute . IsUnique = isUnique ; } else { throw BuildFormatException ( value ) ; } } } indexes . Add ( indexAttribute ) ; } return new IndexAnnotation ( indexes ) ; }
Deserializes the given string back into an  object.
Deserializes the given string back into an object .
The deserialized annotation value.
The deserialized annotation value .
If there is an error reading the serialized value.
If there is an error reading the serialized value .
name
string
The name of the annotation that is being deserialized.
The name of the annotation that is being deserialized .
value
string
The string to deserialize.
The string to deserialize .