Exemple #1
0
 public virtual void VisitObjectSyntax(ObjectSyntax syntax)
 {
     this.Visit(syntax.OpenBrace);
     this.VisitNodes(syntax.Children);
     this.Visit(syntax.CloseBrace);
 }
 void ISyntaxVisitor.VisitObjectSyntax(ObjectSyntax syntax) => ReplaceCurrent(syntax, ReplaceObjectSyntax);
 /// <summary>
 /// Converts a syntactically valid object syntax node to a dictionary mapping property name strings to property value expressions. Will throw if you provide a node with duplicate properties.
 /// </summary>
 /// <param name="syntax">The object syntax node</param>
 public static ImmutableDictionary <string, SyntaxBase> ToKnownPropertyValueDictionary(this ObjectSyntax syntax) =>
 syntax.Properties.ToImmutableDictionaryExcludingNull(p => p.TryGetKeyText(), p => p.Value, LanguageConstants.IdentifierComparer);
 /// <summary>
 /// Converts a syntactically valid object syntax node to a dictionary mapping property name strings to property syntax nodes. Will throw if you provide a node with duplicate properties.
 /// </summary>
 /// <param name="syntax">The object syntax node</param>
 public static ImmutableDictionary <string, ObjectPropertySyntax> ToNamedPropertyDictionary(this ObjectSyntax syntax) =>
 syntax.Properties.ToImmutableDictionaryExcludingNull(p => p.TryGetKeyText(), LanguageConstants.IdentifierComparer);
 /// <summary>
 /// Converts a syntactically valid object syntax node to a hashset of property name strings. Will throw if you provide a node with duplicate properties.
 /// </summary>
 /// <param name="syntax">The object syntax node</param>
 public static ImmutableHashSet <string> ToKnownPropertyNames(this ObjectSyntax syntax) =>
 syntax.Properties.Select(p => p.TryGetKeyText()).ToImmutableHashSetExcludingNull(LanguageConstants.IdentifierComparer);
Exemple #6
0
 /// <summary>
 /// Converts a syntactically valid object syntax node to a dictionary mapping property name strings to property syntax node values. Returns the first property value in the case of duplicate names.
 /// </summary>
 /// <param name="syntax">The object syntax node</param>
 public static ImmutableDictionary <string, SyntaxBase> ToNamedPropertyValueDictionary(this ObjectSyntax syntax)
 => ToNamedPropertyDictionary(syntax).ToImmutableDictionary(x => x.Key, x => x.Value.Value, LanguageConstants.IdentifierComparer);
Exemple #7
0
        /// <summary>
        /// Converts a syntactically valid object syntax node to a dictionary mapping property name strings to property syntax nodes. Returns the first property in the case of duplicate names.
        /// </summary>
        /// <param name="syntax">The object syntax node</param>
        public static ImmutableDictionary <string, ObjectPropertySyntax> ToNamedPropertyDictionary(this ObjectSyntax syntax)
        {
            var dictionary = new Dictionary <string, ObjectPropertySyntax>(LanguageConstants.IdentifierComparer);

            foreach (var property in syntax.Properties)
            {
                if (property.TryGetKeyText() is { } key&& !dictionary.ContainsKey(key))
                {
                    dictionary[key] = property;
                }
            }

            return(dictionary.ToImmutableDictionary(LanguageConstants.IdentifierComparer));
        }
Exemple #8
0
 private static SyntaxBase?TryGetObjectProperty(ObjectSyntax objectSyntax, string propertyName)
 => objectSyntax.Properties.SingleOrDefault(p => p.TryGetKeyText() == propertyName)?.Value;
Exemple #9
0
 public static ObjectPropertySyntax?SafeGetPropertyByNameRecursive(this ObjectSyntax syntax, IList <IdentifierSyntax> propertyAccesses)
 {
     return(syntax.SafeGetPropertyByNameRecursive(propertyAccesses.Select(pa => pa.IdentifierName).ToArray()));
 }