5

I have code snippet for Dbset<>

<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>DbSet</Title>
    <Author>Կյանքի Համար</Author>
    <Shortcut>dbset</Shortcut>
    <Description>Add entity into context </Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Imports>
      <Import>
        <Namespace>Domain</Namespace>
      </Import>
    </Imports>
    <Declarations>
      <Literal>
        <ID>entity</ID>
        <ToolTip>Entity</ToolTip>
        <Default>Entity</Default>
      </Literal>
    </Declarations>
    <Code Language="csharp">
      <![CDATA[public DbSet<$entity$> $entity$s { get; set; }$end$      
      ]]></Code>
  </Snippet>
</CodeSnippet>

it is generating this: public DbSet<Game> Games { get; set; }

in this part I adding namespace for this snippet.

<Imports>
    <Import>
       <Namespace>EDGE.Domain</Namespace>
    </Import>
 </Imports>

I believe that the namespace should be automatically added when I use this snippet, but it did not.

I can not find the descriptions for each attribute of .snippet file(is there any reference documentation of all supported attributes and their meaning?). Can anyone tell me what is tag for?

1 Answer 1

3

From MSDN:

Namespace Element - Specifies the namespace that must be imported for the code snippet to compile and run.

Check it out - all snippet schema tags and their attributes are described there.

Sign up to request clarification or add additional context in comments.

3 Comments

The Namespace element is only supported for Visual Basic projects. The namespace specified in the Namespace element is automatically added to an Imports Statement (.NET Namespace and Type) statement at the beginning of the code, if it does not already exist.
problem is that, it not supported for c#, only for VB
Reviving this from the dead a bit, but I thought I'd update this information to say that C# now supports this. See learn.microsoft.com/en-us/visualstudio/ide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.