object ICustomTextConverter.Parse(Type deservedType, string s, IFormatProvider provider) { if (deservedType != typeof(MultiValuedProperty <SmtpDomainWithSubdomains>)) { throw new NotSupportedException(); } if (string.IsNullOrEmpty(s)) { throw new FormatException(Strings.ValueCanNotBeEmpty); } MultiValuedProperty <SmtpDomainWithSubdomains> multiValuedProperty = new MultiValuedProperty <SmtpDomainWithSubdomains>(); foreach (string text in s.Split(new char[] { ',' })) { if (!string.IsNullOrEmpty(text)) { SmtpDomainWithSubdomains smtpDomainWithSubdomains = SmtpDomainWithSubdomains.Parse(text); if (SmtpDomainWithSubdomains.StarDomain.Equals(smtpDomainWithSubdomains)) { throw new FormatException(Strings.DisallowStarDomainConstraintText); } if (!multiValuedProperty.Contains(smtpDomainWithSubdomains)) { multiValuedProperty.Add(smtpDomainWithSubdomains); } } } return(multiValuedProperty); }
public static void Convert(DataRow dataRow) { foreach (object obj in dataRow.Table.Columns) { DataColumn dataColumn = (DataColumn)obj; Type type = dataColumn.ExtendedProperties["ExpectedType"] as Type; string text = dataRow[dataColumn] as string; if (type != null && dataRow[dataColumn].GetType() != type && text != null) { if (type == typeof(Unlimited <int>)) { dataRow[dataColumn] = Unlimited <int> .Parse(text); } else if (type == typeof(Unlimited <EnhancedTimeSpan>)) { dataRow[dataColumn] = Unlimited <EnhancedTimeSpan> .Parse(text); } else if (type == typeof(EmailAddressPolicyPriority)) { dataRow[dataColumn] = EmailAddressPolicyPriority.Parse(text); } else if (type == typeof(SmtpDomainWithSubdomains)) { dataRow[dataColumn] = SmtpDomainWithSubdomains.Parse(text); } else if (type == typeof(SmtpAddress)) { dataRow[dataColumn] = SmtpAddress.Parse(text); } else if (type == typeof(ProxyAddress)) { dataRow[dataColumn] = ProxyAddress.Parse(text); } else if (type == typeof(MailboxId)) { dataRow[dataColumn] = MailboxId.Parse(text); } else if (type == typeof(UMLanguage)) { dataRow[dataColumn] = UMLanguage.Parse(text); } else { if (!(type == typeof(ExchangeObjectVersion))) { throw new ArgumentException(string.Format("Type {0} is not supported convert from string yet", type)); } Regex regex = new Regex("^(?<Major>\\d+)\\.(?<Minor>\\d+) \\((?<buildMajor>\\d+)\\.(?<buildMinor>\\d+)\\.(?<buildVersion>\\d+)\\.(?<buildRevison>\\d+)\\)$"); Match match = regex.Match(text); if (!match.Success) { throw new ArgumentException(string.Format("{0} is not a valid ExchangeObjectVersion", text)); } dataRow[dataColumn] = new ExchangeObjectVersion(byte.Parse(match.Result("${Major}")), byte.Parse(match.Result("${Minor}")), byte.Parse(match.Result("${buildMajor}")), byte.Parse(match.Result("${buildMinor}")), ushort.Parse(match.Result("${buildVersion}")), ushort.Parse(match.Result("${buildRevison}"))); } } } }
protected static object GetSingleProperty(object prop, Type type) { if (prop == null) { return(null); } object obj = null; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { obj = MockObjectCreator.GetSingleProperty(prop, type.GetGenericArguments()[0]); } else if (type == typeof(ADObjectId) && prop is PSObject) { obj = new ADObjectId(((PSObject)prop).Members["DistinguishedName"].Value.ToString(), new Guid(((PSObject)prop).Members["ObjectGuid"].Value.ToString())); } else if (type == typeof(EnhancedTimeSpan)) { obj = EnhancedTimeSpan.Parse(prop.ToString()); } else if (type == typeof(Unlimited <EnhancedTimeSpan>)) { obj = Unlimited <EnhancedTimeSpan> .Parse(prop.ToString()); } else if (type == typeof(ByteQuantifiedSize)) { obj = ByteQuantifiedSize.Parse(prop.ToString()); } else if (type == typeof(Unlimited <ByteQuantifiedSize>)) { obj = Unlimited <ByteQuantifiedSize> .Parse(prop.ToString()); } else if (type == typeof(Unlimited <int>)) { obj = Unlimited <int> .Parse(prop.ToString()); } else if (type == typeof(ProxyAddress)) { obj = ProxyAddress.Parse(prop.ToString()); } else if (type == typeof(SmtpAddress)) { obj = new SmtpAddress(prop.ToString()); } else if (type == typeof(SmtpDomain)) { obj = SmtpDomain.Parse(prop.ToString()); } else if (type == typeof(CountryInfo)) { obj = CountryInfo.Parse(prop.ToString()); } else if (type == typeof(SharingPolicyDomain)) { obj = SharingPolicyDomain.Parse(prop.ToString()); } else if (type == typeof(ApprovedApplication)) { obj = ApprovedApplication.Parse(prop.ToString()); } else if (type == typeof(SmtpDomainWithSubdomains)) { obj = SmtpDomainWithSubdomains.Parse(prop.ToString()); } else if (type == typeof(UMLanguage)) { obj = UMLanguage.Parse(prop.ToString()); } else if (type == typeof(UMSmartHost)) { obj = UMSmartHost.Parse(prop.ToString()); } else if (type == typeof(ScheduleInterval)) { obj = ScheduleInterval.Parse(prop.ToString()); } else if (type == typeof(NumberFormat)) { obj = NumberFormat.Parse(prop.ToString()); } else if (type == typeof(DialGroupEntry)) { obj = DialGroupEntry.Parse(prop.ToString()); } else if (type == typeof(CustomMenuKeyMapping)) { obj = CustomMenuKeyMapping.Parse(prop.ToString()); } else if (type == typeof(HolidaySchedule)) { obj = HolidaySchedule.Parse(prop.ToString()); } else if (type == typeof(UMTimeZone)) { obj = UMTimeZone.Parse(prop.ToString()); } else if (type == typeof(ServerVersion)) { obj = ServerVersion.ParseFromSerialNumber(prop.ToString()); } else if (type == typeof(X509Certificate2)) { obj = new X509Certificate2(((PSObject)prop).Members["RawData"].Value as byte[]); } else if (type == typeof(LocalizedString)) { obj = new LocalizedString(prop.ToString()); } else if (type == typeof(ExchangeObjectVersion)) { obj = ExchangeObjectVersion.Parse(prop.ToString()); } else if (type == typeof(bool)) { obj = bool.Parse(prop.ToString()); } else if (type == typeof(SecurityPrincipalIdParameter)) { obj = new SecurityPrincipalIdParameter(prop.ToString()); } else if (type == typeof(ActiveDirectoryAccessRule)) { obj = (prop as ActiveDirectoryAccessRule); } else if (type == typeof(ObjectId)) { string text = prop.ToString(); if (!ADObjectId.IsValidDistinguishedName(text) && text.Contains("/")) { text = MockObjectCreator.ConvertDNFromTreeStructure(text); } obj = new ADObjectId(text); } else if (type.IsEnum) { try { obj = Enum.Parse(type, prop.ToString()); } catch (ArgumentException) { obj = Enum.GetValues(type).GetValue(0); } } return(obj ?? prop); }