aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Data.WindowsInstaller/ColumnDefinition.cs
blob: 056be1e9dbb3f68d90ba47e15ee32d1fcdb8b292 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.Data
{
    using System;
    using System.Globalization;
    using System.Xml;

    /// <summary>
    /// Defines MSI column types.
    /// </summary>
    public enum ColumnType
    {
        /// <summary>Unknown column type, default and invalid.</summary>
        Unknown,

        /// <summary>Column is a string.</summary>
        String,

        /// <summary>Column is a localizable string.</summary>
        Localized,

        /// <summary>Column is a number.</summary>
        Number,

        /// <summary>Column is a binary stream.</summary>
        Object,

        /// <summary>Column is a string that is preserved in transforms (like Object).</summary>
        Preserved,
    }

    /// <summary>
    /// Specifies if the column should be modularized.
    /// </summary>
    public enum ColumnModularizeType
    {
        /// <summary>Column should not be modularized.</summary>
        None,

        /// <summary>Column should be modularized.</summary>
        Column,

        /// <summary>When the column is an primary or foreign key to the Icon table it should be modularized special.</summary>
        Icon,

        /// <summary>When the column is a companion file it should be modularized.</summary>
        CompanionFile,

        /// <summary>Column is a condition and should be modularized.</summary>
        Condition,

        /// <summary>Special modularization type for the ControlEvent table's Argument column.</summary>
        ControlEventArgument,

        /// <summary>Special modularization type for the Control table's Text column.</summary>
        ControlText,

        /// <summary>Any Properties in the column should be modularized.</summary>
        Property,

        /// <summary>Semi-colon list of keys, all of which need to be modularized.</summary>
        SemicolonDelimited,
    }

    /// <summary>
    /// Column validation category type
    /// </summary>
    public enum ColumnCategory
    {
        /// <summary>Unknown category, default and invalid.</summary>
        Unknown,

        /// <summary>Text category.</summary>
        Text,

        /// <summary>UpperCase category.</summary>
        UpperCase,

        /// <summary>LowerCase category.</summary>
        LowerCase,

        /// <summary>Integer category.</summary>
        Integer,

        /// <summary>DoubleInteger category.</summary>
        DoubleInteger,

        /// <summary>TimeDate category.</summary>
        TimeDate,

        /// <summary>Identifier category.</summary>
        Identifier,

        /// <summary>Property category.</summary>
        Property,

        /// <summary>Filename category.</summary>
        Filename,

        /// <summary>WildCardFilename category.</summary>
        WildCardFilename,

        /// <summary>Path category.</summary>
        Path,

        /// <summary>Paths category.</summary>
        Paths,

        /// <summary>AnyPath category.</summary>
        AnyPath,

        /// <summary>DefaultDir category.</summary>
        DefaultDir,

        /// <summary>RegPath category.</summary>
        RegPath,

        /// <summary>Formatted category.</summary>
        Formatted,

        /// <summary>Template category.</summary>
        Template,

        /// <summary>Condition category.</summary>
        Condition,

        /// <summary>Guid category.</summary>
        Guid,

        /// <summary>Version category.</summary>
        Version,

        /// <summary>Language category.</summary>
        Language,

        /// <summary>Binary category.</summary>
        Binary,

        /// <summary>CustomSource category.</summary>
        CustomSource,

        /// <summary>Cabinet category.</summary>
        Cabinet,

        /// <summary>Shortcut category.</summary>
        Shortcut,

        /// <summary>Formatted SDDL category.</summary>
        FormattedSDDLText,
    }

    /// <summary>
    /// Definition of a table's column.
    /// </summary>
    public sealed class ColumnDefinition : IComparable<ColumnDefinition>
    {
        private string name;
        private ColumnType type;
        private int length;
        private bool primaryKey;
        private bool nullable;
        private ColumnModularizeType modularize;
        private bool localizable;
        private bool added;

        private bool minValueSet;
        private long minValue;
        private bool maxValueSet;
        private long maxValue;
        private string keyTable;
        private bool keyColumnSet;
        private int keyColumn;
        private ColumnCategory category;
        private string possibilities;
        private string description;
        private bool escapeIdtCharacters;
        private bool useCData;

        /// <summary>
        /// Creates a new column definition.
        /// </summary>
        /// <param name="name">Name of column.</param>
        /// <param name="type">Type of column</param>
        /// <param name="length">Length of column.</param>
        /// <param name="primaryKey">If column is primary key.</param>
        /// <param name="nullable">If column is nullable.</param>
        /// <param name="modularizeType">Type of modularization for column</param>
        /// <param name="localizable">If the column is localizable.</param>
        /// <param name="minValueSet">If the minimum of the value was set.</param>
        /// <param name="minValue">Minimum value for the column.</param>
        /// <param name="maxValueSet">If the maximum value was set.</param>
        /// <param name="maxValue">Maximum value for the colum.</param>
        /// <param name="keyTable">Optional name of table for foreign key.</param>
        /// <param name="keyColumnSet">If the key column was set.</param>
        /// <param name="keyColumn">Optional name of column for foreign key.</param>
        /// <param name="category">Validation category for column.</param>
        /// <param name="possibilities">Set of possible values for column.</param>
        /// <param name="description">Description of column in vaidation table.</param>
        /// <param name="escapeIdtCharacters">If characters should be escaped in IDT.</param>
        /// <param name="useCData">If whitespace should be preserved in a CDATA node.</param>
        public ColumnDefinition(string name, ColumnType type, int length, bool primaryKey, bool nullable, ColumnModularizeType modularizeType, bool localizable, bool minValueSet, long minValue, bool maxValueSet, long maxValue, string keyTable, bool keyColumnSet, int keyColumn, ColumnCategory category, string possibilities, string description, bool escapeIdtCharacters, bool useCData)
        {
            this.name = name;
            this.type = type;
            this.length = length;
            this.primaryKey = primaryKey;
            this.nullable = nullable;
            this.modularize = modularizeType;
            this.localizable = localizable;
            this.minValueSet = minValueSet;
            this.minValue = minValue;
            this.maxValueSet = maxValueSet;
            this.maxValue = maxValue;
            this.keyTable = keyTable;
            this.keyColumnSet = keyColumnSet;
            this.keyColumn = keyColumn;
            this.category = category;
            this.possibilities = possibilities;
            this.description = description;
            this.escapeIdtCharacters = escapeIdtCharacters;
            this.useCData = useCData;
        }

        /// <summary>
        /// Gets whether this column was added via a transform.
        /// </summary>
        /// <value>Whether this column was added via a transform.</value>
        public bool Added
        {
            get { return this.added; }
            set { this.added = value; }
        }

        /// <summary>
        /// Gets the name of the column.
        /// </summary>
        /// <value>Name of column.</value>
        public string Name
        {
            get { return this.name; }
        }

        /// <summary>
        /// Gets the type of the column.
        /// </summary>
        /// <value>Type of column.</value>
        public ColumnType Type
        {
            get { return this.type; }
        }

        /// <summary>
        /// Gets the length of the column.
        /// </summary>
        /// <value>Length of column.</value>
        public int Length
        {
            get { return this.length; }
        }

        /// <summary>
        /// Gets if the column is a primary key.
        /// </summary>
        /// <value>true if column is primary key.</value>
        public bool PrimaryKey
        {
            get { return this.primaryKey; }
        }

        /// <summary>
        /// Gets if the column is nullable.
        /// </summary>
        /// <value>true if column is nullable.</value>
        public bool Nullable
        {
            get { return this.nullable; }
        }

        /// <summary>
        /// Gets the type of modularization for this column.
        /// </summary>
        /// <value>Column's modularization type.</value>
        public ColumnModularizeType ModularizeType
        {
            get { return this.modularize; }
        }

        /// <summary>
        /// Gets if the column is localizable. Can be because the type is localizable, or because the column 
        /// was explicitly set to be so.
        /// </summary>
        /// <value>true if column is localizable.</value>
        public bool IsLocalizable
        {
            get { return this.localizable || ColumnType.Localized == this.Type; }
        }

        /// <summary>
        /// Gets if the minimum value of the column is set.
        /// </summary>
        /// <value>true if minimum value is set.</value>
        public bool IsMinValueSet
        {
            get { return this.minValueSet; }
        }

        /// <summary>
        /// Gets the minimum value for the column, only valid if IsMinValueSet returns true.
        /// </summary>
        /// <value>Minimum value for the column.</value>
        public long MinValue
        {
            get { return this.minValue; }
        }

        /// <summary>
        /// Gets if the maximum value of the column is set.
        /// </summary>
        /// <value>true if maximum value is set.</value>
        public bool IsMaxValueSet
        {
            get { return this.maxValueSet; }
        }

        /// <summary>
        /// Gets the maximum value for the column, only valid if IsMinValueSet returns true.
        /// </summary>
        /// <value>Maximum value for the column.</value>
        public long MaxValue
        {
            get { return this.maxValue; }
        }

        /// <summary>
        /// Gets the table that has the foreign key for this column
        /// </summary>
        /// <value>Foreign key table name.</value>
        public string KeyTable
        {
            get { return this.keyTable; }
        }

        /// <summary>
        /// Gets if the key column is set.
        /// </summary>
        /// <value>True if the key column is set.</value>
        public bool IsKeyColumnSet
        {
            get { return this.keyColumnSet; }
        }

        /// <summary>
        /// Gets the foreign key column that this column refers to.
        /// </summary>
        /// <value>Foreign key column.</value>
        public int KeyColumn
        {
            get { return this.keyColumn; }
        }

        /// <summary>
        /// Gets the validation category for this column.
        /// </summary>
        /// <value>Validation category.</value>
        public ColumnCategory Category
        {
            get { return this.category; }
        }

        /// <summary>
        /// Gets the set of possibilities for this column.
        /// </summary>
        /// <value>Set of possibilities for this column.</value>
        public string Possibilities
        {
            get { return this.possibilities; }
        }

        /// <summary>
        /// Gets the description for this column.
        /// </summary>
        /// <value>Description of column.</value>
        public string Description
        {
            get { return this.description; }
        }

        /// <summary>
        /// Gets if characters should be escaped to fit into IDT.
        /// </summary>
        /// <value>true if data should be escaped when adding to IDT.</value>
        public bool EscapeIdtCharacters
        {
            get { return this.escapeIdtCharacters; }
        }

        /// <summary>
        /// Gets if whitespace should be preserved in a CDATA node.
        /// </summary>
        /// <value>true if whitespace should be preserved in a CDATA node.</value>
        public bool UseCData
        {
            get { return this.useCData; }
        }

        /// <summary>
        /// Gets the type of the column in IDT format.
        /// </summary>
        /// <value>IDT format for column type.</value>
        public string IdtType
        {
            get
            {
                char typeCharacter;
                switch (this.type)
                {
                    case ColumnType.Number:
                        typeCharacter = this.nullable ? 'I' : 'i';
                        break;
                    case ColumnType.Preserved:
                    case ColumnType.String:
                        typeCharacter = this.nullable ? 'S' : 's';
                        break;
                    case ColumnType.Localized:
                        typeCharacter = this.nullable ? 'L' : 'l';
                        break;
                    case ColumnType.Object:
                        typeCharacter = this.nullable ? 'V' : 'v';
                        break;
                    default:
                        throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixDataStrings.EXP_UnknownColumnType, this.type));
                }

                return String.Concat(typeCharacter, this.length);
            }
        }

        /// <summary>
        /// Parses a column definition in a table definition.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The ColumnDefintion represented by the Xml.</returns>
        internal static ColumnDefinition Read(XmlReader reader)
        {
            if (!reader.LocalName.Equals("columnDefinition"))
            {
                throw new XmlException();
            }

            bool added = false;
            ColumnCategory category = ColumnCategory.Unknown;
            string description = null;
            bool empty = reader.IsEmptyElement;
            bool escapeIdtCharacters = false;
            int keyColumn = -1;
            bool keyColumnSet = false;
            string keyTable = null;
            int length = -1;
            bool localizable = false;
            long maxValue = 0;
            bool maxValueSet = false;
            long minValue = 0;
            bool minValueSet = false;
            ColumnModularizeType modularize = ColumnModularizeType.None;
            string name = null;
            bool nullable = false;
            string possibilities = null;
            bool primaryKey = false;
            ColumnType type = ColumnType.Unknown;
            bool useCData = false;

            // parse the attributes
            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                    case "added":
                        added = reader.Value.Equals("yes");
                        break;
                    case "category":
                        switch (reader.Value)
                        {
                            case "anyPath":
                                category = ColumnCategory.AnyPath;
                                break;
                            case "binary":
                                category = ColumnCategory.Binary;
                                break;
                            case "cabinet":
                                category = ColumnCategory.Cabinet;
                                break;
                            case "condition":
                                category = ColumnCategory.Condition;
                                break;
                            case "customSource":
                                category = ColumnCategory.CustomSource;
                                break;
                            case "defaultDir":
                                category = ColumnCategory.DefaultDir;
                                break;
                            case "doubleInteger":
                                category = ColumnCategory.DoubleInteger;
                                break;
                            case "filename":
                                category = ColumnCategory.Filename;
                                break;
                            case "formatted":
                                category = ColumnCategory.Formatted;
                                break;
                            case "formattedSddl":
                                category = ColumnCategory.FormattedSDDLText;
                                break;
                            case "guid":
                                category = ColumnCategory.Guid;
                                break;
                            case "identifier":
                                category = ColumnCategory.Identifier;
                                break;
                            case "integer":
                                category = ColumnCategory.Integer;
                                break;
                            case "language":
                                category = ColumnCategory.Language;
                                break;
                            case "lowerCase":
                                category = ColumnCategory.LowerCase;
                                break;
                            case "path":
                                category = ColumnCategory.Path;
                                break;
                            case "paths":
                                category = ColumnCategory.Paths;
                                break;
                            case "property":
                                category = ColumnCategory.Property;
                                break;
                            case "regPath":
                                category = ColumnCategory.RegPath;
                                break;
                            case "shortcut":
                                category = ColumnCategory.Shortcut;
                                break;
                            case "template":
                                category = ColumnCategory.Template;
                                break;
                            case "text":
                                category = ColumnCategory.Text;
                                break;
                            case "timeDate":
                                category = ColumnCategory.TimeDate;
                                break;
                            case "upperCase":
                                category = ColumnCategory.UpperCase;
                                break;
                            case "version":
                                category = ColumnCategory.Version;
                                break;
                            case "wildCardFilename":
                                category = ColumnCategory.WildCardFilename;
                                break;
                            default:
                                throw new InvalidOperationException();
                        }
                        break;
                    case "description":
                        description = reader.Value;
                        break;
                    case "escapeIdtCharacters":
                        escapeIdtCharacters = reader.Value.Equals("yes");
                        break;
                    case "keyColumn":
                        keyColumnSet = true;
                        keyColumn = Convert.ToInt32(reader.Value, 10);
                        break;
                    case "keyTable":
                        keyTable = reader.Value;
                        break;
                    case "length":
                        length = Convert.ToInt32(reader.Value, 10);
                        break;
                    case "localizable":
                        localizable = reader.Value.Equals("yes");
                        break;
                    case "maxValue":
                        maxValueSet = true;
                        maxValue = Convert.ToInt32(reader.Value, 10);
                        break;
                    case "minValue":
                        minValueSet = true;
                        minValue = Convert.ToInt32(reader.Value, 10);
                        break;
                    case "modularize":
                        switch (reader.Value)
                        {
                            case "column":
                                modularize = ColumnModularizeType.Column;
                                break;
                            case "companionFile":
                                modularize = ColumnModularizeType.CompanionFile;
                                break;
                            case "condition":
                                modularize = ColumnModularizeType.Condition;
                                break;
                            case "controlEventArgument":
                                modularize = ColumnModularizeType.ControlEventArgument;
                                break;
                            case "controlText":
                                modularize = ColumnModularizeType.ControlText;
                                break;
                            case "icon":
                                modularize = ColumnModularizeType.Icon;
                                break;
                            case "none":
                                modularize = ColumnModularizeType.None;
                                break;
                            case "property":
                                modularize = ColumnModularizeType.Property;
                                break;
                            case "semicolonDelimited":
                                modularize = ColumnModularizeType.SemicolonDelimited;
                                break;
                            default:
                                throw new XmlException();
                        }
                        break;
                    case "name":
                        switch (reader.Value)
                        {
                            case "CREATE":
                            case "DELETE":
                            case "DROP":
                            case "INSERT":
                                throw new XmlException();
                            default:
                                name = reader.Value;
                                break;
                        }
                        break;
                    case "nullable":
                        nullable = reader.Value.Equals("yes");
                        break;
                    case "primaryKey":
                        primaryKey = reader.Value.Equals("yes");
                        break;
                    case "set":
                        possibilities = reader.Value;
                        break;
                    case "type":
                        switch (reader.Value)
                        {
                            case "localized":
                                type = ColumnType.Localized;
                                break;
                            case "number":
                                type = ColumnType.Number;
                                break;
                            case "object":
                                type = ColumnType.Object;
                                break;
                            case "string":
                                type = ColumnType.String;
                                break;
                            case "preserved":
                                type = ColumnType.Preserved;
                                break;
                            default:
                                throw new XmlException();
                        }
                        break;
                    case "useCData":
                        useCData = reader.Value.Equals("yes");
                        break;
                }
            }

            // parse the child elements (there should be none)
            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            throw new XmlException();
                        case XmlNodeType.EndElement:
                            done = true;
                            break;
                    }
                }

                if (!done)
                {
                    throw new XmlException();
                }
            }

            ColumnDefinition columnDefinition = new ColumnDefinition(name, type, length, primaryKey, nullable, modularize, localizable, minValueSet, minValue, maxValueSet, maxValue, keyTable, keyColumnSet, keyColumn, category, possibilities, description, escapeIdtCharacters, useCData);
            columnDefinition.Added = added;

            return columnDefinition;
        }

        /// <summary>
        /// Persists a ColumnDefinition in an XML format.
        /// </summary>
        /// <param name="writer">XmlWriter where the Output should persist itself as XML.</param>
        internal void Write(XmlWriter writer)
        {
            writer.WriteStartElement("columnDefinition", TableDefinitionCollection.XmlNamespaceUri);

            writer.WriteAttributeString("name", this.name);

            switch (this.type)
            {
                case ColumnType.Localized:
                    writer.WriteAttributeString("type", "localized");
                    break;
                case ColumnType.Number:
                    writer.WriteAttributeString("type", "number");
                    break;
                case ColumnType.Object:
                    writer.WriteAttributeString("type", "object");
                    break;
                case ColumnType.String:
                    writer.WriteAttributeString("type", "string");
                    break;
                case ColumnType.Preserved:
                    writer.WriteAttributeString("type", "preserved");
                    break;
            }

            writer.WriteAttributeString("length", this.length.ToString(CultureInfo.InvariantCulture.NumberFormat));

            if (this.primaryKey)
            {
                writer.WriteAttributeString("primaryKey", "yes");
            }

            if (this.nullable)
            {
                writer.WriteAttributeString("nullable", "yes");
            }

            if (this.localizable)
            {
                writer.WriteAttributeString("localizable", "yes");
            }

            if (this.added)
            {
                writer.WriteAttributeString("added", "yes");
            }

            switch (this.modularize)
            {
                case ColumnModularizeType.Column:
                    writer.WriteAttributeString("modularize", "column");
                    break;
                case ColumnModularizeType.CompanionFile:
                    writer.WriteAttributeString("modularize", "companionFile");
                    break;
                case ColumnModularizeType.Condition:
                    writer.WriteAttributeString("modularize", "condition");
                    break;
                case ColumnModularizeType.ControlEventArgument:
                    writer.WriteAttributeString("modularize", "controlEventArgument");
                    break;
                case ColumnModularizeType.ControlText:
                    writer.WriteAttributeString("modularize", "controlText");
                    break;
                case ColumnModularizeType.Icon:
                    writer.WriteAttributeString("modularize", "icon");
                    break;
                case ColumnModularizeType.None:
                    // this is the default value
                    break;
                case ColumnModularizeType.Property:
                    writer.WriteAttributeString("modularize", "property");
                    break;
                case ColumnModularizeType.SemicolonDelimited:
                    writer.WriteAttributeString("modularize", "semicolonDelimited");
                    break;
            }

            if (this.minValueSet)
            {
                writer.WriteAttributeString("minValue", this.minValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            }

            if (this.maxValueSet)
            {
                writer.WriteAttributeString("maxValue", this.maxValue.ToString(CultureInfo.InvariantCulture.NumberFormat));
            }

            if (!String.IsNullOrEmpty(this.keyTable))
            {
                writer.WriteAttributeString("keyTable", this.keyTable);
            }

            if (this.keyColumnSet)
            {
                writer.WriteAttributeString("keyColumn", this.keyColumn.ToString(CultureInfo.InvariantCulture.NumberFormat));
            }

            switch (this.category)
            {
                case ColumnCategory.AnyPath:
                    writer.WriteAttributeString("category", "anyPath");
                    break;
                case ColumnCategory.Binary:
                    writer.WriteAttributeString("category", "binary");
                    break;
                case ColumnCategory.Cabinet:
                    writer.WriteAttributeString("category", "cabinet");
                    break;
                case ColumnCategory.Condition:
                    writer.WriteAttributeString("category", "condition");
                    break;
                case ColumnCategory.CustomSource:
                    writer.WriteAttributeString("category", "customSource");
                    break;
                case ColumnCategory.DefaultDir:
                    writer.WriteAttributeString("category", "defaultDir");
                    break;
                case ColumnCategory.DoubleInteger:
                    writer.WriteAttributeString("category", "doubleInteger");
                    break;
                case ColumnCategory.Filename:
                    writer.WriteAttributeString("category", "filename");
                    break;
                case ColumnCategory.Formatted:
                    writer.WriteAttributeString("category", "formatted");
                    break;
                case ColumnCategory.FormattedSDDLText:
                    writer.WriteAttributeString("category", "formattedSddl");
                    break;
                case ColumnCategory.Guid:
                    writer.WriteAttributeString("category", "guid");
                    break;
                case ColumnCategory.Identifier:
                    writer.WriteAttributeString("category", "identifier");
                    break;
                case ColumnCategory.Integer:
                    writer.WriteAttributeString("category", "integer");
                    break;
                case ColumnCategory.Language:
                    writer.WriteAttributeString("category", "language");
                    break;
                case ColumnCategory.LowerCase:
                    writer.WriteAttributeString("category", "lowerCase");
                    break;
                case ColumnCategory.Path:
                    writer.WriteAttributeString("category", "path");
                    break;
                case ColumnCategory.Paths:
                    writer.WriteAttributeString("category", "paths");
                    break;
                case ColumnCategory.Property:
                    writer.WriteAttributeString("category", "property");
                    break;
                case ColumnCategory.RegPath:
                    writer.WriteAttributeString("category", "regPath");
                    break;
                case ColumnCategory.Shortcut:
                    writer.WriteAttributeString("category", "shortcut");
                    break;
                case ColumnCategory.Template:
                    writer.WriteAttributeString("category", "template");
                    break;
                case ColumnCategory.Text:
                    writer.WriteAttributeString("category", "text");
                    break;
                case ColumnCategory.TimeDate:
                    writer.WriteAttributeString("category", "timeDate");
                    break;
                case ColumnCategory.UpperCase:
                    writer.WriteAttributeString("category", "upperCase");
                    break;
                case ColumnCategory.Version:
                    writer.WriteAttributeString("category", "version");
                    break;
                case ColumnCategory.WildCardFilename:
                    writer.WriteAttributeString("category", "wildCardFilename");
                    break;
            }

            if (!String.IsNullOrEmpty(this.possibilities))
            {
                writer.WriteAttributeString("set", this.possibilities);
            }

            if (!String.IsNullOrEmpty(this.description))
            {
                writer.WriteAttributeString("description", this.description);
            }

            if (this.escapeIdtCharacters)
            {
                writer.WriteAttributeString("escapeIdtCharacters", "yes");
            }

            if (this.useCData)
            {
                writer.WriteAttributeString("useCData", "yes");
            }

            writer.WriteEndElement();
        }

        /// <summary>
        /// Validate a value for this column.
        /// </summary>
        /// <param name="value">The value to validate.</param>
        /// <returns>Validated value.</returns>
        internal object ValidateValue(object value)
        {
            if (null == value)
            {
                if (!this.nullable)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set column '{0}' with a null value because this is a required field.", this.name));
                }
            }
            else // check numerical values against their specified minimum and maximum values.
            {
                if (ColumnType.Number == this.type && !this.IsLocalizable)
                {
                    // For now all enums in the tables can be represented by integers. This if statement would need to
                    // be enhanced if that ever changes.
                    if (value is int || value.GetType().IsEnum)
                    {
                        int intValue = (int)value;

                        // validate the value against the minimum allowed value
                        if (this.minValueSet && this.minValue > intValue)
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set column '{0}' with value {1} because it is less than the minimum allowed value for this column, {2}.", this.name, intValue, this.minValue));
                        }

                        // validate the value against the maximum allowed value
                        if (this.maxValueSet && this.maxValue < intValue)
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set column '{0}' with value {1} because it is greater than the maximum allowed value for this column, {2}.", this.name, intValue, this.maxValue));
                        }

                        return intValue;
                    }
                    else if (value is long)
                    {
                        long longValue = (long)value;

                        // validate the value against the minimum allowed value
                        if (this.minValueSet && this.minValue > longValue)
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set column '{0}' with value {1} because it is less than the minimum allowed value for this column, {2}.", this.name, longValue, this.minValue));
                        }

                        // validate the value against the maximum allowed value
                        if (this.maxValueSet && this.maxValue < longValue)
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set column '{0}' with value {1} because it is greater than the maximum allowed value for this column, {2}.", this.name, longValue, this.maxValue));
                        }

                        return longValue;
                    }
                    else
                    {
                        throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set number column '{0}' with a value of type '{1}'.", this.name, value.GetType().ToString()));
                    }
                }
                else
                {
                    if (!(value is string))
                    {
                        //throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Cannot set string column '{0}' with a value of type '{1}'.", this.name, value.GetType().ToString()));
                        return value.ToString();
                    }
                }
            }

            return value;
        }

        /// <summary>
        /// Compare this column definition to another column definition.
        /// </summary>
        /// <remarks>
        /// Only Windows Installer traits are compared, allowing for updates to WiX-specific table definitions.
        /// </remarks>
        /// <param name="other">The <see cref="ColumnDefinition"/> to compare with this one.</param>
        /// <returns>0 if the columns' core propeties are the same; otherwise, non-0.</returns>
        public int CompareTo(ColumnDefinition other)
        {
            // by definition, this object is greater than null
            if (null == other)
            {
                return 1;
            }

            // compare column names
            int ret = String.Compare(this.Name, other.Name, StringComparison.Ordinal);

            // compare column types
            if (0 == ret)
            {
                ret = this.Type == other.Type ? 0 : -1;

                // compare column lengths
                if (0 == ret)
                {
                    ret = this.Length == other.Length ? 0 : -1;

                    // compare whether both are primary keys
                    if (0 == ret)
                    {
                        ret = this.PrimaryKey == other.PrimaryKey ? 0 : -1;

                        // compare nullability
                        if (0 == ret)
                        {
                            ret = this.Nullable == other.Nullable ? 0 : -1;
                        }
                    }
                }
            }

            return ret;
        }
    }
}