Skip to content

Instantly share code, notes, and snippets.

@islaytitans

islaytitans/MergeContactFacets.cs Secret

Last active Jan 19, 2016
Embed
What would you like to do?
How to merge custom Contact Facets
public static void DeepCopyFacet(IFacet source, IFacet destination)
{
Assert.ArgumentNotNull((object)source, "source");
Assert.ArgumentNotNull((object)destination, "destination");
CopyElement((IElement)source, (IElement)destination);
}
private static void CopyElement(IElement source, IElement destination)
{
foreach (IModelMember modelMember in (IEnumerable<IModelMember>)source.Members)
{
IModelAttributeMember modelAttributeMember = modelMember as IModelAttributeMember;
if (modelAttributeMember != null)
{
((IModelAttributeMember)destination.Members[modelMember.Name]).Value
= modelAttributeMember.Value;
}
else
{
IModelDictionaryMember dictionaryMember1 = modelMember as IModelDictionaryMember;
if (dictionaryMember1 != null)
{
IModelDictionaryMember dictionaryMember2
= (IModelDictionaryMember)destination.Members[modelMember.Name];
foreach (string key in (IEnumerable<string>)dictionaryMember1.Elements.Keys)
{
IElement destination1 = dictionaryMember2.Elements.Create(key);
CopyElement(dictionaryMember1.Elements[key], destination1);
}
}
else
{
IModelCollectionMember collectionMember1 = modelMember as IModelCollectionMember;
if (collectionMember1 != null)
{
IModelCollectionMember collectionMember2
= (IModelCollectionMember)destination.Members[modelMember.Name];
for (int index = 0; index < collectionMember1.Elements.Count; ++index)
{
IElement destination1 = collectionMember2.Elements.Create();
CopyElement(collectionMember1.Elements[index], destination1);
}
}
else
{
IModelElementMember modelElementMember1 = modelMember as IModelElementMember;
if (modelElementMember1 != null)
{
IModelElementMember modelElementMember2
= (IModelElementMember)destination.Members[modelElementMember1.Name];
CopyElement(modelElementMember1.Element, modelElementMember2.Element);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment