Example #1
0
 public void Reset()
 {
     Monitor.Enter(_syncRoot);
     try
     {
         _innerEnumerator.Reset();
         _current = null;
         _entry   = null;
     }
     finally { Monitor.Exit(_syncRoot); }
 }
Example #2
0
        private object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee)
        {
            DictionaryEntry?nullable = null;

            if (extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
            {
                nullable = new DictionaryEntry?((DictionaryEntry)extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)]);
            }
            if (nullable.HasValue && (nullable.Value.Value == extendee))
            {
                return(nullable.Value.Key);
            }
            return(null);
        }
 internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee)
 {
     List<ExtendedPropertyInfo> list = new List<ExtendedPropertyInfo>();
     DictionaryEntry? nullable = null;
     if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
     {
         nullable = new DictionaryEntry?((DictionaryEntry) manager.WorkflowMarkupStack[typeof(DictionaryEntry)]);
     }
     if (this.deserializingDictionary || (nullable.HasValue && (nullable.Value.Value == extendee)))
     {
         ExtendedPropertyInfo item = new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance), new GetValueHandler(this.OnGetKeyValue), new SetValueHandler(this.OnSetKeyValue), new GetQualifiedNameHandler(this.OnGetXmlQualifiedName), manager);
         list.Add(item);
     }
     return list.ToArray();
 }
Example #4
0
 public bool MoveNext()
 {
     Monitor.Enter(_syncRoot);
     try
     {
         if (!_innerEnumerator.MoveNext())
         {
             return(false);
         }
         _current = null;
         _entry   = null;
     }
     finally { Monitor.Exit(_syncRoot); }
     return(true);
 }
Example #5
0
        internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee)
        {
            List <ExtendedPropertyInfo> list     = new List <ExtendedPropertyInfo>();
            DictionaryEntry?            nullable = null;

            if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
            {
                nullable = new DictionaryEntry?((DictionaryEntry)manager.WorkflowMarkupStack[typeof(DictionaryEntry)]);
            }
            if (this.deserializingDictionary || (nullable.HasValue && (nullable.Value.Value == extendee)))
            {
                ExtendedPropertyInfo item = new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance), new GetValueHandler(this.OnGetKeyValue), new SetValueHandler(this.OnSetKeyValue), new GetQualifiedNameHandler(this.OnGetXmlQualifiedName), manager);
                list.Add(item);
            }
            return(list.ToArray());
        }
        private object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee)
        {
            DictionaryEntry?entry = null;

            if (extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
            {
                entry = (DictionaryEntry)extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)];
            }
            else
            {
                Debug.Assert(false, "Dictionary Entry not found in the WorkflowMarkupStack");
            }

            if (entry.HasValue && entry.Value.Value == extendee)
            {
                return(entry.Value.Key);
            }
            return(null);
        }
Example #7
0
        private IDictionary CastDict(IDictionary dictionary, Type[] types)
        {
            DictionaryEntry?typeDef = null;

            foreach (DictionaryEntry item in dictionary)
            {
                typeDef = item;
                break;
            }
            if (typeDef.IsInstance())
            {
                var dic = (IDictionary)ActivatorFactory.Activator.ActivateWithExternalGenerics(typeof(Dictionary <object, object>).GetGenericTypeDefinition(), types);
                foreach (DictionaryEntry val in dictionary)
                {
                    dic.Add(val.Key.Convert(Rule.Parent.GetRule(val.Key.GetType(), types[0])), val.Value);
                }
                return(dic);
            }
            return(null);
        }
Example #8
0
        public void FromXML(XmlReader reader)
        {
            Dictionary.Clear();
            if (reader.IsStartElement("Attributes"))
            {
                reader.ReadStartElement("Attributes");

                DictionaryEntry?de = null;
                while (reader.IsStartElement("item"))
                {
                    de = GetItem(reader);
                    if (de.HasValue)
                    {
                        Dictionary.Add(de.Value.Key, de.Value.Value);
                    }
                }

                reader.ReadEndElement();
            }
        }
        internal override ExtendedPropertyInfo[] GetExtendedProperties(WorkflowMarkupSerializationManager manager, object extendee)
        {
            List <ExtendedPropertyInfo> extendedProperties = new List <ExtendedPropertyInfo>();
            DictionaryEntry?            entry = null;

            if (manager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
            {
                entry = (DictionaryEntry)manager.WorkflowMarkupStack[typeof(DictionaryEntry)];
            }
            if (this.deserializingDictionary || (entry.HasValue && entry.Value.Value == extendee))
            {
                ExtendedPropertyInfo extendedProperty =
                    new ExtendedPropertyInfo(typeof(DictionaryEntry).GetProperty("Key", BindingFlags.Public | BindingFlags.Instance),
                                             new GetValueHandler(OnGetKeyValue),
                                             new SetValueHandler(OnSetKeyValue),
                                             new GetQualifiedNameHandler(OnGetXmlQualifiedName), manager);

                extendedProperties.Add(extendedProperty);
            }
            return(extendedProperties.ToArray());
        }
Example #10
0
        public static bool Convert(object val, Type targetType, out object result)
        {
            result = val;
            // Trivial cases
            if (val == null)
            {
                // Cannot convert null to value type
                return(!targetType.IsValueType);
            }
            if (targetType.IsAssignableFrom(val.GetType()))
            {
                return(true);
            }

            // Custom type conversions

            if (_customTypeConverter != null)
            {
                if (_customTypeConverter(val, targetType, out result))
                {
                    return(true);
                }
            }

            // TODO: typeof(Nullable<T>)

            // Built-in type conversions

            if (val.GetType() == typeof(string) && targetType == typeof(Type))
            { // string -> Type
                result = Type.GetType(val.ToString());
                return(result != null);
            }

            // Enumerations
            if (val.GetType() == typeof(string) && targetType.IsEnum)
            { // string -> Enum
                result = Enum.Parse(targetType, (string)val);
                return(true);
            }

            // String target type must be done before enumerations are tried - else, the string will be treated as enumeration
            if (targetType.IsAssignableFrom(typeof(string)))
            { // * -> string
                result = val.ToString();
                return(true);
            }

            // Collection types

            Type enumerableType;
            Type entryType;

            ReflectionHelper.FindImplementedEnumerableType(targetType, out enumerableType, out entryType);

            if (enumerableType != null) // Targets IList, ICollection, IList<>, ICollection<>
            {
                ICollection col;
                if (!ToCollection(val, entryType, out col))
                {
                    return(false);
                }
                List <object> resultList = col.Cast <object>().ToList();
                result = resultList;
                return(true);
            }
            ICollection sourceCol = val as ICollection;

            if (sourceCol != null && sourceCol.Count == 1) // From collection to non-collection target
            {
                // Use the first (single) item of a collection or dictionary
                IEnumerator enumerator = sourceCol.GetEnumerator();
                enumerator.MoveNext();
                object item = enumerator.Current;
                if (Convert(item, targetType, out result)) // Single collection item
                {
                    return(true);
                }
                KeyValuePair <object, object>?kvp = item as KeyValuePair <object, object>?;
                if (kvp.HasValue && Convert(kvp.Value.Value, targetType, out result)) // Value of single dictionary entry - generic dictionary
                {
                    IDisposable d = kvp.Value.Key as IDisposable;
                    if (d != null)
                    {
                        d.Dispose();
                    }
                    return(true);
                }
                DictionaryEntry?entry = item as DictionaryEntry?;
                if (entry.HasValue && Convert(entry.Value.Value, targetType, out result)) // Value of single dictionary entry - legacy dictionary
                {
                    IDisposable d = entry.Value.Key as IDisposable;
                    if (d != null)
                    {
                        d.Dispose();
                    }
                    return(true);
                }
            }

            // Simple type conversions

            System.ComponentModel.TypeConverter tc = TypeDescriptor.GetConverter(targetType);
            if (tc != null && tc.CanConvertFrom(val.GetType()))
            {
                try
                {
                    result = tc.ConvertFrom(null, CultureInfo.InvariantCulture, val);
                    return(true);
                }
                catch { }
            }

            tc = TypeDescriptor.GetConverter(val);
            if (tc != null && tc.CanConvertTo(targetType))
            {
                result = tc.ConvertTo(val, targetType);
                return(true);
            }

            return(false);
        }
 /// <summary>
 /// This method is for constructing continuous path without gaps using a list of elements as input parameter.
 /// Every element of a list consists of a pair: start point and destination point.
 /// In case of impossibility of construction such path ArgumentException will be thrown.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public List <Tuple <string, string> > ConstructPath(List <Tuple <string, string> > input)
 {
     try
     {
         if (input == null)
         {
             throw new ArgumentNullException("Input list is null");
         }
         Hashtable table         = new Hashtable();
         Hashtable reverse_table = new Hashtable();
         foreach (var it in input)
         {
             if (it.Item1 == null)
             {
                 throw new ArgumentException(String.Format("First item is null first: {0},  second: {1}", it.Item1, it.Item2));
             }
             else if (it.Item1 == "")
             {
                 throw new ArgumentException(String.Format("First item is empty first: {0},  second: {1}", it.Item1, it.Item2));
             }
             else if (it.Item2 == null)
             {
                 throw new ArgumentException(String.Format("Second item is null first: {0},  second: {1}", it.Item1, it.Item2));
             }
             else if (it.Item2 == "")
             {
                 throw new ArgumentException(String.Format("Second item is empty first: {0},  second: {1}", it.Item1, it.Item2));
             }
             else if (table.ContainsKey(it.Item1) && !reverse_table.ContainsKey(it.Item2))
             {
                 throw new ArgumentException(String.Format("Branching paths at first item was found. Branch point is {0}", it.Item1));
             }
             else if (!table.ContainsKey(it.Item1) && reverse_table.ContainsKey(it.Item2))
             {
                 throw new ArgumentException(String.Format("Branching paths at second item was found. Branch point is {0}", it.Item2));
             }
             else if (table.ContainsKey(it.Item1) || reverse_table.ContainsKey(it.Item2))
             {
                 continue;
             }
             else
             {
                 table.Add(it.Item1, it.Item2);
                 reverse_table.Add(it.Item2, it.Item1);
             }
         }
         DictionaryEntry?begin          = null;
         bool            wasBeginBefore = false;
         foreach (DictionaryEntry it in table)
         {
             if (!reverse_table.Contains(it.Key))
             {
                 if (wasBeginBefore)
                 {
                     throw new ArgumentException("More than one begin points were found");;
                 }
                 else
                 {
                     begin          = it;
                     wasBeginBefore = true;
                 }
             }
         }
         if (begin.HasValue)
         {
             List <Tuple <string, string> > result = new List <Tuple <string, string> >();
             string next_point = begin.Value.Key.ToString();
             while (table.Contains(next_point))
             {
                 result.Add(new Tuple <string, string>(next_point, table[next_point].ToString()));
                 next_point = table[next_point].ToString();
             }
             return(result);
         }
         else
         {
             throw new ArgumentException("Begin point wasn't found");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void Reset()
 {
     _current = null;
     _entry   = null;
     _innerEnumerator.Reset();
 }
 public bool MoveNext()
 {
     _current = null;
     _entry   = null;
     return(MoveNext());
 }
 public void Dispose()
 {
     _innerEnumerator.Dispose();
     _current = null;
     _entry   = null;
 }
 /// <summary>
 /// This method is for constructing continuous path without gaps using a list of elements as input parameter.
 /// Every element of a list consists of a pair: start point and destination point.
 /// In case of impossibility of construction such path null will be retrurned.
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public List <Tuple <string, string> > ConstructPath(List <Tuple <string, string> > input)
 {
     try
     {
         if (input == null)
         {
             return(null);
         }
         Hashtable table         = new Hashtable();
         Hashtable reverse_table = new Hashtable();
         foreach (var it in input)
         {
             if (it.Item1 == null)
             {
                 return(null);
             }
             else if (it.Item1 == "")
             {
                 return(null);
             }
             else if (it.Item2 == null)
             {
                 return(null);
             }
             else if (it.Item2 == "")
             {
                 return(null);
             }
             else if (table.ContainsKey(it.Item1) && !reverse_table.ContainsKey(it.Item2))
             {
                 return(null);
             }
             else if (!table.ContainsKey(it.Item1) && reverse_table.ContainsKey(it.Item2))
             {
                 return(null);
             }
             else if (table.ContainsKey(it.Item1) || reverse_table.ContainsKey(it.Item2))
             {
                 continue;
             }
             else
             {
                 table.Add(it.Item1, it.Item2);
                 reverse_table.Add(it.Item2, it.Item1);
             }
         }
         DictionaryEntry?begin          = null;
         bool            wasBeginBefore = false;
         foreach (DictionaryEntry it in table)
         {
             if (!reverse_table.Contains(it.Key))
             {
                 if (wasBeginBefore)
                 {
                     return(null);
                 }
                 else
                 {
                     begin          = it;
                     wasBeginBefore = true;
                 }
             }
         }
         if (begin.HasValue)
         {
             List <Tuple <string, string> > result = new List <Tuple <string, string> >();
             string next_point = begin.Value.Key.ToString();
             while (table.Contains(next_point))
             {
                 result.Add(new Tuple <string, string>(next_point, table[next_point].ToString()));
                 next_point = table[next_point].ToString();
             }
             return(result);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
 private object OnGetKeyValue(ExtendedPropertyInfo extendedProperty, object extendee)
 {
     DictionaryEntry? nullable = null;
     if (extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)] != null)
     {
         nullable = new DictionaryEntry?((DictionaryEntry) extendedProperty.SerializationManager.WorkflowMarkupStack[typeof(DictionaryEntry)]);
     }
     if (nullable.HasValue && (nullable.Value.Value == extendee))
     {
         return nullable.Value.Key;
     }
     return null;
 }
Example #17
0
 public bool MoveNext()
 {
     entry = null;
     return(fields.MoveNext());
 }