Reflection Code Review 8/16/12
Where is this info?METADATA!
Type ReflectionIn the .NET universe, reflection is the process of runtime typediscoverySystem.Reflection namespace    Asse...
Reflect the type infoObtain a type reference using System.Type.GetType()   Type t = Type.GetType (typeName);Reflecting on ...
Dynamic LoadingDynamic load  loading external assemblies on  demand  Can use Assembly.Load() or  Assembly.LoadFrom()
Late binding  Late binding is a technique in which you are  able to create an instance of a given type and  invoke its mem...
Attributed programmingUsing attributes, programmers canembed additional metadata into anassembly .NET attributes are class...
Attribute Consumers.Net Compiler.Net base libraries (such as Serialize())Custom Code
Predefined attributes[CLSCompliant][DllImport][Obsolete][Serializable][NonSerialized][WebMethod]
Building Custom Attributespublic sealed class VehicleDescriptionAttribute: System.Attribute{      private string msgData; ...
Upcoming SlideShare
Loading in …5
×

Reflection

1,829 views
1,797 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,829
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Reflection

  1. 1. Reflection Code Review 8/16/12
  2. 2. Where is this info?METADATA!
  3. 3. Type ReflectionIn the .NET universe, reflection is the process of runtime typediscoverySystem.Reflection namespace Assembly, AssemblyName, EventInfo, FieldInfo, MethodInfo, ParameterInfo and PropertyInfoSystem.Type class GetConstructors(), GetEvents(), GetFields(), GetInterfaces(), GetMembers(), GetMethods(), GetProperties(), InvokeMember()
  4. 4. Reflect the type infoObtain a type reference using System.Type.GetType() Type t = Type.GetType (typeName);Reflecting on methods MethodInfo[] mi = t.GetMethods();Reflecting on Fields and properties FieldInfo[] fi = t.GetFields(); PropertyInfo[] pi = t.GetProperties();
  5. 5. Dynamic LoadingDynamic load loading external assemblies on demand Can use Assembly.Load() or Assembly.LoadFrom()
  6. 6. Late binding Late binding is a technique in which you are able to create an instance of a given type and invoke its members at runtime without having compile-time knowledge of its existenceAssembly a = Assembly.Load(“CarLibrary”);Type miniVan = a.GetType (“CarLibrary.MiniVan”); object obj = Activator.CreateInstance(miniVan); MethodInfo mi = miniVan.GetMethod(“TurboBoost”); mi.Invoke(obj, null);
  7. 7. Attributed programmingUsing attributes, programmers canembed additional metadata into anassembly .NET attributes are class types thatextend the abstract System.Attributebase class
  8. 8. Attribute Consumers.Net Compiler.Net base libraries (such as Serialize())Custom Code
  9. 9. Predefined attributes[CLSCompliant][DllImport][Obsolete][Serializable][NonSerialized][WebMethod]
  10. 10. Building Custom Attributespublic sealed class VehicleDescriptionAttribute: System.Attribute{ private string msgData; public VehicleDescriptionAttribute (string description) { msgData = description;}}

×