Microsoft Official Course: Creating Reusable Types and Assemblies
Microsoft Official Course: Creating Reusable Types and Assemblies
Microsoft Official Course: Creating Reusable Types and Assemblies
Course
Module 12
What Is Reflection?
Loading Assemblies by Using Reflection
Examining Types by Using Reflection
Invoking Members by Using Reflection
• Demonstration: Inspecting Assemblies
What Is Reflection?
• The Assembly.ReflectionOnlyLoad
method
var assemblyPath = "...";
var rawBytes = File.ReadAllBytes(assemblyPath);
var assembly = Assembly.ReflectionOnlyLoad(rawBytes);
• The
Assembly.ReflectionOnlyLoadFrom
var assemblyPath = "...";
method
var assembly =
Assembly.ReflectionOnlyLoadFrom(assemblyPath);
Examining Types by Using Reflection
• Instantiate a type
var type = FourthCoffeeServices.GetHandleErrorType();
...
var constructor = type.GetConstructor(new Type[0]));
...
var initializedObject = constructor.Invoke(new object[0]);
[DataContract(Name = "SalesPersonContract",
IsReference=false)]
public class SalesPerson
{
[Obsolete("This property will be removed in the next release.")]
[DataMember]
public string Name { get; set; }
...
}
Creating and Using Custom Attributes
[DeveloperInfo("holly@fourthcoffee.com", 3)]
public class SalePerson
{
...
}
Processing Attributes by Using Reflection
What Is CodeDOM?
Defining a Type and Type Members
Compiling a CodeDOM Model
• Compiling Source Code into an Assembly
What Is CodeDOM?
dynamicNamespace.Imports.Add(new
CodeNamespaceImport("System"));
textWriter.Close();
stream.Close();
Compiling Source Code into an Assembly
What Is an Assembly?
What Is the GAC?
Signing Assemblies
Versioning Assemblies
Installing an Assembly into the GAC
Demonstration: Signing and Installing an
Assembly into the GAC
• Demonstration: Specifying the Data to
Include in the Grades Report Lab
What Is an Assembly?
• Sign an assembly:
• Create a key file
sn -k FourthCoffeeKeyFile.snk
Examples:
• Install an assembly by using Gacutil.exe:
gacutil –i "<pathToAssembly>"
• View an assembly by using Gacutil.exe:
gacutil –l "<assemblyName>"
Demonstration: Signing and Installing an
Assembly into the GAC
Logon Information
• Virtual Machine: 20483B-SEA-DEV11, MSL-TMG1
• User Name: Student
• Password: Pa$$w0rd
• Review Question(s)