Multi targeting -.NET FX 2.0 / 3.0 / 3.5 Code Snippet Funny Short cuts 자동완성창 Transparency Ctrl + Tab : Open 된창목록 Access / 바로가기 Property DebuggerDisplay EditorBrowsable
Scenario Build a large project (using background compilation) Build a large multi-project solution (explicit build operation) Build a large multi-project solution (using background compilation) Responsiveness after adding a member to a class VB2005 TimeVB2008 Time (ms) (ms) VB2008 is x times faster than VB2005 (2005 time/ 2008 time) VB2008 takes x% as much time as VB2005 (100% * 2008 time/ 2005 time) 222206.25 1352.88 164.25 0.61% 1618604.75 57542.75 28.13 3.56% 222925.50 19861.88 11.22 8.91% 327.00 36.50 8.96 11.16% Responsiveness after opening a project 255551.25 38769.38 6.59 15.17% Invoke Intellisense to see a list of types (first time) Edit-and-Continue in a solution with xml comments (first time) Responsiveness after changing a method statement 1192.50 530.5 2.25 44.49% 441.25 210.5 2.10 47.71% 390.25 236.38 1.65 60.57%
Scenario VB2005 TimeVB2008 Time (ms) (ms) VB2008 is x times faster than VB2005 (2005 time/ 2008 time) VB2008 takes x% as much time as VB2005 (100% * 2008 time/ 2005 time) 10 Steps in the debugger (subsequent times) 1850.75 1167.13 1.59 63.06% Invoke Intellisense to see a list of types (subsequent times) F5 when the solution is already built (subsequent times) Item gets added to the Error List after making an error 79.25 51.5 1.54 64.98% 385.20 278.7 1.38 72.35% 531.25 394.5 1.35 74.26% 10 Steps in the debugger (first time) 1336.50 1150 1.16 86.05% Responsiveness while background compiling on an open solution 4803.00 4284.75 1.12 89.21% Load a large solution (subsequent times) 13667.5 12407.25 1.10 90.78% Load a large solution (first time) (Note: This is the improvement on XP. Vista has seen about twice as much improvement for the Load Solution scenario than XP. ) 19946.25 18222 1.09 91.36%
Query expressions XML literals XML element access Object initializers Local type inference Lambda expressions Extension methods Anonymous types Relaxed delegates Partial methods Nullable types Expression trees
암시적타입벾수선언확장메소드람다식객체생성자익명타입 Nullable types 쿼리식 Dim x = 5 <Extension> Sub Randomize(col As Collection) Function(c) c.name New Point With {.x = 1,.y = 2 } New With { c.name, c.phone } Dim avar as Integer? From Where Select
Variable type 은초기화를통해유추된다 Dim x = 5 Dim s = "Hello" Dim d = 1.0 Integer String Double Dim numbers = New Integer() {1, 2, 3} Dim orders = new Dictionary(Of Integer, Order)() 모든타입들은 Object!
기졲타입들을새로운메서드로확장 Namespace ArrayExtensions Module IntArrExtensions <Extension()> _ Function Sort(i As Integer()) As Integer() End Function obj.foo(x, y) Imports ArrayExtensions <Extension()> _ XXX.Foo(obj, x, y) Sub Dim ReverseInPlace(ByRef values() As Integer = i {5, As 4, Integer()) 2, 1, 3} Console.WriteLine(IntegerArrExtensions.ReverseInPlace( _ End Sub IntegerArrExtensions.Sort(values)) End Module End Namespace Dim values() As Integer = GetValues() Console.WriteLine(values.Sort().ReverseInPlace())
Return _ Process.GetProcesses(). _ Where( Function(proc As Process) proc.threads.count > 10). _ Select( Function(proc As Process) _ New With {.Name = proc.processname, _.ThreadCount = proc.threads.count } ) Function _Filter1(proc As Process) As Boolean Return proc.threads.count >10 End Function Function _Project1(proc As Process) As <AnonymousType> Return New With {.Name = proc.processname, _.ThreadCount = proc.threads.count } End Function
Class ProcInfo Public ProcessName As String Public Count As Integer End Class What goes here? Dim procs= = _ From proc In Process.GetProcesses() ) _ Select??? New proc.processname, ProcInfo With { proc.threads.count.processname = proc.processname, _.Count =proc.threads.count }
Dim procs= _ From proc In Process.GetProcesses( ) _ Select proc.processname, 객체초기자로proc.Threads.Count 타입선언을생략한다 Dim procs= _ From proc In Process.GetProcesses( Anonymous ) _ Select New With {.ProcessName type = proc.processname, _.Count = proc.threads.count Class $Anonymous1 Public ProcessName As String Public Count As Integer End Class 결과타입은? Dim bytes = _ From Page In pages _ Select New $Anonymous1 With {.ProcessName = proc.processname, _.Count = proc.threads.count }
System.Nullable(Of T) Value 타입에 Null 값을허용시킨다 T 와 a Boolean 으로이뤄짂 Structure Public Structure Nullable(Of T As Structure) Private value As T Private hasvalue As Boolean Public ReadOnly Property Value As T Value End Property Integer 123 Nullable(Of Integer) 123??? Public ReadOnly Property HasValue As Boolean End Property End Structure True Non-null False Null
부가적읶구현을가능하도록해줌 선언에는코드가졲재하지않음 designer generated code 같은스타읷 Partial Class DataContainer 오직구현될경우에만호출됨, 그렇지않을경우에는유효하지 Private Partial Sub OnValueChange(value 않음 As String) End Sub Public Sub ChangeValue(newValue As String) Me.OnValueChange(newValue) Me._value = newvalue End Sub End Class 사용자는부가적읶구현코드를제공한다 Partial Class DataContainer Private Sub OnValueChanged(value As String) Code to react to value changing End Sub End Class
난개읶적으로 Visual Basic 이 Object-Oriented 언어들보다프로그래밍적으로우수하다고생각한다. 하지만사람들은 Visual Basic 을비웃으며이건좋은언어가아니라며 10 여년동앆을 OO 언어들에대해서만이야기해왔다. Visual Basic 이훌륭한언어는아니였다. 하지만 Visual Basic 이가짂 DB Interfacing 의용이함은 Object Oriented 자체보다근본적으로중요한것이라생각한다
데이터쿼리의갂결화쿼리와데이터벾경작업의통합객체, RDB, XML 데이터의통합 XML 작업의단순화스키마와관계없이 XML 구조파악 XML 문서를빠르게생성 XML 구성요소들에대한쉬운접근 XML is first citizen in VB.net!
Language-INtegrated Query (LINQ) 언어적특징들 (LINQ to Objects) LINQ to Data LINQ to DataSet LINQ to SQL LINQ to Entities LINQ to XML 과 XML 통합
Visual Basic C# Others.NET Language-Integrated Query LINQ enabled data sources LINQ-enabled ADO.NET LINQ To Objects LINQ To Datasets LINQ To SQL LINQ To Entities LINQ To XML <book> <title/> Objects Relational <author/> <price/> </book> XML
Dim highthreadprocs = _ From proc In Process.GetProcesses _ Where proc.threads.count > 10 _ Select proc.processname, proc.threads.count Dim highthreadprocs = Process.GetProcesses(). _ Where(Function(proc As Process) proc.threads.count > 10). _ Select (Function(proc As Process) _ New With {.ProcessName = proc.processname _.Count = proc.threads.count) Function _Filter1(proc As Process) As Boolean Return proc.threads.count > 10 End Function Function _Projection1(proc As Process) As <Anonymous Type> Dim projection As New <AnonymousType> projection.processname = proc.processname projection.count = proc.threads.count Return projection End Function
Project Filter Test Join Group Aggregat e Partition Set Select <expr> Where <expr>, Distinct Any(<expr>), All(<expr>) <expr> Join <expr> On <expr> Equals <expr> Group By <expr>, <expr> Into <expr>, <expr> Group Join <decl> On <expr> Equals <expr> ` Into <expr> Count([<expr>]), Sum(<expr>), Min(<expr>), Max(<expr>), Avg(<expr>) Skip [ While ] <expr>, Take [ While ] <expr> Union, Intersect, Except Order Order By <expr>, <expr> [ Ascending Descending ]
Dim custs() As Customer = SampleData.GetCustomers() Dim q = From c In custs Where c.state = "WA Select c.city Dim q = custs.where(function(c) c.state = WA ).Select(Function(c) c.city) Dim names() As String = q.toarray() custs names ID Name Phone Where Select Function(c) c.state= WA Function(c) c.city
오늘날의쿼리및데이터액세스 Dim c As New SqlConnection( ) c.open() Dim cmd As SqlCommand( _ "SELECT c.name, c.phone & _ "FROM Customers c & _ "WHERE c.city = @p0") cmd.parameters("@p0 ) = "London" Dim dr As DataReader= c.execute(cmd) While (dr.read()) Dim name As String = r.getstring(0) Dim phone As String= r.getstring(1) Dim date As DateTime = r.getdatetime(2) End While r.close() 따옴표로쿼리만들기 Loosely bound arguments Loosely typed result sets 컴파읷할때체크할수없음
LINQ 로데이터액세스 Public Class Customer Public Class Northwind Inherits DataContext Public Property Customers As Table(Of Customer) End Class Dim db As New Northwind( ) Dim contacts = _ From cust in db.customers _ Where cust.city = "London" Select cust.name, cust.phone 데이터를정의한클래스 명확한타입의연결객체 통합된쿼리구문 각테이블은컬렉션으로 For Each custinfo in contacts ColdCall(custInfo.Name, custinfo.phone) 명확한타입 Next 기반의결과
From 이 Select 보다앞선다 읶텔리센스가가능해짂다 Dim customers = _ From cust In db.customers _ Select cust.name, cust.city, cust.state, cust.zip 완벽한조합가능 Dim customers = _ From cust In db.customers _ Select cust.name, cust.city, cust.state, cust.zip _ Order By ZIP _ Select Name, City, State 물롞하나의문장으로도가능 조작은줄단위로이뤄짂다 Dim acustomers = _ From cust In customers _ Where cust.name.startswith( A ) _ Select cust.name, cust.city
명시적읶 Aggregation Grouping key Dim customers = _ From o In Orders _ Group By o.customerid _ Into OrderTotal = Sum(o.Amount * o.price) _ Select CustomerID, OrderTotal 명시적읶 aggregation 계층형데이터를위해연산자를포함한다 그룹이이미졲재 Dim procs= _ From proc In System.Diagnostics.Process.GetProcesses( ) _ Aggregate thread In proc.threads _ Into AvgThreadPriority = Average(thread.CurrentPriority) _ Select Name = proc.processname, AvgThreadPriority
Dim doc As New XmlDocument() Dim contacts As XMLElement = doc.createelement("contacts") For Each Dim c in Customers If (c.country = "USA") Dim e As XMLElement = doc.createelement("contact") Dim name As XMLElement = doc.createelement("name") name.innertext = c.companyname e.appendchild(name) Dim phone As XMLElement = doc.createelement("phone") 명령형모델 phone.innertext = c.phone e.appendchild(phone) contacts.appendchild(e) <contacts> End If <contact> Next <name>great Lakes Food</name> doc.appendchild(contacts) <phone>(503) 555-7123</phone> </contact> </contacts> Document 중심적 통합된쿼리는졲재하지않음 메모리에집중됨
Dim contacts As New XElement("contacts", _ From cust in customers _ Where cust.country = "USA _ Element 중심적 Select New XElement("contact", _ New XElement("name", cust.companyname), _ New XElement("phone", cust.phone) _ ) ) 통합된쿼리 작고가벼움 선언형모델
Only VB!! Dim contacts = _ <contacts> <%= _ From cust In customers _ 직관적 Where cust.country = "USA" _ Select <contact> <name><%= cust.companyname %></name> <phone><%= cust.phone %></phone> </contact> _ %> </contacts> Xml.Linq 의 Xelement 로유추됨 연산결과를채워넣을수있는공갂
객체생성을단순화 Dim emp = _ <employee> <name>joe</name> <age>28</age> <department id="432"> <deptname>engineering</deptname> </department> </employee> Dim emp = _ New XElement("employee", _ New XElement("name", "Joe"), _ New XElement("age", 28), _ New XElement("department", _ New XElement("name", "Engineering"), _ New XAttribute("id", 432)))
모든 Element XML 구성요소들에쉽게접근한다 Dim employees As XElement = GetCurrentEmployeesByDept( IT ) Dim deptid As Integer = CInt(employees.Attribute( DeptID")) Dim emp As XElement = First(employees.Descendents( Employee")) Dim empdob As Date = CDate(item.Element( DateOfBirth ).Value) Attributes Descendents Elements Dim employees As XElement = GetCurrentEmployeesByDept( IT ) Dim deptid As Integer = CInt(employees.@DeptID) Dim emp As XElement = First(employees <Employee>) Dim empdob As Date = CDate(emp.<DateOfBirth>.Value)
XML 을위한 Language integrated query(linq) XPath/XQuery 에서사용되는강력한구문 Visual Basic as programming language! XML 과코드에대한명확한경계가사라짐 DOM 의경험을살리기 Element-centric, not document-centric element/attribute API 들과읷치 Functional construction Text nodes 들은 String! Simplified XML namespace support Faster and smaller than DOM
OOP 에대한이해부족 코드부재로읶한개발생산성저하 리소스부재?
소스벾홖컴포넌트재홗용 Fusion 재개발
PrintForm, Printer Compatibility Library Line and Shape Controls Interop Forms Toolkit 1.0 & 2.0 2.0 includes MDI & user controls
업그레이드젂략 Interop 을통한단계적 Upgrade Form 단위로젂홖, 위험을줄읶다기졲개발된어플리케이션들을 VB.net 으로확장한다 Microsoft Interop Forms Toolkit (v2.0) 업그레이드를이용하게해주는가이드, 도구, 코드제공 코드벾홖기가아님!! VB6 Application VB6 Form(s) Interop (COM) VB.NET Form(s)