示例#1
0
        /////////////////////////////////////////////////////////////////////////////////

        public static void AssignAttribute(object target, object value, string attributeName, IGraph graph)
        {
            if (target is IGraphElement)
            {
                IGraphElement elem = (IGraphElement)target;

                AttributeType attrType;
                value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer(
                    elem, attributeName, value, out attrType);

                BaseGraph.ChangingAttributeAssign(graph, elem, attrType, value);

                elem.SetAttribute(attributeName, value);

                BaseGraph.ChangedAttribute(graph, elem, attrType);
            }
            else if (target is IObject)
            {
                IObject elem = (IObject)target;

                AttributeType attrType = elem.Type.GetAttributeType(attributeName);

                BaseGraph.ChangingAttributeAssign(graph, elem, attrType, value);

                elem.SetAttribute(attributeName, value);
            }
            else //if(target is ITransientObject)
            {
                ITransientObject elem = (ITransientObject)target;

                elem.SetAttribute(attributeName, value);
            }
        }
示例#2
0
 public static bool IsEqual(ITransientObject this_, ITransientObject that)
 {
     if (this_ == that)
     {
         return(true);
     }
     return(this_.AreAttributesEqual(that));
 }
示例#3
0
        public long GetUniqueId(ITransientObject transientObject)
        {
            if (transientObject == null)
            {
                return(-1);
            }

            if (!transientObjectToUniqueId.ContainsKey(transientObject))
            {
                long uniqueId = FetchTransientObjectUniqueId();
                transientObjectToUniqueId[transientObject] = uniqueId;
                uniqueIdToTransientObject[uniqueId]        = transientObject;
            }
            return(transientObjectToUniqueId[transientObject]);
        }
示例#4
0
        private static string ToString(ITransientObject value, IGraph graph, bool firstLevelObjectEmitted,
                                       IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb = new StringBuilder();
            string        transientObjectType = value.Type.PackagePrefixedName;

            sb.Append(transientObjectType);
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("{");
            }
            bool first = true;

            if (procEnv != null)
            {
                sb.Append("&:" + procEnv.GetUniqueId(value));
                first = false;
            }
            if (!firstLevelObjectEmitted)
            {
                foreach (AttributeType attrType in value.Type.AttributeTypes)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(attrType.Name);
                    sb.Append(":");
                    sb.Append(EmitHelper.ToStringAutomatic(value.GetAttribute(attrType.Name), graph, true,
                                                           nameToObject, procEnv));
                }
            }
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("}");
            }
            return(sb.ToString());
        }
示例#5
0
        public static IDictionary Copy(IDictionary dictionary, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Type keyType;
            Type valueType;
            Type dictType = dictionary.GetType();

            GetDictionaryTypes(dictType, out keyType, out valueType);
            IDictionary copy = NewDictionary(keyType, valueType);

            foreach (DictionaryEntry element in dictionary)
            {
                object key   = element.Key;
                object value = element.Value;

                if (key is IObject)
                {
                    IObject elem = (IObject)key;
                    key = elem.Copy(graph, oldToNewObjects);
                }
                else if (key is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)key;
                    key = elem.Copy(graph, oldToNewObjects);
                }

                if (value is IObject)
                {
                    IObject elem = (IObject)value;
                    value = elem.Copy(graph, oldToNewObjects);
                }
                else if (value is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)value;
                    value = elem.Copy(graph, oldToNewObjects);
                }

                copy.Add(key, value);
            }

            return(copy);
        }
示例#6
0
        public static Deque <T> Copy <T>(Deque <T> deque, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Deque <T> copy = new Deque <T>();

            foreach (T element in deque)
            {
                if (element is IObject)
                {
                    IObject elem = (IObject)element;
                    copy.Add((T)elem.Copy(graph, oldToNewObjects));
                }
                else if (element is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)element;
                    copy.Add((T)elem.Copy(graph, oldToNewObjects));
                }
                else
                {
                    copy.Add(element);
                }
            }

            return(copy);
        }
示例#7
0
        public static IDeque Copy(IDeque deque, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            IDeque copy = (IDeque)Activator.CreateInstance(deque.GetType());

            foreach (object element in deque)
            {
                if (element is IObject)
                {
                    IObject elem = (IObject)element;
                    copy.Add(elem.Copy(graph, oldToNewObjects));
                }
                else if (element is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)element;
                    copy.Add(elem.Copy(graph, oldToNewObjects));
                }
                else
                {
                    copy.Add(element);
                }
            }

            return(copy);
        }
示例#8
0
        public static Dictionary <K, V> Copy <K, V>(Dictionary <K, V> dictionary, IGraph graph, IDictionary <IBaseObject, IBaseObject> oldToNewObjects)
        {
            Dictionary <K, V> copy = new Dictionary <K, V>();

            foreach (KeyValuePair <K, V> element in dictionary)
            {
                K key   = element.Key;
                V value = element.Value;

                if (key is IObject)
                {
                    IObject elem = (IObject)key;
                    key = (K)elem.Copy(graph, oldToNewObjects);
                }
                else if (key is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)key;
                    key = (K)elem.Copy(graph, oldToNewObjects);
                }

                if (value is IObject)
                {
                    IObject elem = (IObject)value;
                    value = (V)elem.Copy(graph, oldToNewObjects);
                }
                else if (value is ITransientObject)
                {
                    ITransientObject elem = (ITransientObject)value;
                    value = (V)elem.Copy(graph, oldToNewObjects);
                }

                copy.Add(key, value);
            }

            return(copy);
        }
示例#9
0
        public static void AssignAttributeIndexed(object target, object key, object value, string attributeName, IGraph graph)
        {
            if (target is IGraphElement)
            {
                IGraphElement elem      = (IGraphElement)target;
                object        container = elem.GetAttribute(attributeName);
                AttributeType attrType  = elem.Type.GetAttributeType(attributeName);

                BaseGraph.ChangingAttributeAssignElement(graph, elem, attrType, value, key);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }

                BaseGraph.ChangedAttribute(graph, elem, attrType);
            }
            else if (target is IObject)
            {
                IObject       elem      = (IObject)target;
                object        container = elem.GetAttribute(attributeName);
                AttributeType attrType  = elem.Type.GetAttributeType(attributeName);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }
            }
            else
            {
                ITransientObject elem      = (ITransientObject)target;
                object           container = elem.GetAttribute(attributeName);
                AttributeType    attrType  = elem.Type.GetAttributeType(attributeName);

                if (container is IList)
                {
                    IList array = (IList)container;
                    array[(int)key] = value;
                }
                else if (container is IDeque)
                {
                    IDeque deque = (IDeque)container;
                    deque[(int)key] = value;
                }
                else
                {
                    IDictionary map = (IDictionary)container;
                    map[key] = value;
                }
            }
        }
示例#10
0
 /// <summary>
 /// Creates a transient object according to this type and copies all
 /// common attributes from the given transient object.
 /// </summary>
 /// <param name="oldValue">The old value.</param>
 /// <returns>The created object.</returns>
 public abstract ITransientObject CreateTransientObjectWithCopyCommons(ITransientObject oldValue);