/// <summary>
        /// Validates an enumerated type.
        /// </summary>
        private static void ValidateEnumeratedType(EnumeratedType enumeratedType)
        {
            if (enumeratedType.Value == null || enumeratedType.Value.Length == 0)
            {
                throw Exception("The enumerated type '{0}' does not have any values specified.", enumeratedType.Name);
            }

            int nextIndex = 0;
            Dictionary <string, EnumeratedValue> values = new Dictionary <string, EnumeratedValue>();

            for (int ii = 0; ii < enumeratedType.Value.Length; ii++)
            {
                EnumeratedValue value = enumeratedType.Value[ii];

                if (values.ContainsKey(value.Name))
                {
                    throw Exception("The enumerated type '{0}' has a duplicate value '{1}'.", enumeratedType.Name, value.Value);
                }

                if (!value.ValueSpecified)
                {
                    value.Value          = nextIndex;
                    value.ValueSpecified = true;
                }
                else
                {
                    nextIndex = value.Value + 1;
                }

                values.Add(value.Name, value);
            }
        }
        /// <summary>
        /// Writes an enumerated value in an OPCBinary schema.
        /// </summary>
        private string LoadTemplate_EnumeratedValue(Template template, Context context)
        {
            EnumeratedValue valueType = context.Target as EnumeratedValue;

            if (valueType == null)
            {
                return(null);
            }

            template.WriteLine(String.Empty);
            template.Write(context.Prefix);
            template.Write("<xs:enumeration value=\"{0}_{1}\" />", valueType.Name, valueType.Value);

            /*
             * if (valueType.Value != 1)
             * {
             *  template.WriteLine(">");
             *  template.WriteLine("{0}  <xs:annotation>", context.Prefix);
             *  template.WriteLine("{0}    <xs:appinfo>", context.Prefix);
             *  template.WriteLine("{0}      <EnumerationValue xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">{1}</EnumerationValue>", context.Prefix, valueType.Value);
             *  template.WriteLine("{0}    </xs:appinfo>", context.Prefix);
             *  template.WriteLine("{0}  </xs:annotation>", context.Prefix);
             *  template.WriteLine("{0}</xs:enumeration>", context.Prefix);
             * }
             * else
             * {
             *  template.Write(" />");
             * }
             */

            return(null);
        }
示例#3
0
        private bool WriteTemplate_Enum(Template template, Context context)
        {
            EnumeratedValue field = context.Target as EnumeratedValue;

            if (field != null)
            {
                context.BlankLine = false;

                template.Write(string.Format("\n  {{ {0}, \"{1}\" }},", field.Value, field.Name));
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Writes an enumerated value in an OPCBinary schema.
        /// </summary>
        private string LoadTemplate_EnumeratedValue(Template template, Context context)
        {
            EnumeratedValue valueType = context.Target as EnumeratedValue;

            if (valueType == null)
            {
                return(null);
            }

            template.WriteLine(String.Empty);
            template.Write(context.Prefix);
            template.Write("<opc:EnumeratedValue Name=\"{0}\" Value=\"{1}\" />", valueType.Name, valueType.Value);

            return(null);
        }