コード例 #1
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            snippet.Title       = snippet.Title.Replace(Placeholders.Collection, Type.Name);
            snippet.Description = snippet.Description.Replace(Placeholders.Collection, Type.Name);

            snippet.AddNamespace(Type.Namespace);

            snippet.AddTags(KnownTags.NonUniqueShortcut);
            snippet.AddTags(KnownTags.TitleStartsWithShortcut);
            snippet.AddTags(KnownTags.ExcludeFromReadme);

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.Collection, Type.Name);

            if (Tags.Contains(KnownTags.Dictionary))
            {
                snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.GenericType, $"${LiteralIdentifiers.KeyType}$, ${LiteralIdentifiers.ValueType}$");
                snippet.AddLiteral(LiteralIdentifiers.KeyType, null, language.ObjectType.Keyword);
                snippet.AddLiteral(LiteralIdentifiers.ValueType, null, language.ObjectType.Keyword);

                LiteralRenamer.Rename(snippet, LiteralIdentifiers.CollectionIdentifier, LiteralIdentifiers.DictionaryIdentifier);

                Literal literal = snippet.Literals.Find(LiteralIdentifiers.DictionaryIdentifier);

                if (literal != null)
                {
                    literal.DefaultValue = "dic";
                }
            }

            if (!Tags.Contains(KnownTags.ArgumentList))
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.ArgumentList);
            }

            ProcessFilePath(context, snippet);

            if (snippet.HasTag(KnownTags.Initializer) && Tags.Contains(KnownTags.Initializer))
            {
                var clone = (Snippet)snippet.Clone();
                InitializerCommand.AddInitializer(context, clone, GetInitializer(language), language.GetDefaultValue());
                context.Snippets.Add(clone);
            }
            else
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.Initializer);
            }
        }
コード例 #2
0
        protected override void Execute(ExecutionContext context, Snippet snippet)
        {
            if (snippet.HasTag(KnownTags.Initializer) &&
                (Type.IsImmutable || Type.IsInterface))
            {
                context.IsCanceled = true;
                return;
            }

            LanguageDefinition language = ((LanguageExecutionContext)context).Language;

            var typeName = "";
            var fileName = "";

            if (Type.IsDictionary)
            {
                typeName = language.GetTypeParameterList("TKey, TValue");
                fileName = "OfTKeyTValue";
            }
            else if (Type.Arity == 1)
            {
                typeName = language.GetTypeParameterList("T");
                fileName = "OfT";
            }

            typeName = Type.Name + typeName;
            fileName = Type.Name + fileName;

            snippet.Title       = snippet.Title.Replace(Placeholders.Type, typeName);
            snippet.Description = snippet.Description.Replace(Placeholders.Type, typeName);

            snippet.AddNamespace(Type.Namespace);

            snippet.AddTags(KnownTags.NonUniqueShortcut);
            snippet.AddTags(KnownTags.TitleStartsWithShortcut);
            snippet.AddTags(KnownTags.ExcludeFromReadme);

            snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.Type, Type.Name);

            if (Type.IsDictionary)
            {
                snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.TypeParameterList, language.GetTypeParameterList($"${LiteralIdentifiers.KeyType}$, ${LiteralIdentifiers.ValueType}$"));
                snippet.AddLiteral(LiteralIdentifiers.KeyType, null, language.ObjectType.Keyword);
                snippet.AddLiteral(LiteralIdentifiers.ValueType, null, language.ObjectType.Keyword);

                Literal literal = snippet.Literals.Find(LiteralIdentifiers.Identifier);

                if (literal != null)
                {
                    literal.DefaultValue = "dic";
                }
            }
            else if (Type.Arity == 1)
            {
                snippet.RemoveLiteralAndReplacePlaceholders(LiteralIdentifiers.TypeParameterList, language.GetTypeParameterList($"${LiteralIdentifiers.TypeParameter}$"));
                snippet.AddLiteral(LiteralIdentifiers.TypeParameter, null, "T");
            }
            else
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.TypeParameterList);
            }

            if (!Tags.Contains(KnownTags.Arguments) &&
                !(Type.IsReadOnly && Tags.Contains(KnownTags.Collection)))
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.Arguments);
            }

            snippet.SetFileName(fileName + Path.GetFileName(snippet.FilePath));

            if (snippet.HasTag(KnownTags.Initializer) &&
                Tags.Contains(KnownTags.Initializer))
            {
                var clone = (Snippet)snippet.Clone();
                InitializerCommand.AddInitializer(context, clone, GetInitializer(language), language.GetDefaultValue());
                context.Snippets.Add(clone);
            }
            else
            {
                snippet.RemoveLiteralAndPlaceholders(LiteralIdentifiers.Initializer);
            }
        }