public static ADRawEntry CreateFrom(SimpleADObject simpleADObject, IEnumerable <PropertyDefinition> properties) { ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject); ArgumentValidator.ThrowIfNull("properties", properties); ADPropertyBag adpropertyBag = new ADPropertyBag(); SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties2 = simpleADObject.Properties; SimpleADObject.SimpleADProperty simpleADProperty; if (!properties2.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty)) { throw new InvalidOperationException("dn is missing"); } ValidationError validationError; ADObjectId value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError); adpropertyBag.SetField(ADObjectSchema.Id, value); foreach (PropertyDefinition propertyDefinition in properties) { ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition; SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties2); } adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState); adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion); return(new ADRawEntry(adpropertyBag) { OriginatingServer = simpleADObject.OriginatingServer, WhenReadUTC = new DateTime?(simpleADObject.WhenReadUTC), DirectoryBackendType = simpleADObject.DirectoryBackendType, IsCached = true }); }
public static TObject CreateFrom <TObject>(SimpleADObject simpleADObject, ADObjectSchema schema, IEnumerable <PropertyDefinition> additionalProperties) where TObject : ADRawEntry, new() { ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject); if (typeof(TObject).Equals(typeof(ADRawEntry))) { throw new ArgumentException("TObject cannot be ADRawEntry"); } ADPropertyBag adpropertyBag = new ADPropertyBag(); SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties = simpleADObject.Properties; SimpleADObject.SimpleADProperty simpleADProperty; if (!properties.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty)) { throw new InvalidOperationException("dn is missing"); } ValidationError validationError; ADObjectId value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError); adpropertyBag.SetField(ADObjectSchema.Id, value); adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState); adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion); TObject tobject = Activator.CreateInstance <TObject>(); IEnumerable <PropertyDefinition> enumerable; if (schema != null) { enumerable = schema.AllProperties; } else { enumerable = ((ADObject)((object)tobject)).Schema.AllProperties; } if (additionalProperties != null) { enumerable = enumerable.Concat(additionalProperties); } foreach (PropertyDefinition propertyDefinition in enumerable) { ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition; SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties); } if (tobject is MiniObject) { adpropertyBag.SetIsReadOnly(true); } if (schema != null || (!(tobject is ADRecipient) && !(tobject is MiniRecipient))) { tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeConfigObject <TObject>(adpropertyBag, tobject, null)); } else { tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeRecipientObject <TObject>(adpropertyBag, tobject, null)); } tobject.OriginatingServer = simpleADObject.OriginatingServer; tobject.WhenReadUTC = new DateTime?(simpleADObject.WhenReadUTC); tobject.DirectoryBackendType = simpleADObject.DirectoryBackendType; tobject.IsCached = true; tobject.ValidateRead(); tobject.ResetChangeTracking(); return(tobject); }