예제 #1
0
        //============================================================
        //	STATIC METHODS
        //============================================================
        #region DataTypeAsString(SimpleListDataType type)
        /// <summary>
        /// Returns the data type identifier for the supplied <see cref="SimpleListDataType"/>.
        /// </summary>
        /// <param name="type">The <see cref="SimpleListDataType"/> to get the data type identifier for.</param>
        /// <returns>The data type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        public static string DataTypeAsString(SimpleListDataType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(SimpleListDataType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(SimpleListDataType))
                {
                    SimpleListDataType dataType = (SimpleListDataType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (dataType == type)
                    {
                        object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return(name);
        }
        /// <summary>
        /// Returns the <see cref="SimpleListDataType"/> enumeration value that corresponds to the specified data type name.
        /// </summary>
        /// <param name="name">The name of the data type.</param>
        /// <returns>A <see cref="SimpleListDataType"/> enumeration value that corresponds to the specified string, otherwise returns <b>SimpleListDataType.None</b>.</returns>
        /// <remarks>This method disregards case of specified data type name.</remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception>
        public static SimpleListDataType DataTypeByName(string name)
        {
            SimpleListDataType dataType = SimpleListDataType.None;

            Guard.ArgumentNotNullOrEmptyString(name, "name");
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(SimpleListDataType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(SimpleListDataType))
                {
                    SimpleListDataType type             = (SimpleListDataType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);
                    object[]           customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                        if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            dataType = type;
                            break;
                        }
                    }
                }
            }

            return(dataType);
        }
예제 #3
0
        /// <summary>
        /// Returns the data type identifier for the supplied <see cref="SimpleListDataType"/>.
        /// </summary>
        /// <param name="type">The <see cref="SimpleListDataType"/> to get the data type identifier for.</param>
        /// <returns>The data type identifier for the supplied <paramref name="type"/>, otherwise returns an empty string.</returns>
        public static string DataTypeAsString(SimpleListDataType type)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string name = String.Empty;

            //------------------------------------------------------------
            //	Return alternate value based on supplied protocol
            //------------------------------------------------------------
            foreach (System.Reflection.FieldInfo fieldInfo in typeof(SimpleListDataType).GetFields())
            {
                if (fieldInfo.FieldType == typeof(SimpleListDataType))
                {
                    SimpleListDataType dataType = (SimpleListDataType)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name);

                    if (dataType == type)
                    {
                        object[] customAttributes   = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false);

                        if (customAttributes != null && customAttributes.Length > 0)
                        {
                            EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute;

                            name    = enumerationMetadata.AlternateValue;
                            break;
                        }
                    }
                }
            }

            return name;
        }
예제 #4
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="SimpleListSort"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="SimpleListSort"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="SimpleListSort"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string namespaceAttribute = source.GetAttribute("ns", String.Empty);
                string elementAttribute   = source.GetAttribute("element", String.Empty);
                string labelAttribute     = source.GetAttribute("label", String.Empty);
                string dataTypeAttribute  = source.GetAttribute("data-type", String.Empty);
                string defaultAttribute   = source.GetAttribute("default", String.Empty);

                if (!String.IsNullOrEmpty(namespaceAttribute))
                {
                    Uri elementNamespace;
                    if (Uri.TryCreate(namespaceAttribute, UriKind.RelativeOrAbsolute, out elementNamespace))
                    {
                        this.Namespace = elementNamespace;
                        wasLoaded      = true;
                    }
                }

                if (!String.IsNullOrEmpty(elementAttribute))
                {
                    this.Element = elementAttribute;
                    wasLoaded    = true;
                }

                if (!String.IsNullOrEmpty(labelAttribute))
                {
                    this.Label = labelAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(dataTypeAttribute))
                {
                    SimpleListDataType dataType = SimpleListSort.DataTypeByName(dataTypeAttribute);
                    if (dataType != SimpleListDataType.None)
                    {
                        this.DataType = dataType;
                        wasLoaded     = true;
                    }
                }

                if (!String.IsNullOrEmpty(defaultAttribute))
                {
                    if (String.Compare(defaultAttribute, "true", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsDefault = true;
                        wasLoaded      = true;
                    }
                    else if (String.Compare(defaultAttribute, "false", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsDefault = false;
                        wasLoaded      = true;
                    }
                }
            }

            return(wasLoaded);
        }