lecture
in color
contents of assemblies.txt:
C:\MyComServer.dll. Registry entries for binary: all over the place.
Assembly: A versioned, self-describing, binary (*.dll or *.exe) containing some collection of types (classes, interfaces, strcts, etc...) and optionally resources (images, string tables, etc...).
Module: Generic name for a .NET file.
Physical: Description of the underlying binaries.
Logical: View of the versioning and deployment.
System.Drawing.dll.
using System;
namespace CarLibrary
{
// Holds the state of the engine.
public enum EngineState
{
engineAlive,
engineDead
}
// The abstract base class in the hierarchy.
public abstract class Car
{
// Protected state data.
protected string petName;
protected short currSpeed;
protected short maxSpeed;
protected EngineState egnState;
public Car(){egnState = EngineState.engineAlive;}
public Car(string name, short max, short curr)
{
eggState = EngineState.engineAlive;
petName = name; maxSpeed = max; currSpeed = curr;
}
public string PetName
{
get { return petName; }
set { petName = value; }
}
public short CurrSpeed
{
get { return currSpeed; }
set { currSpeed = value; }
}
public short MaxSpeed
{ get { return maxSpeed; } }
public EngineState EngineState
{ get { return egnState; } }
public abstract void TurboBoost();
}
}
using System.Windows.Forms; for use when we override the abstract method.
namespace CarLibrary {
// The SportsCar
public class SportsCar : Car
{
public SportsCar() { }
public SportsCar(string name, short max, short curr)
: base (name, max, curr) { }
// TurboBoost impl.
public override void TurboBoost()
{
MessageBox.Show("Ramming speed!", "Faster is better...");
}
}
// The MiniVan
public class MiniVan : Car
{
public MiniVan() { }
public MiniVan(string name, short max, short curr)
: base (name, max, curr) { }
// TurboBoost impl.
public override void TurboBoost()
{
// Minivans have poor turbo capabilities!
egnState = EngineState.engineDead;
MessageBox.Show("Time to call AAA", "Your car is dead");
}
}
System.Windows.Forms.dll, this is an Assembly.
using System;
// So we can implement the CarLibrary types
using CarLibrary;
namespace CSharpCarClient
{
public class CarClient
{
public static int Main(string[] args)
{
// Make a sports car
SportsCar viper = new SportsCar("Viper", 240, 40);
viper.TurboBoost();
// Make a minivan.
MiniVan mv = new MiniVan();
mv.TurboBoost();
return 0;
}
}
}
using, we use each language's namespace feature to specify that we are using CarLibrary.
Imports CarLibrary
Public Class PerformanceCar
Inherits CarLibrary.SportsCar
' Implementation of the abstract Car method
public Overrides Sub TurboBoost()
MessageBox.Show("Blistering speed", "VB PerformanceCar says")
End Sub
End Class
#pragma once
#include "stdafx.h"
// If we weren't using Visual Studio.NET we would have use the following two lines.
// They are functionally equivalent to the 'Add Reference' dialog
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using "\\netapp01\asidrane\Visual Studio Projects\VbCarClient\bin\VbCarClient.exe"
#using "\\netapp01\asidrane\Visual Studio Projects\CarLibrary\obj\Debug\CarLibrary.dll"
using namespace VbCarClient;
using namespace System;
// __gc (garbage collected) marks this class as managed by the CLR
__gc class JamesBondCar : public PerformanceCar
{
public:
JamesBondCar(void){}
~JamesBondCar(void){}
virtual void TurboBoost()
{
Console::WriteLine("Driving, flying and drilling...");
}
};
// This is the entry point for this application.
#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
JamesBondCar* jbc = new JamesBondCar();
jbc->PetName = S"Jello";
jbc->TurboBoost();
Console::Write("Car is called: ");
Console::WriteLine(jbc->PetName);
Console::WriteLine(jbc->GetType()->BaseType->ToString());
return 0;
}
using System;
namespace AirVehicles;
{
public class UFO
{
public void AbductHuman()
{
Console.WriteLine("Resistance if gutile");
}
}
}
using System;
namespace AirVehicles
{
public class Heliopter
{
public voic TakeOff()
{
Console.WriteLine("Helicopter taking off!");
}
}
}
csc.exe /t:module ufo.cs: producing ufo.netmodule.
CSC.exe /t:library /addmodule:ufo.netmodule /out airvehicles.dll helicopter.cs
using AirVehicles at the top of out client code.
CarLibrary.dll is a private assembly used by CSharpCarClient.exe and VbCarClient.exe.
CSharpCarClient.exe
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="MyLibraries"/>
</assemblyBinding>
</runtime>
</configuration>
<probing privatePath="MyLibraries"/> tells the compiler where to look, relative to root, fo rthe assemblies.
<probing privatePath="MyLibraries;MyOtherLibraries"/>
System.Windows.Forms.dll
sn.exe and have the *.snk extension.
public class VWMiniVan
{
private bool isBustedbyTheFuzz = false;
public VWMiniVan()
{
Message.Box.Show("Using version 1.0.0.0!", "Shared Car");
}
public void Play60sTunes()
{
Messagebox.Show("What a looong, strange trip it's been...");
}
public bool Busted
{
get { return isBustedByTheFuzz; }
set { isBustedByTheFuzz = value; }
}
}
sn -k myKey.snk to write our pair key to myKey.snk
assembly: AssemblyKeyFile(@"C:\MyKey\myKey.snk") to AssemblyInfo.cs, which is included in every new Visual Studio project.
assembly: AssemblyVersion("1.0.*") to the AssemblyInfo.cs file so that our assembly becomes versioned properly.
public class SharedAsmClient
{
public static int Main(string[] args)
{
VWMiniVan v = new VWMiniVan();
v.Play60sTunes();
return 0;
}
}
lecture
in color