Exemple #1
0
 public EnumValueTypeConverter(EnumValueCollection instance)
 {
     if (instance == null)
     {
         throw new ArgumentNullException();
     }
     m_instance = instance;
 }
        public EnumValueDescriptionProvider(EnumValueCollection instance)
        {
            if (instance == null)
                throw new ArgumentNullException("instance");

            m_instance = instance;
            m_instanceDescriptor = new EnumValueDescriptor(m_instance);
        }
Exemple #3
0
        public EnumValueDescriptionProvider(EnumValueCollection instance)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            m_instance           = instance;
            m_instanceDescriptor = new EnumValueDescriptor(m_instance);
        }
 internal EnumValueCollection(EnumValueCollection other)
 {
     m_possibleValues = new List<EnumValue>();
     foreach(EnumValue val in other.m_possibleValues)
     {
         EnumValue newVal = new EnumValue();
         newVal.Value = val.Value;
         m_possibleValues.Add(newVal);
     }
     m_currentValue = GetValue(other.m_currentValue);
     m_sourceEnum = other.m_sourceEnum;
 }
 public ConfigPropertyObject(string name, object value, Type type, string displayName = null, string descripton = null) :
     this(name, value, type.FullName, type.GetTraceLabQualifiedName(), type.IsEnum, displayName, descripton, true)
 {
     if (IsEnum)
     {
         m_value = string.Empty;
         var enumInfo = new EnumValueCollection(type);
         EnumInfo = enumInfo;
         TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
         Value = value.ToString();
     }
 }
 internal EnumValueCollection(EnumValueCollection other)
 {
     m_possibleValues = new List <EnumValue>();
     foreach (EnumValue val in other.m_possibleValues)
     {
         EnumValue newVal = new EnumValue();
         newVal.Value = val.Value;
         m_possibleValues.Add(newVal);
     }
     m_currentValue = GetValue(other.m_currentValue);
     m_sourceEnum   = other.m_sourceEnum;
 }
Exemple #7
0
 public ConfigPropertyObject(string name, object value, Type type, string displayName = null, string descripton = null) :
     this(name, value, type.FullName, type.GetTraceLabQualifiedName(), type.IsEnum, displayName, descripton, true)
 {
     if (IsEnum)
     {
         m_value = string.Empty;
         var enumInfo = new EnumValueCollection(type);
         EnumInfo = enumInfo;
         TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
         Value = value.ToString();
     }
 }
Exemple #8
0
 protected ConfigPropertyObject(SerializationInfo info, StreamingContext context)
 {
     m_name                  = (string)info.GetValue("m_name", typeof(string));
     m_displayName           = (string)info.GetValue("m_displayName", typeof(string));
     m_description           = (string)info.GetValue("m_description", typeof(string));
     m_value                 = (object)info.GetValue("m_value", typeof(object));
     m_type                  = (string)info.GetValue("m_type", typeof(string));
     m_assemblyQualifiedName = (string)info.GetValue("m_assemblyQualifiedName", typeof(string));
     m_visible               = (bool)info.GetValue("m_visible", typeof(bool));
     m_isEnum                = (bool)info.GetValue("m_isEnum", typeof(bool));
     if (m_isEnum)
     {
         m_enumInfo = (EnumValueCollection)info.GetValue("m_enumInfo", typeof(EnumValueCollection));
         TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
     }
 }
Exemple #9
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (m_instance == null)
            {
                throw new ArgumentException("Context's instance must be value.");
            }

            EnumValueCollection copy = new EnumValueCollection(m_instance);

            Type sourceEnum = Type.GetType(copy.SourceEnum);

            if (sourceEnum != null && sourceEnum == value.GetType())
            {
                value = value.ToString();
            }

            if (value != null && value.GetType() == typeof(string))
            {
                foreach (EnumValue possible in copy.PossibleValues)
                {
                    if (possible.Value.Equals(value as string, StringComparison.CurrentCultureIgnoreCase))
                    {
                        copy.CurrentValue = possible;
                        break;
                    }
                }
            }
            else if (value != null && value.GetType() == typeof(EnumValue))
            {
                EnumValue val = value as EnumValue;
                foreach (EnumValue possible in copy.PossibleValues)
                {
                    if (possible.Value.Equals(val.Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        copy.CurrentValue = possible;
                        break;
                    }
                }
            }

            TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(copy), copy);

            return(copy);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (m_instance == null)
            {
                throw new ArgumentException("Context's instance must be value.");
            }

            EnumValueCollection copy = new EnumValueCollection(m_instance);

            Type sourceEnum = Type.GetType(copy.SourceEnum);
            if (sourceEnum != null && sourceEnum == value.GetType())
            {
                value = value.ToString();
            }

            if (value != null && value.GetType() == typeof(string))
            {
                foreach (EnumValue possible in copy.PossibleValues)
                {
                    if (possible.Value.Equals(value as string, StringComparison.CurrentCultureIgnoreCase))
                    {
                        copy.CurrentValue = possible;
                        break;
                    }
                }
            }
            else if (value != null && value.GetType() == typeof(EnumValue))
            {
                EnumValue val = value as EnumValue;
                foreach (EnumValue possible in copy.PossibleValues)
                {
                    if (possible.Value.Equals(val.Value, StringComparison.CurrentCultureIgnoreCase))
                    {
                        copy.CurrentValue = possible;
                        break;
                    }
                }
            }

            TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(copy), copy);

            return copy;
        }
Exemple #11
0
        public ConfigPropertyObject(ConfigPropertyObject propertyObject)
        {
            Name  = String.Copy(propertyObject.Name);
            Value = ObjectCopier.Clone(propertyObject.Value);
            Type  = String.Copy(propertyObject.Type);
            AssemblyQualifiedName = String.Copy(propertyObject.AssemblyQualifiedName);
            DisplayName           = String.Copy(propertyObject.DisplayName);
            Description           = String.Copy(propertyObject.Description);
            Visible = propertyObject.Visible;
            IsEnum  = propertyObject.IsEnum;

            if (IsEnum)
            {
                var enumInfo = new EnumValueCollection(propertyObject.EnumInfo);
                EnumInfo = enumInfo;
                TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
                Value = propertyObject.Value.ToString();
            }
        }
Exemple #12
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">A <see cref="T:System.Globalization.CultureInfo"/>. If null is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="T:System.Object"/> to convert.</param>
        /// <param name="destinationType">The <see cref="T:System.Type"/> to convert the <paramref name="value"/> parameter to.</param>
        /// <returns>
        /// An <see cref="T:System.Object"/> that represents the converted value.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="destinationType"/> parameter is null. </exception>
        ///
        /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            EnumValueCollection instance = value as EnumValueCollection;

            if (m_instance != null)
            {
                instance = m_instance;
            }

            Type sourceEnum = Type.GetType(instance.SourceEnum);

            if (sourceEnum != null && sourceEnum == destinationType)
            {
                return(Enum.Parse(destinationType, instance.CurrentValue.Value));
            }
            else if (destinationType == typeof(string))
            {
                return(instance.CurrentValue);
            }

            return(null);
        }
 public EnumValueDescriptor(EnumValueCollection instance)
 {
     m_instance = instance;
     m_converter = new EnumValueTypeConverter(instance);
 }
 protected ConfigPropertyObject(SerializationInfo info, StreamingContext context)
 {
     m_name = (string)info.GetValue("m_name", typeof(string));
     m_displayName = (string)info.GetValue("m_displayName", typeof(string));
     m_description = (string)info.GetValue("m_description", typeof(string));
     m_value = (object)info.GetValue("m_value", typeof(object));
     m_type = (string)info.GetValue("m_type", typeof(string));
     m_assemblyQualifiedName = (string)info.GetValue("m_assemblyQualifiedName", typeof(string));
     m_visible = (bool)info.GetValue("m_visible", typeof(bool));
     m_isEnum = (bool)info.GetValue("m_isEnum", typeof(bool));
     if (m_isEnum)
     {
         m_enumInfo = (EnumValueCollection)info.GetValue("m_enumInfo", typeof(EnumValueCollection));
         TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
     }
 }
Exemple #15
0
 public EnumValueDescriptor(EnumValueCollection instance)
 {
     m_instance  = instance;
     m_converter = new EnumValueTypeConverter(instance);
 }
Exemple #16
0
        private void ReadVersion2(XPathNavigator nav)
        {
            //read name
            var iter = nav.SelectSingleNode("/PropertyObject/Name");

            if (iter == null)
            {
                throw new XmlSchemaException("Property Object does not contain the proper xml.");
            }

            Name = iter.Value;

            //read display name
            iter = nav.SelectSingleNode("/PropertyObject/DisplayName");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                DisplayName = iter.Value;
            }
            else
            {
                DisplayName = Name;
            }

            iter = nav.SelectSingleNode("/PropertyObject/Description");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                Description = iter.Value;
            }
            else
            {
                Description = String.Empty;
            }

            //read if visible
            iter    = nav.SelectSingleNode("/PropertyObject/Visible");
            Visible = true; //default
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                string visibleString = iter.Value;
                bool   tmpVisible;
                if (bool.TryParse(visibleString, out tmpVisible))
                {
                    Visible = tmpVisible;
                }
            }

            //read enum information
            iter = nav.SelectSingleNode("/PropertyObject/IsEnum");
            if (iter != null)
            {
                IsEnum = bool.Parse(iter.Value);
                if (IsEnum)
                {
                    iter = nav.SelectSingleNode("/PropertyObject/EnumInfo");
                    if (iter == null)
                    {
                        throw new XmlSchemaException("Property Object does not contain the proper xml.");
                    }

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();

                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(EnumValueCollection), null);
                    EnumInfo = (EnumValueCollection)serializer.Deserialize(dataReader);
                    TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);

                    AssemblyQualifiedName = EnumInfo.SourceEnum;
                    Type = AssemblyQualifiedName.Remove(AssemblyQualifiedName.IndexOf(','));
                }
            }

            if (!IsEnum)
            {
                //read data type
                iter = nav.SelectSingleNode("/PropertyObject/ValueType");
                if (iter == null)
                {
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");
                }

                Type valueType = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(iter.Value));
                if (valueType == null)
                {
                    throw new InvalidOperationException(string.Format("Type {0} does not exist.", iter.Value));
                }

                AssemblyQualifiedName = valueType.GetTraceLabQualifiedName();
                Type = valueType.FullName;

                //read value
                iter = nav.SelectSingleNode("/PropertyObject/Value");
                if (iter == null)
                {
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");
                }
                if (iter.GetAttribute("IsNull", "") != "True")
                {
                    var typeToDeserialize = valueType;
                    if (!string.IsNullOrWhiteSpace(m_actualValueTypeName))
                    {
                        typeToDeserialize = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(m_actualValueTypeName));
                    }

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();
                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeToDeserialize, null);

                    Value = serializer.Deserialize(dataReader);
                }
                else
                {
                    Value = null;
                }
            }
        }
 public EnumValueTypeConverter(EnumValueCollection instance)
 {
     if (instance == null)
         throw new ArgumentNullException();
     m_instance = instance;
 }
        private void ReadVersion2(XPathNavigator nav)
        {
            //read name
            var iter = nav.SelectSingleNode("/PropertyObject/Name");
            if (iter == null)
                throw new XmlSchemaException("Property Object does not contain the proper xml.");

            Name = iter.Value;

            //read display name
            iter = nav.SelectSingleNode("/PropertyObject/DisplayName");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                DisplayName = iter.Value;
            }
            else
            {
                DisplayName = Name;
            }

            iter = nav.SelectSingleNode("/PropertyObject/Description");
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                Description = iter.Value;
            }
            else
            {
                Description = String.Empty;
            }

            //read if visible
            iter = nav.SelectSingleNode("/PropertyObject/Visible");
            Visible = true; //default
            if (iter != null && String.IsNullOrEmpty(iter.Value) == false)
            {
                string visibleString = iter.Value;
                bool tmpVisible;
                if (bool.TryParse(visibleString, out tmpVisible))
                {
                    Visible = tmpVisible;
                }
            }

            //read enum information
            iter = nav.SelectSingleNode("/PropertyObject/IsEnum");
            if (iter != null)
            {
                IsEnum = bool.Parse(iter.Value);
                if (IsEnum)
                {
                    iter = nav.SelectSingleNode("/PropertyObject/EnumInfo");
                    if (iter == null)
                        throw new XmlSchemaException("Property Object does not contain the proper xml.");

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();

                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(EnumValueCollection), null);
                    EnumInfo = (EnumValueCollection)serializer.Deserialize(dataReader);
                    TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);

                    AssemblyQualifiedName = EnumInfo.SourceEnum;
                    Type = AssemblyQualifiedName.Remove(AssemblyQualifiedName.IndexOf(','));
                }
            }

            if (!IsEnum)
            {
                //read data type
                iter = nav.SelectSingleNode("/PropertyObject/ValueType");
                if (iter == null)
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");

                Type valueType = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(iter.Value));
                if (valueType == null)
                    throw new InvalidOperationException(string.Format("Type {0} does not exist.", iter.Value));

                AssemblyQualifiedName = valueType.GetTraceLabQualifiedName();
                Type = valueType.FullName;

                //read value
                iter = nav.SelectSingleNode("/PropertyObject/Value");
                if (iter == null)
                    throw new XmlSchemaException("Property Object does not contain the proper xml.");
                if (iter.GetAttribute("IsNull", "") != "True")
                {
                    var typeToDeserialize = valueType;
                    if (!string.IsNullOrWhiteSpace(m_actualValueTypeName))
                    {
                        typeToDeserialize = System.Type.GetType(TraceLabSDK.TypeHelper.ConvertOldTypeName(m_actualValueTypeName));
                    }

                    var dataReader = iter.ReadSubtree();
                    dataReader.MoveToContent();
                    dataReader.Read();
                    var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeToDeserialize, null);

                    Value = serializer.Deserialize(dataReader);
                }
                else
                {
                    Value = null;
                }
            }
        }
        public ConfigPropertyObject(ConfigPropertyObject propertyObject)
        {
            Name = String.Copy(propertyObject.Name);
            Value = ObjectCopier.Clone(propertyObject.Value);
            Type = String.Copy(propertyObject.Type);
            AssemblyQualifiedName = String.Copy(propertyObject.AssemblyQualifiedName);
            DisplayName = String.Copy(propertyObject.DisplayName);
            Description = String.Copy(propertyObject.Description);
            Visible = propertyObject.Visible;
            IsEnum = propertyObject.IsEnum;

            if (IsEnum)
            {
                var enumInfo = new EnumValueCollection(propertyObject.EnumInfo);
                EnumInfo = enumInfo;
                TypeDescriptor.AddProvider(new EnumValueDescriptionProvider(EnumInfo), EnumInfo);
                Value = propertyObject.Value.ToString();
            }
        }