示例#1
0
        /// <summary>
        ///     Converts a ldap entry to the ldap model object.
        /// </summary>
        /// <param name="entry">Entry to convert.</param>
        public virtual void ProvideEntry(LdapEntry entry)
        {
            this.Id    = entry.GetAttribute(LdapProperties.CommonName);
            this.Dn    = entry.DN;
            this.Entry = entry;

            // load properties with reflection
            foreach (KeyValuePair <PropertyInfo, LdapAttr> kv in this.Properties)
            {
                object value;
                switch (Type.GetTypeCode(kv.Value.Type))
                {
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                    value = entry.GetIntAttribute(kv.Value);
                    break;

                case TypeCode.Boolean:
                    bool?boolval = entry.GetBoolAttribute(kv.Value);
                    value = boolval ?? false;
                    break;

                case TypeCode.DateTime:
                    value = entry.GetDateTimeAttribute(kv.Value);
                    break;

                case TypeCode.Object:
                    if (kv.Value.Type == typeof(List <string>))
                    {
                        value = entry.GetStringListAttribute(kv.Value);
                        break;
                    }

                    value = null;
                    break;

                default:
                    value = entry.GetAttribute(kv.Value);
                    break;
                }

                kv.Key.SetValue(this, value);
            }
        }