1

This is probably a really silly question, but I can't seem to find an answer for it. In my model classes, I always have to add in a couple of lines of using statements - for example

using System.ComponentModel.DataAnnotations

Is there any way to have that namespace included automatically in every model class so I don't have to type it in every time?

Thanks

3 Answers 3

3

Your question is similar to this one The answer in that question is you have 4 options:

  • edit it manually
  • live with it
  • change the class template (or export a second class template)
  • create the file outside the sub-directory, then drag it in

see more comments on the question

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

Comments

0

To achieve that you will need to create custom visual studio item template:

How to create a Visual Studio Item Template

Comments

0

This namespace is used for the validation attributes. I tend to write out a property in my class, and add an attribute, e.g. RequiredAttribute.

I type [Required, and after the d Visual Studio puts a little square at the bottom of the line. Hit Ctrl + . and you'll get a context menu that will add the required using statement for you. So you don't ever have to type it out by hand.

Comments

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.