示例#1
0
        internal AliasNodeField(string name, AliasDefinition alias, bool isArray)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"Invalid name: '{name}'", nameof(name));
            }
            if (alias == null)
            {
                throw new ArgumentNullException(nameof(alias));
            }

            this.Name    = name;
            this.Alias   = alias;
            this.IsArray = isArray;
        }
        internal TreeDefinition(
            AliasDefinition rootAlias,
            ImmutableArray <AliasDefinition> aliases,
            ImmutableArray <EnumDefinition> enums,
            ImmutableArray <NodeDefinition> nodes)
        {
            if (rootAlias == null)
            {
                throw new ArgumentNullException(nameof(rootAlias));
            }
            if (aliases == null)
            {
                throw new ArgumentNullException(nameof(aliases));
            }
            if (enums == null)
            {
                throw new ArgumentNullException(nameof(enums));
            }
            if (nodes == null)
            {
                throw new ArgumentNullException(nameof(nodes));
            }

            // Verify that root-alias exists in the aliases array.
            Debug.Assert(aliases.Contains(rootAlias), "Root-alias must exist in aliases array");

            // Verify that there are no duplicate alias/enum identifiers.
            Debug.Assert(
                aliases.Select(a => a.Identifier).Concat(enums.Select(e => e.Identifier)).IsUnique(),
                "Alias/Enum identifiers must be unique");

            // Verify that there are no duplicate nodes.
            Debug.Assert(nodes.Select(n => n.Type).IsUnique(), "Nodetype must be unique");

            // Verify that aliases only reference nodes that actually exist.
            Debug.Assert(
                aliases.SelectMany(a => a.Values).All(aliasVal => nodes.Any(n => n.Type == aliasVal)),
                "Alias defines a value that is not a type in the types array");

            this.RootAlias = rootAlias;
            this.Aliases   = aliases;
            this.Enums     = enums;
            this.Nodes     = nodes;
        }
 /// <summary>
 /// Attempt to get an alias by identifier.
 /// </summary>
 /// <param name="identifier">Identifier of the alias to get</param>
 /// <param name="alias">Found alias</param>
 /// <returns>True if found, otherwise false</returns>
 public bool TryGetAlias(string identifier, out AliasDefinition alias)
 {
     alias = this.Aliases.FirstOrDefault(a => a.Identifier == identifier);
     return(alias != null);
 }