public AttributeInfo(string attributeName, XmlNode[] nodes)
        {
            if (attributeName == null)
                throw new ArgumentNullException("attributeName");
            if (attributeName.Length == 0)
                throw new ArgumentException("attributeName is an empty string");
            if (nodes == null)
                throw new ArgumentNullException("nodes");
            if (nodes.Length == 0)
                throw new ArgumentException("nodes is an empty array");

            string[] possibleValues = FindAllPossibleValues(attributeName, nodes);
            bool isOptional = IsOptional(attributeName, nodes);
            bool canBeEmpty = CanBeEmpty(attributeName, nodes);
            Info = new DataInfo(attributeName, possibleValues, isOptional, canBeEmpty);
        }
示例#2
0
        public CDataInfo(XmlNode[] nodes)
        {
            if (nodes == null)
                throw new ArgumentNullException("nodes");
            if (nodes.Length == 0)
                throw new ArgumentException("nodes is an empty array");

            string[] possibleValues = FindAllPossibleValues(nodes);
            bool isOptional = IsOptional(nodes);
            bool canBeEmpty = CanBeEmpty(nodes);
            Info = new DataInfo("CDATA", possibleValues, isOptional, canBeEmpty);
            if (possibleValues.Length == 0)
                Include = false;
            else
                Include = true;
        }
        public DataInfoPanel(DataInfo info)
        {
            if (info == null)
                throw new ArgumentNullException("info");

            InitializeComponent();

            Info = info;
            List<DataType> supportedTypes = new List<DataType>();
            supportedTypes.AddRange(info.GetSupportedTypes());
            if (supportedTypes.Contains(info.SelectedDataType))
                allTypesCheckBox.Checked = false;
            else
                allTypesCheckBox.Checked = true;

            UpdateComboBox();

            nameLabel.Text = Info.Name;
            propertyNameTextBox.Text = Info.PropertyName;
            optionalCheckBox.Checked = Info.IsOptional;
            emptyCheckBox.Checked = Info.CanBeEmpty;
            errorLabel.Text = string.Empty;
            UpdateError();
        }
示例#4
0
 private MethodInfo[] GenerateMethods(DataInfo[] dataArray)
 {
     List<MethodInfo> methodList = new List<MethodInfo>(dataArray.Length);
     foreach(DataInfo data in dataArray)
         methodList.Add(GenerateImportMethod(data));
     foreach (DataInfo data in dataArray)
         methodList.Add(GenerateExportMethod(data));
     return methodList.ToArray();
 }
示例#5
0
        private MethodInfo GenerateImportMethod(DataInfo info)
        {
            string methodName = GetImportMethodName(info.PropertyName);
            MethodInfo method = new MethodInfo
            (
                "public",
                "void",
                methodName,
                string.Format("Parses a string value and stores the data in {0}.", info.PropertyName)
            );

            method.Parameters.Add(new ParameterInfo
            (
                "string",
                "value",
                "String representation of the value.",
                null,
                null
            ));

            if (!info.IsOptional && !info.CanBeEmpty)
            {
                method.Exceptions.Add(new ExceptionInfo
                (
                    "InvalidDataException",
                    "The string value is a null reference or an empty string."
                ));
            }
            else
            {
                if (!info.IsOptional)
                {
                    method.Exceptions.Add(new ExceptionInfo
                    (
                        "InvalidDataException",
                        "The string value is a null reference."
                    ));
                }

                if (!info.CanBeEmpty)
                {
                    method.Exceptions.Add(new ExceptionInfo
                    (
                        "InvalidDataException",
                        "The string value is an empty string."
                    ));
                }
            }

            method.Exceptions.Add(new ExceptionInfo
            (
                "InvalidDataException",
                "The string value could not be parsed."
            ));

            method.CodeLines.AddRange(info.SelectedDataTypeObject.GenerateImportMethodCode());
            return method;
        }
示例#6
0
        private MethodInfo GenerateExportMethod(DataInfo info)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("String representing the value.");
            if (info.IsOptional)
                sb.Append(" Can be null.");
            if (info.CanBeEmpty)
                sb.Append(" Can be empty.");

            string methodName = GetExportMethodName(info.PropertyName);
            MethodInfo method = new MethodInfo
            (
                "public",
                "string",
                methodName,
                string.Format("Gets a string representation of {0}.", info.PropertyName),
                null,
                sb.ToString()
            );

            method.CodeLines.AddRange(info.SelectedDataTypeObject.GenerateExportMethodCode());
            return method;
        }
示例#7
0
        private bool? DetermineDataContructorEmptyCheck(DataInfo info)
        {
            // Here is a truth table for the following logic:
            //
            // IsOptional	CanBeEmpty	IsNullable	IsArray	CanBeEmpty
            // 0			0			0			0		NULL
            // 1			0			0			0		NULL
            // 0			1			0			0		NULL
            // 1			1			0			0		NULL
            // 0			0			1			0		NULL
            // 1			0			1			0		NULL
            // 0			1			1			0		NULL
            // 1			1			1			0		NULL
            // 0			0			0			1		0
            // 1			0			0			1		0
            // 0			1			0			1		1
            // 1			1			0			1		1
            // 0			0			1			1		NULL
            // 1			0			1			1		NULL
            // 0			1			1			1		NULL
            // 1			1			1			1		NULL

            if (!info.SelectedDataTypeObject.IsArray)
                return null;
            else
            {
                if (info.SelectedDataTypeObject.IsNullable)
                    return null;
                else
                    return info.CanBeEmpty;
            }
        }