Skip to content

Commit

Permalink
Use reflection instead of hardcoded names to copy object LDAPConnecti…
Browse files Browse the repository at this point in the history
…on, to avoid misses/errors
  • Loading branch information
Yvand committed Apr 10, 2019
1 parent 6017579 commit 24b86c0
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions LDAPCP/LDAPCPConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,24 +796,31 @@ public LDAPConnection()

internal LDAPConnection CopyPublicProperties()
{
return new LDAPConnection()
LDAPConnection copy = new LDAPConnection();
FieldInfo[] publicFields = this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo field in publicFields)
{
Id = this.Id,
Path = this.Path,
Username = this.Username,
Password = this.Password,
Metadata = this.Metadata,
AuthenticationTypes = this.AuthenticationTypes,
UserServerDirectoryEntry = this.UserServerDirectoryEntry,
AugmentationEnabled = this.AugmentationEnabled,
GetGroupMembershipAsADDomain = this.GetGroupMembershipAsADDomain,
GroupMembershipAttributes = this.GroupMembershipAttributes,
Directory = this.Directory,
Filter = this.Filter,
DomainName = this.DomainName,
DomainFQDN = this.DomainFQDN,
RootContainer = this.RootContainer,
};
field.SetValue(copy, field.GetValue(this));
}
return copy;
//return new LDAPConnection()
//{
// Id = this.Id,
// Path = this.Path,
// Username = this.Username,
// Password = this.Password,
// Metadata = this.Metadata,
// AuthenticationTypes = this.AuthenticationTypes,
// UserServerDirectoryEntry = this.UserServerDirectoryEntry,
// AugmentationEnabled = this.AugmentationEnabled,
// GetGroupMembershipAsADDomain = this.GetGroupMembershipAsADDomain,
// GroupMembershipAttributes = this.GroupMembershipAttributes,
// Directory = this.Directory,
// Filter = this.Filter,
// DomainName = this.DomainName,
// DomainFQDN = this.DomainFQDN,
// RootContainer = this.RootContainer,
//};
}
}

Expand Down

0 comments on commit 24b86c0

Please sign in to comment.