Beispiel #1
0
 /// <summary>
 /// If the attribute of the given name of the given element is a container attribute
 /// then return a clone of the given container value, otherwise just return the original value;
 /// additionally returns the AttributeType of the attribute of the element.
 /// </summary>
 public static object IfAttributeOfElementIsContainerThenCloneContainer(
     IObject element, String AttributeName, object value, out AttributeType attrType)
 {
     attrType = element.Type.GetAttributeType(AttributeName);
     if (attrType.Kind == AttributeKind.SetAttr || attrType.Kind == AttributeKind.MapAttr)
     {
         Type keyType, valueType;
         ContainerHelper.GetDictionaryTypes(element.GetAttribute(AttributeName), out keyType, out valueType);
         return(ContainerHelper.NewDictionary(keyType, valueType, value)); // by-value-semantics -> clone dictionary
     }
     else if (attrType.Kind == AttributeKind.ArrayAttr)
     {
         Type valueType;
         ContainerHelper.GetListType(element.GetAttribute(AttributeName), out valueType);
         return(ContainerHelper.NewList(valueType, value)); // by-value-semantics -> clone array
     }
     else if (attrType.Kind == AttributeKind.DequeAttr)
     {
         Type valueType;
         ContainerHelper.GetDequeType(element.GetAttribute(AttributeName), out valueType);
         return(ContainerHelper.NewDeque(valueType, value)); // by-value-semantics -> clone deque
     }
     return(value);
 }