예제 #1
0
        /// <summary>
        /// Creates DictionaryData filled by entries in the IDictionary.
        /// </summary>
        /// <remarks>
        /// Its behavior is decided by FromDictionary method, depending on how it's
        /// implemented by inheritors.
        /// </remarks>
        public static DictionaryData CreateDictionaryData(IDictionary dict)
        {
            //every dictionary must have type information
            //if not, exception should be thrown
            DictionaryDataType t = (DictionaryDataType)dict[DictionaryData.DataTypeKey];
            //This is supposed to be a derived class
            DictionaryData d = PrepareDictionaryData(t);

            d.FromDictionary(dict);
            return(d);
        }
예제 #2
0
 /// <summary>
 /// Converts the enum value of a DictionaryData type to a class type.
 /// </summary>
 public static Type GetDataType(DictionaryDataType type)
 {
     switch(type) {
     case DictionaryDataType.FingerprintedData:
       return typeof(FingerprintedData);
     case DictionaryDataType.FragmentableData:
       return typeof(FragmentableData);
     case DictionaryDataType.Regular:
       return typeof(RegularData);
     case DictionaryDataType.FragmentationInfo:
       return typeof(FragmentationInfo);
     case DictionaryDataType.BTPeerEntry:
       return typeof(PeerEntry);
     default:
       return typeof(object);
       }
 }
예제 #3
0
        /// <summary>
        /// Converts the enum value of a DictionaryData type to a class type.
        /// </summary>
        public static Type GetDataType(DictionaryDataType type)
        {
            switch (type)
            {
            case DictionaryDataType.FingerprintedData:
                return(typeof(FingerprintedData));

            case DictionaryDataType.FragmentableData:
                return(typeof(FragmentableData));

            case DictionaryDataType.Regular:
                return(typeof(RegularData));

            case DictionaryDataType.FragmentationInfo:
                return(typeof(FragmentationInfo));

            case DictionaryDataType.BTPeerEntry:
                return(typeof(PeerEntry));

            default:
                return(typeof(object));
            }
        }
예제 #4
0
 /**
  * Creates an <b>empty</b> DictionaryData object with the datatype info.
  * @return A reference to the newly created object.
  */
 protected static DictionaryData PrepareDictionaryData(DictionaryDataType type)
 {
     Type t = DictionaryDataUtil.GetDataType(type);
       return (DictionaryData)Activator.CreateInstance(t);
 }
예제 #5
0
        /**
         * Creates an <b>empty</b> DictionaryData object with the datatype info.
         * @return A reference to the newly created object.
         */
        protected static DictionaryData PrepareDictionaryData(DictionaryDataType type)
        {
            Type t = DictionaryDataUtil.GetDataType(type);

            return((DictionaryData)Activator.CreateInstance(t));
        }