示例#1
0
        public static DomainSecurityPrincipalName TryParse(string name)
        {
            if (name.IsNullOrWhiteSpace())
            {
                return(null);
            }

            var samNameParts = name.Split("\\");

            if (samNameParts.Length == 2)
            {
                var domainSecurityPrincipalName = TryParse(samNameParts[0], samNameParts[1]);
                if (domainSecurityPrincipalName != null)
                {
                    return(domainSecurityPrincipalName);
                }
            }

            var distinguishedName = DistinguishedName.TryParse(name);

            if (distinguishedName != null)
            {
                return(new DomainSecurityPrincipalName(distinguishedName.DomainDnsName, distinguishedName));
            }

            var securityPrincipalName = SecurityPrincipalName.TryParse(name);

            return(securityPrincipalName == null
                ? null
                : new DomainSecurityPrincipalName(null, securityPrincipalName));
        }
示例#2
0
 public static DomainSecurityPrincipalName TryParse(string domainName, string name)
 {
     return(name.IsNullOrWhiteSpace()
         ? null
         : domainName.IsNullOrWhiteSpace()
             ? TryParse(name)
             : new DomainSecurityPrincipalName(NetworkName.TryParse(domainName), SecurityPrincipalName.TryParse(name)));
 }