Attribute Class Map

You can put attributes directly on your class, mapping it to the directory. This does not require adding the mapping to the Directory Mapper. You can simply start querying with it and the first time it is encountered it will be mapped.

By default any property with a getter and setter (public, internal, protected, or private) and a DirectoryAttribute will be mapped. Your class must also be decorated with the DirectorySchema attribute. You can opt out of a property mapping for a subclass by overriding the property in the subclass without an attribute. Changing the default behavior can be done by either subclassing AttributeClassMap and or changing the default attribute mapper on Directory Mapper.

Mapping ObjectClasses and / or ObjectCategory gives you the option to include them in all queries or ignore them unless otherwise specified by IgnoreOC or IncludeOC.
Basic Mapping
[DirectorySchema("OU=Roles,DC=example,DC=com", ObjectCategory = "Group", ObjectClass = "Group")]
public class Role
{
    [DistinguishedName]
    public string DistinguishedName { get; set; }

    [DirectoryAttribute("cn", ReadOnly = true)]
    public string CommonName { get; set; }

    [DirectoryAttribute]
    public Collection<string> Members { get; set; }
}
Subclass Mapping
[DirectorySchema("OU=Servers,DC=example,DC=com", ObjectClass = "Server")]
public class Server
{
    [DistinguishedName]
    public string DistinguishedName { get; set; }

    [DirectoryAttribute(ReadOnly = true)]
    public string Cn { get; set; }

    [DirectoryAttribute("objectguid", StoreGenerated = true)]
    public Guid Guid { get; set; }

    [DirectoryAttribute]
    public string OperatingSystem { get; set; }
}

[DirectorySchema("OU=Email Servers,OU=Servers,DC=example,DC=com",ObjectClass = "Server")]
public class EmailServer : Server
{
    [DirectoryAttribute]
    public string Platform { get; set; }
}

[DirectorySchema("OU=Web Servers,OU=Servers,DC=example,DC=com", ObjectClass = "Server")]
public class WebServer : Server
{
    [DirectoryAttribute]
    public string Platform { get; set; }

    [DirectoryAttribute]
    public bool IsLoadBalanced { get; set; }

    [DirectoryAttribute]
    public string LoadBalancerName { get; set; }
}

Last edited Jul 24, 2015 at 4:05 PM by MadHatter22, version 10