示例#1
0
        public void Build(FileInfo fileInfo)
        {
            Clear(); // This clears all local primary and default entries, as well as the list of parents.

            if (fileInfo == null)
            {
                throw new ArgumentNullException("fileInfo", "The argument must not be null.");
            }
            if (!fileInfo.Exists)
            {
                throw new FileNotFoundException("The specified file does not exist.", fileInfo.FullName);
            }

            _root    = fileInfo;
            Name     = _root.Name;
            FullName = _root.FullName;

            var propFile = new File(fileInfo);

            foreach (var entry in propFile.Properties)
            {
                LocalEntries.Add(entry.Key, entry.Value);
            }
            BuildParents();
        }
示例#2
0
 /// <summary>
 /// This constructor accepts an enumerable of initial properties for loading into the local dictionary.
 /// The internal DirectoryInfo instance is created pointing to the current directory. This obviously
 /// has no specific meaning.
 /// </summary>
 public FileDictionaryTree(IEnumerable <KeyValuePair <string, string> > initialProperties) : this()
 {
     foreach (var pair in initialProperties)
     {
         LocalEntries.Add(pair.Key, pair.Value);
     }
 }
示例#3
0
 /// <summary>
 /// This adds a key/value pair "shallowly".
 /// That is, it only adds it to the top-level dictionary.
 /// The parents and defaults, if they exist, are unaffected.
 /// Note that this is just a convenience, since the method could also be called directly on the Primary dictionary.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void Add(TKey key, TValue value)
 {
     lock (_syncRoot)
     {
         LocalEntries.Add(key, value);
     }
 }
示例#4
0
        // The following INamespace properties are implemented on DictionaryTree
        //public string Name { get; protected set; }
        //public string FullName { get; protected set; }

        #endregion

        #region IParameterSource

        /// <summary>
        /// This method inserts or overwrites a parameter and its value in the Primary dictionary.
        /// Note that this only affects the top-level Primary dictionary. If parents contain entries
        /// for the same parameter, those entries remain unaffected and will "shadow" whatever
        /// entry is created or overwritten here. In other words, if this entry is later removed
        /// from the dictionary at this level, then the parent entries will come back into view.
        /// </summary>
        /// <param name="parameter">The parameter that will be used as the key.</param>
        /// <param name="paramValue">The parameter value that will be associated with the key.</param>
        public void SetParameter(IParameter parameter, string paramValue)
        {
            if (LocalEntries.ContainsKey(parameter.Param)) // update existing entry
            {
                LocalEntries[parameter.Param] = paramValue;
            }
            else
            {
                LocalEntries.Add(parameter.Param, paramValue); // add new entry
            }
        }