internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableNameDeclaration = rootElement.GetUniqueDescendant <NameDeclaration>(
                "Table Name",
                n => n.NameInParent == "TableName");
            var mappingNameExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Name",
                n => n.NameInParent == "MappingName");
            var mappingKindToken = rootElement.GetUniqueDescendant <SyntaxToken>(
                "Mapping Kind",
                n => n.NameInParent == "MappingKind");
            var mappingFormatExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Format",
                n => n.NameInParent == "MappingFormat");
            var mappingFormatFirstPart  = QuotedText.FromLiteral(mappingFormatExpression);
            var mappingFormatExtraParts = rootElement
                                          .GetDescendants <CompoundStringLiteralExpression>()
                                          .SelectMany(c => c.Tokens)
                                          .Select(t => QuotedText.FromToken(t));
            var mappingFormatParts = mappingFormatExtraParts
                                     .Prepend(mappingFormatFirstPart)
                                     .Select(q => q.Text);
            var mappingFormat = string.Concat(mappingFormatParts);
            var command       = new CreateMappingCommand(
                EntityName.FromCode(tableNameDeclaration),
                mappingKindToken.Text,
                QuotedText.FromLiteral(mappingNameExpression),
                QuotedText.FromText(mappingFormat) !);

            return(command);
        }
Exemple #2
0
        private static QuotedText?GetProperty(SyntaxElement rootElement, SyntaxKind kind)
        {
            var literal = rootElement
                          .GetDescendants <SyntaxElement>(e => e.Kind == kind)
                          .Select(e => e.Parent.GetDescendants <LiteralExpression>().FirstOrDefault())
                          .FirstOrDefault();

            return(literal == null
                ? null
                : QuotedText.FromLiteral(literal));
        }
        internal static CommandBase FromCode(SyntaxElement rootElement)
        {
            var tableNameReference = rootElement.GetUniqueDescendant <NameReference>(
                "Table Name",
                n => n.NameInParent == "TableName");
            var mappingNameExpression = rootElement.GetUniqueDescendant <LiteralExpression>(
                "Mapping Name",
                n => n.NameInParent == "MappingName");
            var mappingKindToken = rootElement.GetUniqueDescendant <SyntaxToken>(
                "Mapping Kind",
                n => n.NameInParent == "MappingKind");
            var command = new DropMappingCommand(
                new EntityName(tableNameReference.SimpleName),
                mappingKindToken.Text,
                QuotedText.FromLiteral(mappingNameExpression));

            return(command);
        }