从PowerShell脚本调用DLL的方法
$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);
相关推荐
huha 2020-10-16
lianshaohua 2020-09-23
higheels 2020-08-03
ZoctopusD 2020-08-03
酷云的csdn 2020-08-03
higheels 2020-07-27
liushun 2020-06-28
zhendeshifeng 2020-06-22
Sabrina 2020-06-11
CARBON 2020-06-03
CARBON 2020-06-01
DBATips 2020-05-31
higheels 2020-05-29
applecarelte 2020-04-15
Yyqingmofeige 2020-03-28
yoshubom 2020-03-06
Yyqingmofeige 2020-03-02
SciRui 2020-02-26