---
title: "CSharp代码工具集"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/csharp-code-toolkit/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/02-编程语言与运行时/.NET与CSharp/CSharp代码工具集.md"
content_hash: 417d6d321d179bb282659665a87c97baf102fe6b8de13c1f75ddb871ec9a4c07
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# CSharp代码工具集

﻿# CSharp代码工具集

> 创建时间：2024/1/13 19:02

* 获取函数的调用栈信息
  * 判断操作系统类型
  * 枚举类型扩展方法
  * 监听目录下文件的改动
  * 实时获取手机电流、电压、计算功率发热

## 获取函数的调用栈信息

1.(new StackTrace()).GetFrame(1) // 0为本身的方法；1为调用方法
2.(new StackTrace()).GetFrame(1).GetMethod().Name; // 方法名
3.(new StackTrace()).GetFrame(1).GetMethod().ReflectedType.Name; // 类名

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

## 判断操作系统类型

操作系统| PlatformID| 主版本号| 副版本号
---|---|---|---
Windows95| 1| 4| 0
Windows98| 1| 4| 10
WindowsMe| 1| 4| 90
WindowsNT3.5| 2| 3| 0
WindowsNT4.0| 2| 4| 0
Windows2000| 2| 5| 0
WindowsXP| 2| 5| 1
Windows2003| 2| 5| 2
WindowsVista| 2| 6| 0
Windows7| 2| 6| 1

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

System.PlatformID枚举值及其含义
Win32S 操作系统为 Win32s（Win32 子集）类型。
Win32s 是运行于 Windows 16 位版本上的层，它提供对 32 位应用程序的访问。
Win32Windows 操作系统为 Windows 95 或较新的版本。
Win32NT 操作系统为 Windows NT 或较新的版本。
WinCE 操作系统为 Windows CE。
Unix 操作系统为 Unix。
Xbox 开发平台为 Xbox 360。

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

## 枚举类型扩展方法

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

## 监听目录下文件的改动

Ref: https://blog.csdn.net/xingxiupaioxue/article/details/82901403

```csharp
string str1 = &quot;test&quot;;
string str2 = &quot;test&quot;;

```

Ref: https://blog.csdn.net/wojiaoxiaol/article/details/4084997

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

在Unity中实现

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```

## 实时获取手机电流、电压、计算功率发热

https://www.xuanyusong.com/archives/4753

```csharp
string a = &quot;test&quot;;
string tmp = &quot;est&quot;;
string b = &quot;t&quot; + tmp;
Console.WriteLine(string .ReferenceEquals(str1, str2));

```
