Exemplo n.º 1
0
        public static object GetInstanceWithVal(string type, List <LdapValue> ldapValue)
        {
            object returnVal   = "";
            bool   hasMultiple = ldapValue.Count > 1;

            if (!hasMultiple)
            {
                returnVal = MiscUtilsService.GetInstanceFromType(type);
                switch (type)
                {
                case "System.DateTime":
                    var str = ldapValue[0].StringValue;
                    returnVal = DateTime.ParseExact(str, DATE_FORMAT, CultureInfo.InvariantCulture);
                    break;

                default:
                    returnVal = ConvertVal(ldapValue[0].StringValue);
                    break;
                }
            }
            else
            {
                var list = new List <string>();

                foreach (LdapValue value in ldapValue)
                {
                    list.Add(value.StringValue);
                }

                returnVal = list;
            }
            return(returnVal);
        }
Exemplo n.º 2
0
 public static void ConvertToKVData(Dictionary <string, VMDirBagItem> _properties, List <KeyValuePair <string, string> > _kvData)
 {
     MiscUtilsService.CheckedExec(delegate
     {
         _kvData.Clear();
         foreach (var entry in _properties)
         {
             object value = entry.Value.Value;
             if (value != null)
             {
                 Type valueType = value.GetType();
                 if (valueType.IsArray)
                 {
                     LdapValue[] arr = value as LdapValue[];
                     foreach (var arrayElement in arr)
                     {
                         _kvData.Add(new KeyValuePair <string, string>(entry.Key, arrayElement.StringValue));
                     }
                 }
                 else
                 {
                     var LdapEntry = (LdapValue)value;
                     _kvData.Add(new KeyValuePair <string, string>(entry.Key, value.ToString()));
                 }
             }
             else
             {
                 _kvData.Add(new KeyValuePair <string, string>(entry.Key, string.Empty));
             }
         }
         _kvData.Sort(delegate(KeyValuePair <string, string> x, KeyValuePair <string, string> y)
         {
             return(x.Key.CompareTo(y.Key));
         });
     });
 }