Correction of AD attribute assignment in adhelper

Source: Internet
Author: User

For more information about ad programming, see adhelper. It seems that the method of assigning values to attributes of AD is incorrect.
The original method is similar to the following:

1 Public   Static   Void Setproperty (directoryentry de, String Propertyname, String Propertyvalue)
2 {
3 If (Propertyvalue ! =   String . Empty | Propertyvalue ! =   ""   | Propertyvalue ! =   Null )
4 {
5 If (De. properties. Contains (propertyname ))
6 {
7 De. properties [propertyname] [ 0 ] = Propertyvalue;
8 }
9 Else
10 {
11 De. properties [propertyname]. Add (propertyvalue );
12 }
13 }
14 }

However, in actual operations, you will find that sometimes the attribute we have assigned must be changed to a null value, then the method will not take effect. In addition, you will also find that the null value of propertyvalue is removed, and it will not pass, because no matter whether this attribute exists or not, you will report an error if you directly assign this attribute to null.
To assign a value to a null value, you can remove it. The following method is correct: 1 Public   Static   Void Setproperty (directoryentry entry, String Propertyname, String Propertyvalue)
2 {
3 If (Entry. properties. Contains (propertyname ))
4 {
5 If ( String . Isnullorempty (propertyvalue ))
6 {
7 Object O = Entry. properties [propertyname]. value;
8 Entry. properties [propertyname]. Remove (O );
9 }
10 Else
11 {
12 Entry. properties [propertyname] [ 0 ] = Propertyvalue;
13 }
14 }
15 Else
16 {
17 If ( ! String . Isnullorempty (propertyvalue ))
18 {
19 Entry. properties [propertyname]. Add (propertyvalue );
20 }
21 }
22 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.