Title: Introduction to .NET Platform and .NET Framework
1(No Transcript)
2???????????? ?? ?????
???????????? ?? .NET Framework
http//www.nakov.com/dotnet-project/
?????? ???????
???-????? www.gis-sofia.bg Microsoft Student
Consultant www.fmi.uni-sofia.bg/microsoft/
3?????????? ??????
- ?????? ???????? ?? .NET Framework ? CLR (Common
Language Runtime) - ?????? ???????? ?? ?????? ??????? ?? ?????? ?
.NET (Common Type System - CTS) - ?????? ???????? ?? ???????????? ?? ??????? ? .NET
(Framework Class Library - FCL) - ???????? ?? ????? C
- ???????? ?? ?????? ?? ?????
- ?????? ???????? ?? Reflection
- ???????? ?? Attributes
- ???????? ?? ?????? ? XML ? .NET Framework
4??????????
- ????????????
- XML ????????????
- ???????
- ??????????
- ??????
- ?????????? ??????????
5????????????
- ????????????
- ????? e ?????????????
- ?? ????? ?? ????????
- ???? ?????????????
- ??? ?? ????????????
- ?????? ??????e?? (Formatters)
- ???????? ?? ????????????
- ????? ?????? ????????????
- ????? ?????? ??????????????
- IDeserializationCallback
- ISerializable
- ???????????? ?? ??????????????
- Streaming Contexts
- XML ????????????
6????? e ?????????????
- ??????, ????? ??????????? ????? ??? ??????? ????
?? ?????? ?? ????? ?? ???????, ?? ??????
???????????? (Serialization) - ??????? ???? ?? ???? ??????? (binary) ??? ???????
(XML) - ????????, ????? ????? ????? ?? ??????? ??????? ??
??????, ?? ?????? ??????????????
(Deserialization) - ??????? ????????????? ??????
- ?????????? ???????? ?? ??? ???????
7?? ????? ?? ????????
- ??????????? ?? ??????????? ?? ?????
- ???? ???????? ???? ?? ??????? ??????????? ?? ??
??????? (????, ??) - ??????????? ?? ????? ???? ?????
- ??? ???????? ????? ?? ?? ???????? ?????
- .NET Framework ?? ???????? ????????
- ?? ?? ?????? session state-? ? ASP.NET
- ???????? ? clipboard ?? Windows Forms
- ????????? ?? ?????? ?? ???????? ?? ????
Application Domain ? ???? - ??????? ???????? ( Deep Copy )
- Remoting
8?? ????? ?? ???????? (2)
- ???? ???? ???? ????? ???? ????????? ? ????? ??
???????, ???? ?? ???? - ?????????
- ???????????
- ?????? ???? ??????? ?? ?????????
- ?? ??????? ?? ?????????????? ?????
- ????? ?? ?? ???????????? ???????? ????? ?? ??????
- ??????, ????? ?? ????????? ???? ????? - ?????????? ??????????? ????? ????? ???? ?? ??????
?? ????? ? ???????? ?????
9???? ?????????????
- ??????????? ?? ???? ????????? ????? ???? ?? ??
??????? ? ??? ???????????? - ?????????????? ? ????????????? ??????
??????????? ?? - ?????? ?????????? ? 10 000 ?????
- ????, ????? ??????? ?? ???? ?????? ???????? ??
???? ??????? - (???? ?? ? ??????? ? MFC)
- ???? ??? ????? ????, ????? ?? ?????? ? ?????????,
??????????? ?? ???????? ??? ??????/??????,
?????????? ?? ??????, ?????? ?????? ??? ?????
??????, ?????? ??? ?????????, ??????,
10??? ?? ????????????
String str ??? ?? ?? ???? BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin) f.Serialize(s,
str) s.Close()
- ???????, ????? ?? ?? ???????????
- ??????? ???? ?? ???? ???????? - Int32, String,
DateTime, Exception, Image, ArrayList, Hashtable,
- ?? ???? ??? ????????? ??????????, ?????????
??-?????
11??? ?? ????????????
String str ??? ?? ?? ???? BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin) f.Serialize(s,
str) s.Close()
- ????????? ?? ???????? (formatter)
- ?????????? ? ????????? ???, ????? ????????????
IFormatter - ?????????? ???? ??? ?? ??????????? ? ???????????
???????? ?? ??????
12??? ?? ????????????
String str ??? ?? ?? ???? BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin) f.Serialize(s,
str) s.Close()
- ???????, ? ????? ?? ?? ???????????? ???????
- ???? ????????? ?? ?????? ????????? ?? ???????????
???? System.IO.Stream - ???? ????????, ?? ??????? ???? ?? ?? ???????????
? MemoryStream, FileStream, NetworkStream,
13??? ?? ????????????
String str ??? ?? ?? ???? BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin) f.Serialize(s,
str) s.Close()
- ?????? ?????? ?? ????????????
- ?????????? ??????? ? reflection ?????? ????
?????????? ?? ?????? - ?????????? ?? ????-???????????? ???? ???????? -
???????????? ?? ?????? - ???????????? ?? ??????? ???? ?? ??????, ?? ??
????? ??? ???????? ???????
14?????? ????????? (Formatter)
- ??????????? ???????? ???????? ?? ???????????????
?? ???????? - ???????? ??????????? ?? ???? ??????????
- ???? reflection ???????? ??????????? ??
- ????????? (formatter) o? System.Runtime.Serializat
ion - BinaryFormatter
- SoapFormatter
- ????????????? ??????????
- ?????????? System.Runtime.Serialization.Formatter
s.Formatter ?????????? ????, ????? ???? ??????
??????????????
15???????? ?? ?????????????
16????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
17????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
18????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
19????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
20????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
21????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
22????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin , ...) f.Serialize(s,
o)
23????? ?????? - ????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Serialize() FirstExample fe new
FirstExample() BinaryFormatter f new
BinaryFormatter() Stream s new
FileStream(x.bin, ...) f.Serialize(s, o)
24????? ?????? - ??????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Deserialize() BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin, ...) FirstExample fe
(FirstExample) f.Deserialize(s, o)
25????? ?????? - ??????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Deserialize() BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin, ...) FirstExample fe
(FirstExample) f.Deserialize(s, o)
26????? ?????? - ??????????????
using System.IO using System.Runtime.Serializatio
n Serializable class FirstExample public
int number NonSerialized public int
ID public string name class Serializer
public Deserialize() BinaryFormatter f
new BinaryFormatter() Stream s new
FileStream(x.bin, ...) FirstExample fe
(FirstExample) f.Deserialize(s, o)
27???????????? 1
- SimpleBinarySerialization
28???????????? 2
29???????????? 3
30IDeserializationCallback
- ??? ??????, ? ????? ?? ?????? ???? ???? ??????? ?
??????????????, ?? ?? ???????? ??? ???? - ???????????? ????????? IDeserializationCallback ?
???????????? ?????? OnDeserialization() - ??????? ?? ????????? ???? ??????? ??????????????
?? ?????? - ???? ? ???????, ?? ?????? ???? ?????????? ??
???????????????
31???????????? 4
32???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
33???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
34???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
35???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
36???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
37???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
38???????????? ?? ??????????????
using System.Runtime.Serialization Serializable
class Person ISerializable private int
age private string name private Person(
SerializationInfo info, StreamingContext
context ) age info.GetInt32("person's
age") name (string) info.GetString("person'
s name") void ISerializable.GetObjectData(
SerializationInfo info, StreamingContext
context) info.AddValue( "person's age",
age ) info.AddValue( "person's name", name
)
39ISerializable
- ????????? ?? ????????????? ?? ?????????????
???????????? - .ctor( SerializationInfo info, StreamingContext
context ) - ?? ?????????? base(info, context)
- ISerializable.GetObjectData( SerializationInfo
info, StreamingContext context ) - ?? ?????????? base.GetObjectData(info, context)
- ????????? ?? ?????????? ????????????, ??????
???????????? ???? ??? ?? ?? ??????? ?? ?? ????????
40???????????? 5
41Streaming Contexts
- ?????? ???? ?? ??????????? ???????
- CrossProcess(0x0001), CrossMachines(0x0002),
File(0x0004), Persistence(0x0008),
Remoting(0x0010), Other(0x0020), Clone(0x0040),
CrossAppDomain(0x0080), All(0x00FF) - ?????????? ??????? ?? ????? ???? ?? ???????????,
??????? ?????? ??? ?? ??????? - ?? ??????????? ???????? ???? ?????????
- ?? ?????? ??????????,
42???????????? 6
43XML ????????????
- ????????????
- XML ????????????
- ????? ? XML ?????????????
- ???????????? ?? ???????? XML
- ??????? ?? ??????????????
44XML ????????????
- ???????????? ?? ?????????? ?????? ? ?????? ??????
(? ???? ?????? XML) ?? ?????????? ??? ????????? - XML ?????????????? ????????? ??????
- XML ?????????????? ? ???? ?? ??????????? ?? XML ?
.NET - ????????? ???????????? ?? ???? ???????? ???????
- XML ?????????????? ?? ???? ?? ?? ?????? ?
???????? ???????? ????? ?? ??????
45???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
46???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
47???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
48???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
49???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
50???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
51???????????? ?? ???????? XML
- ??????????? ?? ? ????????
using System.Xml.Serialization public class
OptionalOrder XmlElement(ElementName
"Tax_Rate") public decimal TaxRate
XmlAttribute public string FirstOrder
XmlIgnoreAttribute public bool
FirstOrderSpecified XmlArrayAttribute("Items
") XmlArrayItem("MemberName") public
OrderedItem OrderedItems XmlElement
public Employee Employees
52???????????? 7
53??????? ?? ??????????????
- ?????? ??????? ?? ??? ?? ???????
- ?????????? ?? XmlElementAttribute
- ???????? ?? ?? ????????? (? ?????? ElementName)
- XmlElementAttribute ?? ?????? ? ????????? ??
XmlAttributes - XmlAttributes ?? ?????? ??? ????????? ??
XmlAttributeOverrides - ??????????? ?? XmlAttributeOverrides ?? ???????
?? XmlSerializer
54???????????? 8
- OverridingXmlSerialization
55?????????????? ?????
????????
56?????????? FormatterServices
- ????????? ???? System.Runtime. Serialization.Forma
tterServices - ?????? ?? ????????????
- public static MemberInfo GetSerializableMembers(
Type type) - public static Object GetObjectData(Object obj,
MemberInfo members) - ?????? ?? ??????????????
- public static Type GetTypeFromAssembly( Assembly
assem, String name) - public static Object GetUninitializedObject(Type
type) - public static Object PopulateObjectMembers(Object
obj, MemberInfo members, Object data)
57??????
58?????????? ??????????
- MSDN Library, Object Serialization in the .NET
Frameworkhttp//msdn.microsoft.com/library/defaul
t.asp?url/library/en-us/dndotnet/html/objserializ
.asp?frametruehidetoctrue - MSDN Library, System.Runtime.Serialization
Namespacehttp//msdn.microsoft.com/library/defaul
t.asp?url/library/en-us/cpref/html/frlrfsystemrun
timeserialization.asp?frametruehidetoctrue - MSDN, System.Runtime.Serialization.Formatters
Namespacehttp//msdn.microsoft.com/library/defaul
t.asp?url/library/en-us/cpref/html/frlrfsystemrun
timeserializationformatters.asp?frametruehidetoc
true - MSDN, System.Runtime.Serialization.Formatters.Bina
ry Namespacehttp//msdn.microsoft.com/library/def
ault.asp?url/library/en-us/cpref/html/frlrfsystem
runtimeserializationformattersbinary.asp?frametru
ehidetoctrue - MSDN, System.Runtime.Serialization.Formatters.Soap
Namespacehttp//msdn.microsoft.com/library/defau
lt.asp?url/library/en-us/cpref/html/frlrfsystemru
ntimeserializationformatterssoap.asp?frametruehi
detoctrue - MSDN, System.Xml.Serialization Namespacehttp//ms
dn.microsoft.com/library/default.asp?url/library/
en-us/cpref/html/frlrfsystemxmlserialization.asp?f
rametruehidetoctrue
59?????????? ??????????
- MSDN Library, XmlSerializer Classhttp//msdn.micr
osoft.com/library/default.asp?url/library/en-us/c
pref/html/frlrfsystemxmlserializationxmlserializer
classtopic.asp?frametruehidetoctrueMSDN
Library, Controlling XML Serialization Using
Attributeshttp//msdn.microsoft.com/library/defau
lt.asp?url/library/en-us/cpguide/html/cpconcontro
llingserializationbyxmlserializerwithattributes.as
p?frametruehidetoctrue - MSDN, Overriding XML Serializationhttp//msdn.mic
rosoft.com/library/default.asp?url/library/en-us/
cpguide/html/cpconoverridingserializationofclasses
withxmlattributeoverridesclass.asp?frametruehide
toctrue - MSDN, Attributes That Control Encoded SOAP
Serializationhttp//msdn.microsoft.com/library/de
fault.asp?url/library/en-us/cpguide/html/cpconatt
ributesthatcontrolsoapencodedserialization.asp?fra
metruehidetoctrue - MSDN, ttributes That Control XML
Serializationhttp//msdn.microsoft.com/library/de
fault.asp?url/library/en-us/cpguide/html/cpconatt
ributesthatcontrolserialization.asp?frametruehid
etoctrue - MSDN, The XML Schema Definition Tool and XML
Serializationhttp//msdn.microsoft.com/library/de
fault.asp?url/library/en-us/cpguide/html/cpconusi
ngxmlschemadefinitiontool.asp?frametruehidetoct
rue
60?????????? ??????????
- MSDN Library, Generating SOAP Messages With XML
Serializationhttp//msdn.microsoft.com/library/de
fault.asp?url/library/en-us/cpguide/html/cpconxml
serializationusingsoapprotocol.asp?frametruehide
toctrue - .NET Serialization By Vyacheslav
Biktagirovhttp//www.csharphelp.com/archives/arch
ive38.html - CodeGuru .NET Serialization Mickey Williams
http//www.codeguru.com/columns/DotNet/article.php
/c6595/ - CodeGuru Object Serialization Using .NET Ali
Sufyanhttp//www.codeguru.com/Csharp/Csharp/cs_sy
ntax/serialization/article.php/c7201/ - CodeGuru Streams and .NET Richard
Grimeshttp//www.codeguru.com/Csharp/Csharp/cs_da
ta/streaming/article.php/c4223 - .NET Run-time Serialization -- MSDN Magazine,
April 2002 Jeffrey Richterhttp//msdn.microsoft.c
om/msdnmag/issues/02/04/net/ - .NET Run-time Serialization, Part 2 -- MSDN
Magazine, September 2002 Jeffrey
Richterhttp//msdn.microsoft.com/msdnmag/issues/0
2/07/net/ - .NET Run-time Serialization, Part 3 -- MSDN
Magazine, September 2002 Jeffrey
Richterhttp//msdn.microsoft.com/msdnmag/issues/0
2/09/net/