Created
April 11, 2012 14:40
-
-
Save daniellee/2359749 to your computer and use it in GitHub Desktop.
LdapObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ILdapObject | |
{ | |
string ObjectName { get; set; } | |
string Context { get; set; } | |
} | |
public abstract class LdapObject<T>: ILdapObject where T: ILdapObject, new() | |
{ | |
public string ObjectName { get; set; } | |
public string Context { get; set; } | |
protected static readonly Regex Parser = new Regex("^cn=(?<object>.*?),(?<context>.*)$", RegexOptions.IgnoreCase); | |
public static T Parse(string s) | |
{ | |
if (s == null || s.Trim().Length == 0) return default(T); | |
var m = Parser.Match(s); | |
return | |
(m.Success) | |
? new T { ObjectName = m.Groups["object"].Value, Context = m.Groups["context"].Value } | |
: new T { ObjectName = s, Context = null }; | |
} | |
} | |
public class LdapGroup : LdapObject<LdapGroup> | |
{ | |
public List<LdapUserInfo> Members { get; set; } | |
public LdapGroup() | |
{ | |
Members = new List<LdapUserInfo>(); | |
} | |
} | |
public class LdapUserInfo : LdapObject<LdapUserInfo> | |
{ | |
public List<LdapGroup> MemberOf { get; set; } | |
public LdapUserInfo() | |
{ | |
MemberOf = new List<LdapGroup>(); | |
} | |
} | |
[Test] | |
public void LdapObject_Parse_ReturnEmpty() | |
{ | |
LdapGroup test = LdapGroup.Parse("test"); | |
Assert.That(test, Is.Not.Null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment