SciRui 2019-12-26
$PSVersionTable.PSVersion
Major Minor Build Revision ----- ----- ----- -------- 5 1 18362 145
创建一个Class,这个类包含了构造方法,静态方法和普通方法
using System;
namespace Cosmos.StudentForFrameWork
{
public class Students
{
public string Name { get; set; }
public int Age { get; private set; }
public Students(string name, int age)
{
Name = name;
Age = age;
}
public static string StaticStudent(string name)
{
return "Hello:" + name;
}
public String GetInfo(string message)
{
return message + Name + Age;
}
public static string GetName
{
get { return "Do u want get my Name!"; }
}
}
}把他编译成dll.
导入你的dll所在的地方
调用 dll 的构造方法 使用 ::new()调用dll 的静态方法使用::MethodName()
Import-Module "$PSScriptRoot\Cosmos.StudentForFrameWork.dll"; $Stuent=[Cosmos.StudentForFrameWork.Students]::new($name,$age); $StudentInfo=$Stuent.GetInfo();$StaticStu=[Cosmos.StudentForFrameWork.Students]::StaticStudent($name);