Example #1
0
        /// <summary>
        /// Puts a {@link CustomProperty} into this map. It is assumed that the
        /// {@link CustomProperty} alReady has a valid ID. Otherwise use
        /// {@link #Put(CustomProperty)}.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="cp">The custom property.</param>
        /// <returns></returns>
        public CustomProperty Put(string name, CustomProperty cp)
        {
            if (string.IsNullOrEmpty((string)name))     //tony qu changed the code
            {
                /* Ignoring a property without a name. */
                isPure = false;
                return null;
            }
            if (!(name is String))
                throw new ArgumentException("The name of a custom property must " +
                        "be a String, but it is a " +
                        name.GetType().Name);
            if (!(name.Equals(cp.Name)))
                throw new ArgumentException("Parameter \"name\" (" + name +
                        ") and custom property's name (" + cp.Name +
                        ") do not match.");

            /* Register name and ID in the dictionary. Mapping in both directions is possible. If there is alReady a  */
            long idKey = cp.ID;
            Object oldID = dictionaryNameToID[name];
            if(oldID!=null)
                dictionaryIDToName.Remove(oldID);
            dictionaryNameToID[name]=idKey;
            dictionaryIDToName[idKey]= name;

            /* Put the custom property into this map. */
            if (oldID != null)
                base.Remove(oldID);

            base[idKey]= cp;
            return cp;
        }
Example #2
0
 /// <summary>
 /// Adds a named bool property.
 /// </summary>
 /// <param name="name">The property's name.</param>
 /// <param name="value">The property's value.</param>
 /// <returns>the property that was stored under the specified name before, or
 /// <c>null</c>
 ///  if there was no such property before.</returns>
 public Object Put(String name, bool value)
 {
     MutableProperty p = new MutableProperty();
     p.ID=-1;
     p.Type=Variant.VT_BOOL;
     p.Value=value;
     CustomProperty cp = new CustomProperty(p, name);
     return Put(cp);
 }
Example #3
0
 /// <summary>
 /// Adds a named date property.
 /// </summary>
 /// <param name="name">The property's name.</param>
 /// <param name="value">The property's value.</param>
 /// <returns>the property that was stored under the specified name before, or
 /// <c>null</c>
 ///  if there was no such property before.</returns>
 public Object Put(String name,DateTime value)
 {
     MutableProperty p = new MutableProperty();
     p.ID=-1;
     p.Type=Variant.VT_FILETIME;
     p.Value=value;
     CustomProperty cp = new CustomProperty(p, name);
     return Put(cp);
 }
Example #4
0
 /// <summary>
 /// Puts a {@link CustomProperty} that has not yet a valid ID into this
 /// map. The method will allocate a suitable ID for the custom property:
 /// <ul>
 /// 	<li>If there is alReady a property with the same name, take the ID
 /// of that property.</li>
 /// 	<li>Otherwise Find the highest ID and use its value plus one.</li>
 /// </ul>
 /// </summary>
 /// <param name="customProperty">The custom property.</param>
 /// <returns>If the was alReady a property with the same name, the</returns>
 private Object Put(CustomProperty customProperty)
 {
     String name = customProperty.Name;
     
     /* Check whether a property with this name is in the map alReady. */
     object oldId = dictionaryNameToID[(name)];
     if (oldId!=null)
     {
         customProperty.ID = (long)oldId;
     }
     else
     {
         long max = 1;
         for (IEnumerator i = dictionaryIDToName.Keys.GetEnumerator(); i.MoveNext(); )
         {
             long id = (long)i.Current;
             if (id > max)
                 max = id;
         }
         customProperty.ID = max + 1;
     }
     return this.Put(name, customProperty);
 }