SlideShare a Scribd company logo
Introduction to .NET Framework 
2- Attributes
Outlines 
مقدمة إلى الصفات .  
. Assemblyinfo.cs الملف  
البحث عن الصفات .  
.NET الصفات المبيتة في  
. System.ObsoleteAttribute الصفة  
. System.SerializableAttribute الصفة  
05 2 تشرين الثاني، 14
مقدمة إلى الصفات 
؟)Attribute( ما هي الصفة  
مبدئي ا سنعرف الصفة على أنها "معلومات إضافية يمكن تطبيقها على كتلة من 
. ")EXE أو DLL( الشيفرة البرمجية ضمن المجمعة 
أو Data Member أو Method أو Class يمكن أن تمثل هذه الكتل  
Property 
أخر يستخدم هذه )Class( يمكن الوصول إلى هذه المعلومات من أي صنف  
المُجمعة. 
Assemblyinfo.cs الملف  
. Pickling عملية تخزين الصفات ضمن المجمعة تسمى  
و والبارمترات التي نمررها هي بارامترات ال Class تصريح الصفة تمثل  
Constructor 
05 3 تشرين الثاني، 14
Assemblyinfo.cs 
using System.Reflection; 
using System.Runtime.CompilerServices; 
using System.Runtime.InteropServices; 
// General Information about an assembly is controlled through the 
following 
// set of attributes. Change these attribute values to modify the 
information 
// associated with an assembly. 
[assembly: AssemblyTitle("Training")] 
[assembly: AssemblyDescription("")] 
[assembly: AssemblyConfiguration("")] 
[assembly: AssemblyCompany("")] 
[assembly: AssemblyProduct("Training")] 
[assembly: AssemblyCopyright("Copyright © 2010")] 
[assembly: AssemblyTrademark("")] 
[assembly: AssemblyCulture("")] 
05 4 تشرين الثاني، 14
مقدمة إلى الصفات 
يمكننا مشاهدة قيم الصفات من خلال خصائص المجمعة أو من خلال الإنعكاس .  
يمكننا الآن أن نعرّف الصفة على أنها :  
يمكن أن يحوي بيانات إضافية عن المجمعة , تتعلق Class "الصفة : عبارة عن 
هذه المعلومات بالمجمعة نفسها أو بأي نوع ضمنها“ . 
[assembly: AssemblyTitle("Training")] 
هو مدى الصفة ويعني أن الصفة مطبقة على المجمعة نفسها. : Assembly  
05 5 تشرين الثاني، 14
البحث عن الصفات : 
using System; 
using System.Reflection; 
static void Main(string[] args) 
{ 
Assembly a = Assembly.LoadFrom(@"D:atom.dll"); 
object[] attributes = a.GetCustomAttributes(true); 
foreach(object o in attributes) 
{ 
Console.WriteLine(o.ToString()); 
} 
} 
05 6 تشرين الثاني، 14
ا 
05 7 تشرين الثاني، 14
.NET الصفات المبيتة في 
هي صفات Assemblyinfo.cs إن الصفات الموجودة في الملف  
خاصة بالمجمعة بحد ذاتها. 
الصفات التي سنعرضها فهي تخص الأنواع المعرفة ضمنها وأحيانا  
المجمعة بحد ذاتها. 
. System.ObsoleteAttribute الصفة  
. System.SerializableAttribute الصفة  
05 8 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
هذه الصفة تستخدم لوسم تابع بأنه لم يعد مستخدما بعد الآن .  
خلال عملية التطوير سيكون بعض المناهج التي لن يكون لها وجود  
في الإصدارة النهائية من المكتبة – وبذلك يمكن تحضير مستخدمي 
مكتبتك لغياب ميزة محددة )تابع مثلا (. 
05 9 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
[Obsolete("Use NewMethod instead")] 
public void OldMethod() 
{ 
} 
public void NewMethod() 
{ 
} 
05 10 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
عند ترجمة المشروع سنحصل على رسالة تحذير بأن هذا المنهج "مهجور  
بدلاُ NewMethod أو سُيهجر قريبا وعليك استخدام "deprecated 
منه . 
05 11 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
مع الوقت فأن جميع مستخدمين هذا المنهج سيعلمون أن عليهم تجنب  
.deprecated استخدام هذا المنهج وحتى عند استدعائه يعطيك أن هذا المنهج 
05 12 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
من شيفرتك OldMethod ومع الوقت يمكنك أن تزيل المنهج  
Obsolete تماما دون خوف لذلك يمكنك إضافة بارمتر جديد للصفة 
كما يلي: 
[Obsolete("Use NewMethod instead",true)] 
public void OldMethod() 
{ 
} 
05 13 تشرين الثاني، 14
System.ObsoleteAttribute الصفة 
وعندما يحاول المستخدمون استخدام هذا المنهج فأن  
وتتوقف عملية الترجمة . Error المترجم سيصدر خطأ 
05 14 تشرين الثاني، 14
System.SerializableAttribute الصفة 
هو الاسم الذي يطلق على ترتيب )Serialization( السّلسَلة  
واستعادة الكائنات من الذاكرة أو من الأقراص بصورتها الثنائية . 
عندما نقوم بسّلسَلة كائن فإن جميع بيانات الكائن تحُفظ ضمن وسط  
سيتم إعادة الكائن من )Deserialize( التخزين وعند إزالة السّلسَلة 
وسط التخزين إلى حالته الأصلية. 
05 15 تشرين الثاني، 14
System.SerializableAttribute الصفة 
[Serializable] 
class Employee 
{ 
public Employee(int id ,string name) 
{ 
_id = id; 
_name = name; 
} 
private int _id; 
private string _name; 
[NonSerialized] 
//this Data Member is not Serialized,Such asTransiet in JAVA 
private string _password; 
public int Id 
{ 
get { return _id; } 
set { _id = value; } 
} 
public string Name 
{ 
get { return _name; } 
set { _name = value; } 
} 
} 
05 16 تشرين الثاني، 14
System.SerializableAttribute الصفة 
م ملف نا Employee سن وم ا ن س لسلة ا 
static void Main(string[] args) 
{ 
Employee e = new Employee(1, "mohammad"); 
FileStream fs = null; 
try 
{ 
string path= @"D:file"; 
fs = new FileStream(path, FileMode.Create); 
BinaryFormatter bf = new BinaryFormatter(); 
// Serialize Object(e) in the file stream(fs) 
bf.Serialize(fs, e); 
} 
catch (Exception Ex) 
{ 
Console.WriteLine(Ex.Message); 
} 
finally 
{ 
try 
{ 
fs.Close(); 
} 
catch (Exception es) 
{ 
Console.WriteLine(es.Message); 
} 
} 
} 
05 17 تشرين الثاني، 14
System.SerializableAttribute الصفة 
فتتم كما يلي : DeSerailization أما إزالة السلسة 
نكتب ما يلي : Main ضمن التابع 
static void Main(string[] args) 
{ 
Employee e1 = null; 
try 
{ 
string path = @"D:file"; 
fs = new FileStream(path, FileMode.Open); 
BinaryFormatter bf = new BinaryFormatter(); 
e1 = (Employee)bf.Deserialize(fs); // DownCasting is mandatory 
Console.WriteLine("Id={0} name={1}",e1.Id,e1.Name); 
} 
catch (Exception Ex) 
{ 
Console.WriteLine(Ex.Message); 
} 
finally 
{ 
try 
{ 
fs.Close(); 
} 
catch (Exception ex) { Console.WriteLine(ex.Message); } 
} 
} 
05 18 تشرين الثاني، 14
05 19 تشرين الثاني، 14

More Related Content

What's hot

Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
Anton Keks
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Kavitha713564
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
Leandro Coutinho
 
Java Programming - 08 java threading
Java Programming - 08 java threadingJava Programming - 08 java threading
Java Programming - 08 java threading
Danairat Thanabodithammachari
 
Java nio ( new io )
Java nio ( new io )Java nio ( new io )
Java nio ( new io )
Jemin Patel
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
aminmesbahi
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
Abhi Arya
 
parenscript-tutorial
parenscript-tutorialparenscript-tutorial
parenscript-tutorialtutorialsruby
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 
Got database access? Own the network!
Got database access? Own the network!Got database access? Own the network!
Got database access? Own the network!
Bernardo Damele A. G.
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Winl xf
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
Gerald Villorente
 
CppUnit using introduction
CppUnit using introductionCppUnit using introduction
CppUnit using introduction
Iurii Kyian
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
Kwangshin Oh
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
 

What's hot (20)

55j7
55j755j7
55j7
 
Java Course 9: Networking and Reflection
Java Course 9: Networking and ReflectionJava Course 9: Networking and Reflection
Java Course 9: Networking and Reflection
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Java 7 & 8 New Features
Java 7 & 8 New FeaturesJava 7 & 8 New Features
Java 7 & 8 New Features
 
Java Programming - 08 java threading
Java Programming - 08 java threadingJava Programming - 08 java threading
Java Programming - 08 java threading
 
Java nio ( new io )
Java nio ( new io )Java nio ( new io )
Java nio ( new io )
 
Cp7 rpc
Cp7 rpcCp7 rpc
Cp7 rpc
 
The Java Memory Model
The Java Memory ModelThe Java Memory Model
The Java Memory Model
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
parenscript-tutorial
parenscript-tutorialparenscript-tutorial
parenscript-tutorial
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Got database access? Own the network!
Got database access? Own the network!Got database access? Own the network!
Got database access? Own the network!
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Erlang Message Passing Concurrency, For The Win
Erlang  Message  Passing  Concurrency,  For  The  WinErlang  Message  Passing  Concurrency,  For  The  Win
Erlang Message Passing Concurrency, For The Win
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
Why Drupal is Rockstar?
Why Drupal is Rockstar?Why Drupal is Rockstar?
Why Drupal is Rockstar?
 
CppUnit using introduction
CppUnit using introductionCppUnit using introduction
CppUnit using introduction
 
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 

Viewers also liked

10 system.security.cryptography
10 system.security.cryptography10 system.security.cryptography
10 system.security.cryptographyMohammad Alyan
 
8 memory managment & pointers
8 memory managment & pointers8 memory managment & pointers
8 memory managment & pointersMohammad Alyan
 
1 first lesson -assemblies
1  first lesson -assemblies1  first lesson -assemblies
1 first lesson -assemblies
Mohammad Alyan
 
Login System with Windows/Microsoft Live using OAuth php and mysql
Login System with Windows/Microsoft Live using OAuth php and mysqlLogin System with Windows/Microsoft Live using OAuth php and mysql
Login System with Windows/Microsoft Live using OAuth php and mysql
thesoftwareguy7
 
4 fourth lesson-deployment
4 fourth lesson-deployment4 fourth lesson-deployment
4 fourth lesson-deploymentMohammad Alyan
 
Fax With Sangoma Gateway
Fax With Sangoma GatewayFax With Sangoma Gateway
Fax With Sangoma Gateway
Hossein Yavari
 
3 third lesson-reflection
3 third lesson-reflection3 third lesson-reflection
3 third lesson-reflectionMohammad Alyan
 
Introduction To ERP
Introduction To ERPIntroduction To ERP
Introduction To ERP
Mohammad Alyan
 
Coursera
CourseraCoursera
Coursera
Mohammad Alyan
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
Karwin Software Solutions LLC
 

Viewers also liked (13)

10 system.security.cryptography
10 system.security.cryptography10 system.security.cryptography
10 system.security.cryptography
 
8 memory managment & pointers
8 memory managment & pointers8 memory managment & pointers
8 memory managment & pointers
 
7 multi threading
7 multi threading7 multi threading
7 multi threading
 
1 first lesson -assemblies
1  first lesson -assemblies1  first lesson -assemblies
1 first lesson -assemblies
 
5 fifth lesson -xml
5 fifth lesson -xml5 fifth lesson -xml
5 fifth lesson -xml
 
Login System with Windows/Microsoft Live using OAuth php and mysql
Login System with Windows/Microsoft Live using OAuth php and mysqlLogin System with Windows/Microsoft Live using OAuth php and mysql
Login System with Windows/Microsoft Live using OAuth php and mysql
 
4 fourth lesson-deployment
4 fourth lesson-deployment4 fourth lesson-deployment
4 fourth lesson-deployment
 
Fax With Sangoma Gateway
Fax With Sangoma GatewayFax With Sangoma Gateway
Fax With Sangoma Gateway
 
3 third lesson-reflection
3 third lesson-reflection3 third lesson-reflection
3 third lesson-reflection
 
Introduction To ERP
Introduction To ERPIntroduction To ERP
Introduction To ERP
 
9 networking
9 networking9 networking
9 networking
 
Coursera
CourseraCoursera
Coursera
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
 

Similar to 2 second lesson- attributes

Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
Mahmoud Ouf
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
Rohit Vipin Mathews
 
Computer programming(C++): Structures
Computer programming(C++): StructuresComputer programming(C++): Structures
Computer programming(C++): Structures
JishnuNath7
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
Mahmoud Ouf
 
Organizing Machine Learning Projects - Repository Organization
Organizing Machine Learning Projects - Repository OrganizationOrganizing Machine Learning Projects - Repository Organization
Organizing Machine Learning Projects - Repository Organization
Hao-Wen (Herman) Dong
 
Apache avro data serialization framework
Apache avro   data serialization frameworkApache avro   data serialization framework
Apache avro data serialization framework
veeracynixit
 
C# and Borland StarTeam Connectivity
C# and Borland StarTeam ConnectivityC# and Borland StarTeam Connectivity
C# and Borland StarTeam Connectivity
Shreesha Rao
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
Pranav Sharma
 
Continuous Integration and Drupal
Continuous Integration and DrupalContinuous Integration and Drupal
Continuous Integration and Drupal
Steven Merrill
 
User and group security migration
User and group security migrationUser and group security migration
User and group security migrationAmit Sharma
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
BlackSeraph
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
MeenakshiPatel13
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point developmentPranav Sharma
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
iewsxc
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernatepatinijava
 
CCF #1: Taking the reins of your data with Hiera 5
CCF #1: Taking the reins of your data with Hiera 5CCF #1: Taking the reins of your data with Hiera 5
CCF #1: Taking the reins of your data with Hiera 5
davidmogar
 
User and group security migration
User and group security migrationUser and group security migration
User and group security migrationAmit Sharma
 
Force.com migration utility
Force.com migration utilityForce.com migration utility
Force.com migration utilityAmit Sharma
 

Similar to 2 second lesson- attributes (20)

Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
Computer programming(C++): Structures
Computer programming(C++): StructuresComputer programming(C++): Structures
Computer programming(C++): Structures
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Organizing Machine Learning Projects - Repository Organization
Organizing Machine Learning Projects - Repository OrganizationOrganizing Machine Learning Projects - Repository Organization
Organizing Machine Learning Projects - Repository Organization
 
Apache avro data serialization framework
Apache avro   data serialization frameworkApache avro   data serialization framework
Apache avro data serialization framework
 
C# and Borland StarTeam Connectivity
C# and Borland StarTeam ConnectivityC# and Borland StarTeam Connectivity
C# and Borland StarTeam Connectivity
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
 
Continuous Integration and Drupal
Continuous Integration and DrupalContinuous Integration and Drupal
Continuous Integration and Drupal
 
User and group security migration
User and group security migrationUser and group security migration
User and group security migration
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
 
IO and threads Java
IO and threads JavaIO and threads Java
IO and threads Java
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
 
Topic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.pptTopic12ADTS_GenericDataStructures.ppt
Topic12ADTS_GenericDataStructures.ppt
 
Using SP Metal for faster share point development
Using SP Metal for faster share point developmentUsing SP Metal for faster share point development
Using SP Metal for faster share point development
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
Patni Hibernate
Patni   HibernatePatni   Hibernate
Patni Hibernate
 
CCF #1: Taking the reins of your data with Hiera 5
CCF #1: Taking the reins of your data with Hiera 5CCF #1: Taking the reins of your data with Hiera 5
CCF #1: Taking the reins of your data with Hiera 5
 
User and group security migration
User and group security migrationUser and group security migration
User and group security migration
 
Force.com migration utility
Force.com migration utilityForce.com migration utility
Force.com migration utility
 

More from Mohammad Alyan

Blue ocean strategy arabic
Blue ocean strategy arabicBlue ocean strategy arabic
Blue ocean strategy arabic
Mohammad Alyan
 
Apple case study
Apple case studyApple case study
Apple case study
Mohammad Alyan
 
Introduction to Industry Life Cycles
 Introduction to Industry Life Cycles  Introduction to Industry Life Cycles
Introduction to Industry Life Cycles
Mohammad Alyan
 
Crowd funding
Crowd fundingCrowd funding
Crowd funding
Mohammad Alyan
 
Coursera
CourseraCoursera
Coursera
Mohammad Alyan
 
التفكير- مصنع للإبداع
التفكير- مصنع للإبداعالتفكير- مصنع للإبداع
التفكير- مصنع للإبداع
Mohammad Alyan
 
Cloud computing
Cloud computing Cloud computing
Cloud computing
Mohammad Alyan
 

More from Mohammad Alyan (11)

Blue ocean strategy arabic
Blue ocean strategy arabicBlue ocean strategy arabic
Blue ocean strategy arabic
 
Apple case study
Apple case studyApple case study
Apple case study
 
Introduction to Industry Life Cycles
 Introduction to Industry Life Cycles  Introduction to Industry Life Cycles
Introduction to Industry Life Cycles
 
Crowd funding
Crowd fundingCrowd funding
Crowd funding
 
Coursera
CourseraCoursera
Coursera
 
Course index
Course indexCourse index
Course index
 
التفكير- مصنع للإبداع
التفكير- مصنع للإبداعالتفكير- مصنع للإبداع
التفكير- مصنع للإبداع
 
Cloud computing
Cloud computing Cloud computing
Cloud computing
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 
10 1 otp all
10 1 otp all10 1 otp all
10 1 otp all
 
6 ado.net
6 ado.net6 ado.net
6 ado.net
 

2 second lesson- attributes

  • 1. Introduction to .NET Framework 2- Attributes
  • 2. Outlines مقدمة إلى الصفات .  . Assemblyinfo.cs الملف  البحث عن الصفات .  .NET الصفات المبيتة في  . System.ObsoleteAttribute الصفة  . System.SerializableAttribute الصفة  05 2 تشرين الثاني، 14
  • 3. مقدمة إلى الصفات ؟)Attribute( ما هي الصفة  مبدئي ا سنعرف الصفة على أنها "معلومات إضافية يمكن تطبيقها على كتلة من . ")EXE أو DLL( الشيفرة البرمجية ضمن المجمعة أو Data Member أو Method أو Class يمكن أن تمثل هذه الكتل  Property أخر يستخدم هذه )Class( يمكن الوصول إلى هذه المعلومات من أي صنف  المُجمعة. Assemblyinfo.cs الملف  . Pickling عملية تخزين الصفات ضمن المجمعة تسمى  و والبارمترات التي نمررها هي بارامترات ال Class تصريح الصفة تمثل  Constructor 05 3 تشرين الثاني، 14
  • 4. Assemblyinfo.cs using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Training")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Training")] [assembly: AssemblyCopyright("Copyright © 2010")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] 05 4 تشرين الثاني، 14
  • 5. مقدمة إلى الصفات يمكننا مشاهدة قيم الصفات من خلال خصائص المجمعة أو من خلال الإنعكاس .  يمكننا الآن أن نعرّف الصفة على أنها :  يمكن أن يحوي بيانات إضافية عن المجمعة , تتعلق Class "الصفة : عبارة عن هذه المعلومات بالمجمعة نفسها أو بأي نوع ضمنها“ . [assembly: AssemblyTitle("Training")] هو مدى الصفة ويعني أن الصفة مطبقة على المجمعة نفسها. : Assembly  05 5 تشرين الثاني، 14
  • 6. البحث عن الصفات : using System; using System.Reflection; static void Main(string[] args) { Assembly a = Assembly.LoadFrom(@"D:atom.dll"); object[] attributes = a.GetCustomAttributes(true); foreach(object o in attributes) { Console.WriteLine(o.ToString()); } } 05 6 تشرين الثاني، 14
  • 7. ا 05 7 تشرين الثاني، 14
  • 8. .NET الصفات المبيتة في هي صفات Assemblyinfo.cs إن الصفات الموجودة في الملف  خاصة بالمجمعة بحد ذاتها. الصفات التي سنعرضها فهي تخص الأنواع المعرفة ضمنها وأحيانا  المجمعة بحد ذاتها. . System.ObsoleteAttribute الصفة  . System.SerializableAttribute الصفة  05 8 تشرين الثاني، 14
  • 9. System.ObsoleteAttribute الصفة هذه الصفة تستخدم لوسم تابع بأنه لم يعد مستخدما بعد الآن .  خلال عملية التطوير سيكون بعض المناهج التي لن يكون لها وجود  في الإصدارة النهائية من المكتبة – وبذلك يمكن تحضير مستخدمي مكتبتك لغياب ميزة محددة )تابع مثلا (. 05 9 تشرين الثاني، 14
  • 10. System.ObsoleteAttribute الصفة [Obsolete("Use NewMethod instead")] public void OldMethod() { } public void NewMethod() { } 05 10 تشرين الثاني، 14
  • 11. System.ObsoleteAttribute الصفة عند ترجمة المشروع سنحصل على رسالة تحذير بأن هذا المنهج "مهجور  بدلاُ NewMethod أو سُيهجر قريبا وعليك استخدام "deprecated منه . 05 11 تشرين الثاني، 14
  • 12. System.ObsoleteAttribute الصفة مع الوقت فأن جميع مستخدمين هذا المنهج سيعلمون أن عليهم تجنب  .deprecated استخدام هذا المنهج وحتى عند استدعائه يعطيك أن هذا المنهج 05 12 تشرين الثاني، 14
  • 13. System.ObsoleteAttribute الصفة من شيفرتك OldMethod ومع الوقت يمكنك أن تزيل المنهج  Obsolete تماما دون خوف لذلك يمكنك إضافة بارمتر جديد للصفة كما يلي: [Obsolete("Use NewMethod instead",true)] public void OldMethod() { } 05 13 تشرين الثاني، 14
  • 14. System.ObsoleteAttribute الصفة وعندما يحاول المستخدمون استخدام هذا المنهج فأن  وتتوقف عملية الترجمة . Error المترجم سيصدر خطأ 05 14 تشرين الثاني، 14
  • 15. System.SerializableAttribute الصفة هو الاسم الذي يطلق على ترتيب )Serialization( السّلسَلة  واستعادة الكائنات من الذاكرة أو من الأقراص بصورتها الثنائية . عندما نقوم بسّلسَلة كائن فإن جميع بيانات الكائن تحُفظ ضمن وسط  سيتم إعادة الكائن من )Deserialize( التخزين وعند إزالة السّلسَلة وسط التخزين إلى حالته الأصلية. 05 15 تشرين الثاني، 14
  • 16. System.SerializableAttribute الصفة [Serializable] class Employee { public Employee(int id ,string name) { _id = id; _name = name; } private int _id; private string _name; [NonSerialized] //this Data Member is not Serialized,Such asTransiet in JAVA private string _password; public int Id { get { return _id; } set { _id = value; } } public string Name { get { return _name; } set { _name = value; } } } 05 16 تشرين الثاني، 14
  • 17. System.SerializableAttribute الصفة م ملف نا Employee سن وم ا ن س لسلة ا static void Main(string[] args) { Employee e = new Employee(1, "mohammad"); FileStream fs = null; try { string path= @"D:file"; fs = new FileStream(path, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); // Serialize Object(e) in the file stream(fs) bf.Serialize(fs, e); } catch (Exception Ex) { Console.WriteLine(Ex.Message); } finally { try { fs.Close(); } catch (Exception es) { Console.WriteLine(es.Message); } } } 05 17 تشرين الثاني، 14
  • 18. System.SerializableAttribute الصفة فتتم كما يلي : DeSerailization أما إزالة السلسة نكتب ما يلي : Main ضمن التابع static void Main(string[] args) { Employee e1 = null; try { string path = @"D:file"; fs = new FileStream(path, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); e1 = (Employee)bf.Deserialize(fs); // DownCasting is mandatory Console.WriteLine("Id={0} name={1}",e1.Id,e1.Name); } catch (Exception Ex) { Console.WriteLine(Ex.Message); } finally { try { fs.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } 05 18 تشرين الثاني، 14
  • 19. 05 19 تشرين الثاني، 14