Skip to content

Instantly share code, notes, and snippets.

@islaytitans
Last active January 19, 2016 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save islaytitans/d77e9a3cf48c0e6266dc to your computer and use it in GitHub Desktop.
Save islaytitans/d77e9a3cf48c0e6266dc to your computer and use it in GitHub Desktop.
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