/// <summary>
/// Finds the attributes in connector object and rename it according to input array of names, but only
/// if the atribute name is in attributes to get
/// </summary>
/// <param name="cobject">ConnectorObject which attributes should be replaced</param>
/// <param name="attsToGet">Attributes to get list</param>
/// <param name="map">Replace mapping</param>
/// <returns>ConnectorObject with replaced attributes</returns>
/// <exception cref="ArgumentNullException">If some of the params is null</exception>
internal static ConnectorObject ReplaceAttributes(ConnectorObject cobject, ICollection<string> attsToGet, IDictionary<string, string> map)
{
Assertions.NullCheck(cobject, "cobject");
Assertions.NullCheck(map, "map");
if (attsToGet == null)
{
return cobject;
}
var attributes = cobject.GetAttributes();
var builder = new ConnectorObjectBuilder();
foreach (ConnectorAttribute attribute in attributes)
{
string newName;
if (map.TryGetValue(attribute.Name, out newName) && attsToGet.Contains(newName))
{
var newAttribute = RenameAttribute(attribute, newName);
builder.AddAttribute(newAttribute);
break;
}
builder.AddAttribute(attribute);
}
builder.AddAttributes(attributes);
builder.ObjectClass = cobject.ObjectClass;
builder.SetName(cobject.Name);
builder.SetUid(cobject.Uid);
return builder.Build();
}