23.5.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 77 行
TXT
77 行
Listing 23.5 Programmatically Creating Assemblies
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
namespace _9_DynamicAssembly
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string input;
AnimalBuilder builder = new AnimalBuilder();
Console.WriteLine( “Welcome to the .NET Animal Builder!” );
Console.WriteLine( “This program lets you build an animal and “ +
“ save it as an assembly” );
input = GetInput( “What type of animal do you want?” );
builder.AnimalType = input;
input = GetInput( “What sound does the animal make?” );
builder.AnimalSound = input;
input = GetInput( “How many sounds will it make before it gets” +
“ hoarse (no pun intended)?” );
builder.SoundsBeforeHoarse = Int32.Parse(input);
input = GetInput( “Where would you like to save this animal?” );
builder.BuildAndSaveAnimal( input );
}
static string GetInput( string question )
{
Console.Write( question + “: “ );
return Console.ReadLine();
}
public class AnimalBuilder
{
private string animalType;
private string animalSound;
private int sounds;
public string AnimalType
{
get
{
return animalType;
}
set
{
animalType = value;
}
}
public string AnimalSound
{
get
{
return animalSound;
}
set
{
animalSound = value;
}
}
public int SoundsBeforeHoarse
{
get
{
return sounds;
}
set
{
sounds = value;
}
}
public void BuildAndSaveAnimal( string assemblyPath )
{
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?