饭饭TXT > 学习管理 > 《Visual Studio 2010 高级编程(英文出书版)》作者:Nick Randolph/等【完结】 > [Visual.Studio.2010.高级编程].Professional.Visual.Studio.2010.txt

第 21 页

作者:Nick Randolph/等 当前章节:15403 字 更新时间:2026-6-18 14:51

create SQL scripts for the database schema only or schema and data. You can also provide custom

SQL scripts to be executed either before or after the auto-generated script.

fiGure 6-26

Chapter 49 explores the web application deployment options in more detail.

web site ProJects

The Web Site project functions quite differently from other project types. Web Site projects do

not include a .csproj or .vbproj file, which means they have a number of limitations in terms of

build options, project resources, and managing references. Instead, Web Site projects use the folder

summary .

117

structure to define the contents of the project. All files within the folder structure are implicitly part

of the project.

Web Site projects provide the advantage of dynamic compilation, which allows pages to be edited

without rebuilding the entire site. The file can be saved and simply reloaded in the browser. As such

they enable extremely short code and debug cycles. Microsoft first introduced Web Site projects

with Visual Studio 2005; however, it was quickly inundated with customer feedback to reintroduce

the Application Project model, which had been provided as an additional download. By the release

of Service Pack 1, Web Application projects were back within Visual Studio as a native project type.

Since Visual Studio 2005, an ongoing debate has been raging about which is

better — Web Site projects or Web Application projects. Unfortunately, there is

no simple answer to this debate. Each has its own pros and cons, and the

decision comes down to your requirements and your preferred development

workflow.

You can find further discussion on Web Site and Web Application projects in Chapter 20.

suMMary

In this chapter you have seen how a solution and projects can be configured using the user interfaces

provided within Visual Studio 2010. In particular, this chapter showed you how to do the following:

.

Create and configure solutions and projects.

.

Control how an application is compiled, debugged, and deployed.

.

Configure the many project-related properties.

.

Include resources and settings with an application.

.

Enforce good coding practices with the Code Analysis Tools.

.

Modify the configuration, packaging, and deployment options for web applications.

In subsequent chapters many of the topics, such as building and deploying projects and the use of

resource files, are examined in more detail.

7 7

intellisense and Bookmarks

what’s in this chaPter?

.

Improving efficiency with contextual help

.

Detecting and fixing simple errors

.

Reducing keystrokes

.

Generating code

.

Navigating source code with bookmarks

One thing that Microsoft has long been good at is providing automated help as you write your

code. Older versions of Visual Basic had a limited subset of this automated intelligence known

as IntelliSense, but with the introduction of Visual Studio .NET, Microsoft firmly established

the technology throughout the whole IDE. With recent releases of Visual Studio, IntelliSense

has become so pervasive that it has been referred to as IntelliSense Everywhere.

This chapter illustrates the many ways in which IntelliSense helps you write your code.

Among the topics covered are detecting and repairing syntax errors, harnessing contextual

information, and variable name completion. You also learn how to set and use bookmarks in

your code for easier navigation.

intellisense exPlained

IntelliSense is the general term for automated help and actions in a Microsoft application. The

most commonly encountered aspects of IntelliSense are those wavy lines you see under words

that are not spelled correctly in Microsoft Word, or the small visual indicators in a Microsoft

Excel spreadsheet that inform you that the contents of the particular cell do not conform to

what was expected.

120 .

chaPter 7 inTelliSenSe And bookmArkS

Even these basic indicators enable you to quickly perform related actions. Right-clicking a word

with red wavy underlining in Word displays a list of suggested alternatives. Other applications have

similar features.

The good news is that Visual Studio has had similar functionality for a long time. In fact, the

simplest IntelliSense features go back to tools such as Visual Basic 6. With each release of Visual

Studio, Microsoft has refined the IntelliSense features, making them more context-sensitive and

putting them in more places so that you should always have the information you need right at your

fingertips.

In Visual Studio 2010, the IntelliSense name is applied to a number of different features from visual

feedback for bad code and smart tags for designing forms to shortcuts that insert whole slabs of

code. These features work together to provide you with deeper insight, efficiency, and control of

your code. Some of the features new to Visual Studio 2010, such as suggestion mode and Generate

From Usage, are designed to support the alternative style of application development known as

test-driven development (TDD).

General intellisense

The simplest feature of IntelliSense gives you immediate feedback about bad code in your code

listings. Figure 7-1 shows one such example, in which an unknown data type is used to instantiate

an object. Because the data type is unknown where this code appears, Visual Studio draws a red

(C#) or blue (VB) wavy line underneath to indicate a problem.

fiGure 7-1

The formatting of this color feedback can be adjusted in the Fonts and Colors

group of Options.

Hovering the mouse over the offending piece of code displays a tooltip to explain the problem.

In this example the cursor was placed over the data type, with the resulting tooltip “The type or

namespace name ‘Customer’ could not be found.”

Visual Studio is able to look for this kind of error by continually precompiling the code you write

in the background, and looking for anything that will produce a compilation error. If you were to

add the Customer class to your project, Visual Studio would automatically process this and remove

the IntelliSense marker.

Figure 7-2 displays the smart tag associated with the error. This applies only to errors for which

Visual Studio 2010 can offer you corrective actions. Just below the problem code, a small blue (C#)

or red (VB) rectangle is displayed. Placing the mouse

cursor over this marker displays the smart tag action

menu associated with the type of error — in this case

the action menu provides options for generating your

Customer class from what Visual Studio is able to

determine from the way you have used it.

The smart tag technology found in Visual Studio

is not solely reserved for the code window. In fact,

Visual Studio 2010 also includes smart tags on visual

components when you are editing a form or user control

in Design view (see Figure 7 - 3).

When you select a control that has a smart tag, a small

triangle appears at the top - right corner of the control

itself. Click this button to open the smart tag Tasks list — Figure 7 - 3 shows the Tasks list for a

standard TextBox control.

completing words and Phrases

The power of IntelliSense in Visual Studio 2010 becomes apparent as soon as you start writing code.

As you type, various drop - down lists are displayed to help you choose valid members, functions,

and parameter types, thus reducing the number of potential compilation errors before you even

fi nish writing your code. Once you become familiar with the IntelliSense behavior, you ’ ll notice that

it can greatly reduce the amount of code you actually have to write. This can be a signifi cant savings

to developers using more verbose languages such as Visual Basic.

in Context

In Visual Studio 2010, IntelliSense appears almost as soon as you begin to type within the code

window. Figure 7 - 4 illustrates the IntelliSense displayed during the creation of a For loop in Visual

Basic. On the left side of the image, IntelliSense appeared as soon as the f was entered, and the list

of available words progressively shrank as each subsequent key was pressed. As you can see, the list

fiGure 7 - 2

fiGure 7 - 3

The standard shortcut key used by all Microsoft applications to activate an

IntelliSense smart tag is Shift+Alt+F10, but Visual Studio 2010 provides the

more wrist - friendly Ctrl+. shortcut for the same action.

The keyboard shortcuts for opening smart tags also work for visual controls.

intellisense explained . 121

122 . chaPter 7 inTelliSenSe And bookmArkS

is made up of all the alternatives, whether they

be statements, classes, methods, or properties,

that match the letters entered (in this case those

containing the word For ).

Notice the difference in the right - hand image

of Figure 7 - 4, where a space has been entered

after the word for . Now the IntelliSense list

has expanded to include all the alternatives that

could be entered at this position in the code.

In addition, there is a tooltip that indicates the

syntax of the For statement. Lastly, there is a

< new variable > item just above the IntelliSense

list. This is to indicate that it ’ s possible for you

to specify a new variable at this location.

Although it can be useful that the IntelliSense list is reduced based on the letters you enter, this

feature is a double - edged sword. Quite often you will be looking for a variable or member but won ’ t

quite remember what it is called. In this scenario, you might enter the fi rst couple of letters of a

guess and then use the scrollbar to locate the right alternative. Clearly, this won ’ t work if the letters

you have entered have already eliminated the alternative. To bring up the full list of alternatives,

simply hit the Backspace key with the IntelliSense list visible.

In previous versions of Visual Studio, IntelliSense has only been able to help you fi nd members

that began with the same characters that you typed into the editor. In Visual Studio 2010 this is

no longer true. Now it is possible to fi nd words that appear in the middle of member names as

well. It does this by looking for word boundaries

within the member names. Figure 7 - 5 shows an

example in C# where typing Console.in will

fi nd In , InputEncoding , OpenStandardInput ,

SetIn , and TreatControlCAsInput but does not

fi nd LargestWindowHeight despite the fact that it

contains the substring “ in. ” fiGure 7 - 5

fiGure 7 - 4

The < new variable > item appears only for Visual Basic users.

If you know exactly what you are looking for, you can save even more

keystrokes by typing the fi rst character of each word in uppercase. As an

example, if you type System.Console.OSI , then OpenStandardInput will be

selected by IntelliSense.

intellisense explained .

123

If you find that the IntelliSense information is obscuring

other lines of code, or you simply want to hide the list, you

can press Esc. Alternatively, if you simply want to view

what is hidden behind the IntelliSense list without closing it

completely, you can hold down the Ctrl key. This makes the

IntelliSense list translucent, enabling you to read the code

behind it, as shown in Figure 7-6. fiGure 7-6

The IntelliSense list is not just for informational purposes. You can select an item from this list

and have Visual Studio actually insert the full text into the editor window for you. You have a

number of ways to select an item from the list. You can double-click the desired item with the

mouse; you can use the arrow keys to change which item is highlighted and then press the Enter or

Tab keys to insert the text; and finally, when an item is highlighted in the list it will automatically

be selected if you enter a commit character. Commit characters are those that are not normally

allowed within member names. Examples include parentheses, braces, mathematical symbols, and

semicolons.

list Members

Because IntelliSense has been around for so long, most developers will be familiar with the member

list that appears when you type the name of an object and immediately follow it by a period. This

indicates that you are going to refer to a member of the object, and Visual Studio automatically

displays a list of members available to you for that object (see Figure 7-7). If this is the first time

you’ve accessed the member list for a particular object, Visual Studio simply shows the member list

in alphabetical order with the top of the list visible. However, if you’ve used it before, it highlights

the last member you accessed to speed up the process for repetitive coding tasks.

Figure 7-7 also shows another helpful aspect of the member list for Visual Basic programmers.

The Common and All tabs (at the bottom of the member list) enable you to view either just the

commonly used members or a comprehensive list.

fiGure 7-7

124 . chaPter 7 inTelliSenSe And bookmArkS

suggestion Mode

By default, when Visual Studio 2010 shows the IntelliSense member list, one member is selected and

as you type, the selection is moved to the item in the list that best matches the characters entered.

If you press Enter, Space, or type one of the commit characters (such as an open parenthesis), the

currently selected member is inserted into the editor window. This default behavior is known as

“ completion mode. ”

In most cases completion mode provides the desired behavior and can save you a great deal of

typing, but it can be problematic for some activities. One such activity is test - driven development

where references are frequently made to members that have not yet been defi ned. This causes

IntelliSense to select members that you didn ’ t intend it to and insert text that you do not want.

To avoid this issue Microsoft has introduced a new IntelliSense mode into Visual Studio 2010 called

suggestion mode . When IntelliSense is in suggestion mode one member in the list will have focus

but will not be selected by default. As you type, IntelliSense moves the focus indicator to the item

目录
设置
设置
阅读主题
字体风格
雅黑 宋体 楷书 卡通
字体大小
适中 偏大 超大
保存设置
恢复默认
手机
手机阅读
扫码获取链接,使用浏览器打开
书架同步,随时随地,手机阅读
首 页 < 上一章 章节列表 下一章 > 尾 页