Microsoft .NET Framework. 3.

2

Microsoft .NET Framework - Microsoft .NET, , Web- . Microsoft .NET Framework . Common Language Runtime (CLR) - .NET-. Common Language Runtime Common Type System.

, .

.NET Framework Class Library , :

  • ;
  • ;
  • / ;
  • ;
  • ;
  • Windows-;
  • Web-;
  • Web-.

, .NET Framework Class Library (namespaces). , - /, Web-, XML- .. .NET.

.NET. - Object, .NET, Console . , .

Console

System.Console, .NET - , . , Console.

Console , . , , (input stream) (output stream). (error output stream). In, Out Error Console. - System.IO.TextReader, - System.IO. TextWriter. , , ..

Visual Basic .NET, , Main - :

'---------------------------------------
' .NET -
'---------------------------------------
Imports System
Module Cons

Sub Main()

Console.WriteLine(".NET Console application")
Console.ReadLine()

End Sub

End Module

Read ReadLine , Write WriteLine - .

SetIn, SetOut SetError , . TextWriter, .

Microsoft .NET Class Library. System .

System

System Microsoft .NET Class Library , .NET Framework. Object, .NET, , 100 , , , ..

Object

System.Object .NET. , , .

:

  • Equals (Object) Equals (Object, Object) - , . ( ValueType) . : , Equals , ; Equals , .
  • ReferenceEquals (Object, Object) , .
  • Finalize() . , (Garbage Collector) .
  • GetHashCode() - ( Integer), -.
  • MemberwiseClone() .
  • ToString() . .
  • GetType() Type .

, Type.

Type Reflection

Type Reflection. (Reflection) .NET - . , , , , , , , , , .

Type GetMethods() GetProperties(), . , Reflection, , , ( System.Reflection. MethodInfo) Invoke().

, . , GetType() Type :

'-------------------------------------------
' .NET GetType
'-------------------------------------------

Imports System
Imports System.Reflection

Module Cons

Sub Main()

Dim I As Integer
Dim T As Type

T = I.GetType()
Console.WriteLine("Name = " & T.Name)
Console.WriteLine("Module = " & T.Module.ToString())
Console.WriteLine("Namespace = " & T.Namespace)

End Sub

End Module

, Reflection, .

  • Assembly , (assembly manifest), , , .
  • Module , , .
  • ConstructorInfo , , . GetConstructors() GetConstructor() Type.
  • MethodInfo , , , . GetMethods() GetMethod() Type.
  • - , .. - FieldInfo. , .
  • EventInfo , . .
  • PropertyInfo , . .
  • ParameterInfo - , , ..

, , .

'-------------------------------------------
' .NET - ""
'-------------------------------------------

Imports System
Imports System.Reflection

Module Cons

Sub Main()

Dim I As Integer
Dim T As Type
Dim Types() As Type
Dim M As [Module]

T = I.GetType()
M = T.Module
Types = M.GetTypes()
For Each T In Types
Console.WriteLine(T.FullName)
Next

End Sub

End Module

:

, ITypeLibrary Win32 API , .NET , .

, , , . GetProperties(), GetConstructors(), GetMethods(), GetInterfaces() GetEvents() Type. PropertyInfo, MethodInfo, EventInfo .. - MemberInfo, . PropertyInfo - , :

'-------------------------------------------
' .NET - ""
'-------------------------------------------

Imports System
Imports System.Reflection
Module Cons

Sub Main()

Dim T As Type
Dim MI As MemberInfo
Dim Types() As Type
Dim Members() As MemberInfo
Dim M As [Module]
Dim PI As PropertyInfo
Dim PText As String
T = Type.GetType("System.Array")
Console.WriteLine("{0} : {1}", GetTypeDescription(T), T)

'
'
'
Console.WriteLine("---- ----")
Members = T.GetProperties
For Each MI In Members
PI = MI
If PI.CanRead And PI.CanWrite Then
PText = "get; set;"
Else
If PI.CanRead Then
PText = "get"
Else
If PI.CanWrite Then
PText = "set"
End If
End If
End If
Console.WriteLine("{0} {1} : {2} {3}", vbTab, "Prop", _
PText, MI.ToString)
Next

'
'
'

Console.WriteLine("---- ----")
Members = T.GetConstructors(BindingFlags.Public Or _
BindingFlags.Static Or BindingFlags.NonPublic Or _
BindingFlags.Instance)
For Each MI In Members
Console.WriteLine("{0} {1} : {2}", vbTab, "Meth", _
MI.ToString)
Next

'
'
'
Console.WriteLine("---- ----")
Members = T.GetMethods
For Each MI In Members
Console.WriteLine("{0} {1} : {2}", vbTab, "Meth", MI)
Next

'
'
'
Console.WriteLine("---- ----")
Members = T.GetInterfaces
For Each MI In Members
Console.WriteLine("{0} {1} : {2}", vbTab, "Intf", _
MI.ToString)
Next

'
'
'
Console.WriteLine("---- ----")
Members = T.GetEvents
For Each MI In Members
Console.WriteLine("{0} {1} : {2}", vbTab, "Evnt", _
MI.ToString)
Next
'Next

End Sub

Private Function GetTypeDescription(ByVal aType As Type) As String
Dim str As String = Nothing

If aType.IsClass Then
str = "Class"
End If

If aType.IsInterface Then
str = "Interface"
End If

If aType.IsValueType Then
str = "Struct"
End If

If aType.IsArray Then
str = "Array"
End If

Return str
End Function 'GetTypeDescription

End Module

, System.Array:

Class : System.Array
---- ----
Prop : get Int32 Length
Prop : get Int32 Rank
Prop : get System.Object SyncRoot
Prop : get Boolean IsReadOnly
Prop : get Boolean IsFixedSize
Prop : get Boolean IsSynchronized
---- ----
Meth : Void .ctor()
---- ----
Meth : System.Collections.IEnumerator GetEnumerator()
Meth : Boolean get_IsSynchronized()
Meth : System.Object get_SyncRoot()
Meth : Void CopyTo(System.Array, Int32)
Meth : Boolean get_IsFixedSize()
Meth : Boolean get_IsReadOnly()
Meth : System.Object Clone()
Meth : Int32 GetHashCode()
Meth : Boolean Equals(System.Object)
Meth : System.String ToString()
Meth : System.Array CreateInstance(System.Type, Int32)
Meth : System.Array CreateInstance(System.Type, Int32, Int32)
Meth : System.Array CreateInstance(System.Type, Int32, Int32, Int32)
Meth : System.Array CreateInstance(System.Type, Int32[])
Meth : System.Array CreateInstance(System.Type, Int32[], Int32[])
Meth : Void Copy(System.Array, System.Array, Int32)
Meth : Void Copy(System.Array, Int32, System.Array, Int32, Int32)
Meth : Void Clear(System.Array, Int32, Int32)
Meth : System.Object GetValue(Int32[])
Meth : System.Object GetValue(Int32)
Meth : System.Object GetValue(Int32, Int32)
Meth : System.Object GetValue(Int32, Int32, Int32)
Meth : Void SetValue(System.Object, Int32)
Meth : Void SetValue(System.Object, Int32, Int32)
Meth : Void SetValue(System.Object, Int32, Int32, Int32)
Meth : Void SetValue(System.Object, Int32[])
Meth : Int32 get_Length()
Meth : Int32 GetLength(Int32)
Meth : Int32 get_Rank()
Meth : Int32 GetUpperBound(Int32)
Meth : Int32 GetLowerBound(Int32)
Meth : Int32 BinarySearch(System.Array, System.Object)
Meth : Int32 BinarySearch(System.Array, Int32, Int32, System.Object)
Meth : Int32 BinarySearch(System.Array, System.Object,
System.Collections.IComparer)
Meth : Int32 BinarySearch(System.Array, Int32, Int32, System.Object,
System.Collections.IComparer)
Meth : Int32 IndexOf(System.Array, System.Object)
Meth : Int32 IndexOf(System.Array, System.Object, Int32)
Meth : Int32 IndexOf(System.Array, System.Object, Int32, Int32)
Meth : Int32 LastIndexOf(System.Array, System.Object)
Meth : Int32 LastIndexOf(System.Array, System.Object, Int32)
Meth : Int32 LastIndexOf(System.Array, System.Object, Int32, Int32)
Meth : Void Reverse(System.Array)
Meth : Void Reverse(System.Array, Int32, Int32)
Meth : Void Sort(System.Array)
Meth : Void Sort(System.Array, System.Array)
Meth : Void Sort(System.Array, Int32, Int32)
Meth : Void Sort(System.Array, System.Array, Int32, Int32)
Meth : Void Sort(System.Array, System.Collections.IComparer)
Meth : Void Sort(System.Array, System.Array, System.Collections.IComparer)
Meth : Void Sort(System.Array, Int32, Int32, System.Collections.IComparer)
Meth : Void Sort(System.Array, System.Array, Int32, Int32,
System.Collections.IComparer)
Meth : Void Initialize()
Meth : System.Type GetType()
---- ----
Intf : System.ICloneable
Intf : System.Collections.IList
Intf : System.Collections.ICollection
Intf : System.Collections.IEnumerable

, - . , GetParameters() ParameterInfo. , :

'
'
'
Console.WriteLine("---- ----")
Members = T.GetMethods
For Each MI In Members
PAInfo = CType(MI, MethodInfo).GetParameters
If PAInfo.Length > 0 Then
Console.WriteLine("{0} {1} : {2}{3}", vbTab, "Meth", MI.Name, "(")
For Each PAI In PAInfo
Console.WriteLine(" {0} {1} : {2}", vbTab, PAI.Name, _
PAI.ParameterType.ToString)
Next
Console.WriteLine("{0}{1}", vbTab, ")")
Else
Console.WriteLine(" {0} {1} : {2}{3}", vbTab, "Meth", MI.Name, _
"()")
End If
Next

:

---- ----
Meth : GetEnumerator()
Meth : get_IsSynchronized()
Meth : get_SyncRoot()
Meth : CopyTo(
array : System.Array
index : System.Int32
)
Meth : get_IsFixedSize()
Meth : get_IsReadOnly()
Meth : Clone()
Meth : GetHashCode()
Meth : Equals(
obj : System.Object
)
Meth : ToString()
Meth : CreateInstance(
elementType : System.Type
length : System.Int32
)

...

( (- mscorlib.dll), ), . :

Imports System.Reflection
Imports System.IO
Imports Microsoft.Win32
Imports Microsoft.VisualBasic

Module Module1

Sub Main()

Dim Asm As [Assembly]
Dim Mdls As [Module]()
Dim Mdl As [Module]
Asm = [Assembly].LoadFrom(GetNetFrameworkPath() + _
"system.windows.forms.dll")
Mdls = Asm.GetModules
Mdl = Mdls(0)

End Sub

Function GetNetFrameworkPath() As String

Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\.NETFramework")
GetNetFrameworkPath = CType(Key.GetValue("InstallRoot"), String) + _
CType(Key.GetValue("Version"), String) + "\"

End Function

End Module

, ( , ), .

.NET Framework Class Library. ( System.Array) ( System.Collections).

4


 http://www.interface.ru
 http://www.interface.ru/home.asp?artId=3308