From 69b15d96cebdbb7201b1849b4f62786633d70b8d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 1 Nov 2017 10:56:09 -0700 Subject: Introduce WiX Intermediate Representation --- src/WixToolset.Data/IntermediateTupleDefinition.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/WixToolset.Data/IntermediateTupleDefinition.cs (limited to 'src/WixToolset.Data/IntermediateTupleDefinition.cs') diff --git a/src/WixToolset.Data/IntermediateTupleDefinition.cs b/src/WixToolset.Data/IntermediateTupleDefinition.cs new file mode 100644 index 00000000..5658cfe9 --- /dev/null +++ b/src/WixToolset.Data/IntermediateTupleDefinition.cs @@ -0,0 +1,47 @@ +// 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; + + public class IntermediateTupleDefinition + { + public IntermediateTupleDefinition(string name, IntermediateFieldDefinition[] fieldDefinitions, Type strongTupleType) + : this(TupleDefinitionType.MustBeFromAnExtension, name, fieldDefinitions, strongTupleType) + { + } + + internal IntermediateTupleDefinition(TupleDefinitionType type, IntermediateFieldDefinition[] fieldDefinitions, Type strongTupleType) + : this(type, type.ToString(), fieldDefinitions, strongTupleType) + { + } + + private IntermediateTupleDefinition(TupleDefinitionType type, string name, IntermediateFieldDefinition[] fieldDefinitions, Type strongTupleType) + { + this.Type = type; + this.Name = name; + this.FieldDefinitions = fieldDefinitions; + this.StrongTupleType = strongTupleType ?? typeof(IntermediateTuple); +#if DEBUG + if (!this.StrongTupleType.IsSubclassOf(typeof(IntermediateTuple))) throw new ArgumentException(nameof(strongTupleType)); +#endif + } + + public TupleDefinitionType Type { get; } + + public string Name { get; } + + public IntermediateFieldDefinition[] FieldDefinitions { get; } + + private Type StrongTupleType { get; } + + public IntermediateTuple CreateTuple(SourceLineNumber sourceLineNumber = null, Identifier id = null) + { + var result = (this.StrongTupleType == typeof(IntermediateTuple)) ? (IntermediateTuple)Activator.CreateInstance(this.StrongTupleType, this) : (IntermediateTuple)Activator.CreateInstance(this.StrongTupleType); + result.SourceLineNumbers = sourceLineNumber; + result.Id = id; + + return result; + } + } +} -- cgit v1.2.3-55-g6feb