[源码下载]

背水一战 Windows 10 (122) - 其它: 通过 Windows.System.Profile 命名空间下的类获取信息, 查找指定类或接口的所在程序集的所有子类和子接口

作者:webabcd

介绍
背水一战 Windows 10 之 其它

  • 通过 Windows.System.Profile 命名空间下的类获取信息
  • 查找指定类或接口的所在程序集的所有子类和子接口

示例
1、演示如何通过 Windows.System.Profile 命名空间下的类获取信息
Information/ProfileInfo.xaml

<Page
x:Class="Windows10.Information.ProfileInfo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Information"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <TextBlock Name="lblMsg" TextWrapping="Wrap" Margin="0 10 10 10" /> </StackPanel>
</Grid>
</Page>

Information/ProfileInfo.xaml.cs

/*
* 演示如何通过 Windows.System.Profile 命名空间下的类获取信息
*
* 主要可获取到设备类型,系统版本号等
*/ using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.System.Profile; namespace Windows10.Information
{
public sealed partial class ProfileInfo : Page
{
public ProfileInfo()
{
this.InitializeComponent(); this.Loaded += ProfileInfo_Loaded;
} private void ProfileInfo_Loaded(object sender, RoutedEventArgs e)
{
// 获取设备类型,目前已知的返回字符串有:Windows.Mobile, Windows.Desktop, Windows.Xbox
lblMsg.Text = string.Format("DeviceFamily: {0}", AnalyticsInfo.VersionInfo.DeviceFamily);
lblMsg.Text += Environment.NewLine; // 获取系统版本号,一个长整型值
lblMsg.Text += string.Format("DeviceFamilyVersion: {0}", AnalyticsInfo.VersionInfo.DeviceFamilyVersion);
lblMsg.Text += Environment.NewLine; // 将长整型的系统版本号转换为 major.minor.revision.build 的方式
string versionString = AnalyticsInfo.VersionInfo.DeviceFamilyVersion;
ulong version = ulong.Parse(versionString);
ulong v1 = (version & 0xFFFF000000000000L) >> ;
ulong v2 = (version & 0x0000FFFF00000000L) >> ;
ulong v3 = (version & 0x00000000FFFF0000L) >> ;
ulong v4 = (version & 0x000000000000FFFFL);
string v = $"{v1}.{v2}.{v3}.{v4}"; lblMsg.Text += string.Format("DeviceFamilyVersion(major.minor.revision.build): {0}", v);
lblMsg.Text += Environment.NewLine; // 获取当前的“向 Microsoft 发送你的设备数据”的收集等级。在“设置”->“隐私”->“反馈和诊断”中配置(Security, Basic, Enhanced, Full)
lblMsg.Text += string.Format("PlatformDiagnosticsAndUsageDataSettings.CollectionLevel: {0}", PlatformDiagnosticsAndUsageDataSettings.CollectionLevel);
lblMsg.Text += Environment.NewLine; // 检查当前配置是否允许指定级别的信息收集
lblMsg.Text += string.Format("PlatformDataCollectionLevel.Full: {0}", PlatformDiagnosticsAndUsageDataSettings.CanCollectDiagnostics(PlatformDataCollectionLevel.Full));
lblMsg.Text += Environment.NewLine; // 在“设置”->“隐私”->“反馈和诊断”中配置的“向 Microsoft 发送你的设备数据”发生变化时触发的事件
PlatformDiagnosticsAndUsageDataSettings.CollectionLevelChanged += PlatformDiagnosticsAndUsageDataSettings_CollectionLevelChanged;
} private async void PlatformDiagnosticsAndUsageDataSettings_CollectionLevelChanged(object sender, object e)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
lblMsg.Text += string.Format("PlatformDiagnosticsAndUsageDataSettings.CollectionLevel: {0}", PlatformDiagnosticsAndUsageDataSettings.CollectionLevel);
lblMsg.Text += Environment.NewLine; lblMsg.Text += string.Format("PlatformDataCollectionLevel.Full: {0}", PlatformDiagnosticsAndUsageDataSettings.CanCollectDiagnostics(PlatformDataCollectionLevel.Full));
lblMsg.Text += Environment.NewLine;
});
}
}
}

2、用于查找指定类或接口的所在程序集的所有子类和子接口
Tools/FindSubClass.xaml

<Page
x:Class="Windows10.Tools.FindSubClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Tools"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<ScrollViewer Margin="10 0 10 10">
<StackPanel Name="root" Margin="5"> <Button Name="btnFind" Content="查找指定类或接口的所在程序集的所有子类或子接口" Margin="1 5 1 20" Click="btnFind_Click" /> </StackPanel>
</ScrollViewer>
</Grid>
</Page>

Tools/FindSubClass.xaml.cs

/*
* 用于查找指定类或接口的所在程序集的所有子类和子接口
*/ using System;
using System.Reflection;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Linq; namespace Windows10.Tools
{
public sealed partial class FindSubClass : Page
{
public FindSubClass()
{
this.InitializeComponent();
} private void btnFind_Click(object sender, RoutedEventArgs e)
{
// 这样不行
// Type type = Type.GetType("Windows.UI.Xaml.Controls.Button"); Type type = typeof(Windows.UI.Xaml.UIElement); List<Type> subTypes = GetSubTypes(type);
AddWrapGrid(subTypes);
} private void AddWrapGrid(List<Type> subTypes)
{
VariableSizedWrapGrid wrapGrid = CreateWrapGrid();
root.Children.Add(wrapGrid); foreach (Type type in subTypes)
{
Button button = CreateButton(type);
wrapGrid.Children.Add(button);
}
} private void Button_Click(object sender, RoutedEventArgs e)
{
FrameworkElement button = sender as FrameworkElement;
Type type = button.Tag as Type; int index = ;
// 删除被选中按钮的所属容器,以及此容器之后的所有控件
if (button.Parent.GetType() == typeof(VariableSizedWrapGrid))
index = root.Children.IndexOf(button.Parent as UIElement);
// 删除被选中按钮,以及此按钮之后的所有控件
else
index = root.Children.IndexOf(button);
while (root.Children.Count > index)
{
root.Children.RemoveAt(root.Children.Count - );
} // 将被选中按钮添加到根容器
Button buttonNew = CreateButton(type);
root.Children.Add(buttonNew);
root.Children.Add(new Grid() { Height = }); // 将被选中类的所有子类添加到根容器
List<Type> subTypes = GetSubTypes(type);
AddWrapGrid(subTypes);
} private VariableSizedWrapGrid CreateWrapGrid()
{
VariableSizedWrapGrid wrapGrid = new VariableSizedWrapGrid();
wrapGrid.Orientation = Orientation.Vertical;
wrapGrid.ItemWidth = ;
wrapGrid.HorizontalAlignment = HorizontalAlignment.Stretch; return wrapGrid;
} private Button CreateButton(Type type)
{
Button button = new Button();
button.Content = type.ToString();
button.Margin = new Thickness();
button.Tag = type;
button.Click += Button_Click; return button;
} // 获取儿子类,孙子及以下级别不会返回
private List<Type> GetSubTypes(Type type)
{
List<Type> subTypes = new List<Type>(); Type[] assemblyTypes = type.GetTypeInfo().Assembly.GetTypes(); foreach (Type t in assemblyTypes)
{
if (type.GetTypeInfo().IsInterface)
{
if (t.GetInterfaces().Contains(type))
{
subTypes.Add(t);
}
}
else
{
if (t.GetTypeInfo().BaseType == type)
{
subTypes.Add(t);
}
}
} subTypes = subTypes.OrderBy(p => p.FullName).ToList(); return subTypes;
}
}
}

OK
[源码下载]

背水一战 Windows 10 (122) - 其它: 通过 Windows.System.Profile 命名空间下的类获取信息, 查找指定类或接口的所在程序集的所有子类和子接口的更多相关文章

  1. 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒

    [源码下载] 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒 作者:webabcd ...

  2. Windows 10 IoT Serials 3 - Windows 10 IoT Core Ardunio Wiring Mode

    Maker社区和智能硬件的朋友一定知道Arduino,很多3D打印机都是用它做的.为了迎合这一大块市场,微软在基于Intel Galileo的Windows 8.1 IoT中就是使用这种基于Ardui ...

  3. Windows 10 IoT Serials 2 - Windows 10 IoT RTM 升级教程

    7月29日,微软推出了Windows 10 for PC的正式版,其版本号是Build 10240.近两天官方说已经有4700万的下载安装量,同时这个数字还在不断攀升.另外,除了Windows 10 ...

  4. 【Windows 10 IoT - 3】Windows 10 RTM安装及新特性(树莓派 Pi2)

    在<[Window 10 IoT - 1]Window 10系统安装(树莓派 Pi2)>中,我们介绍了Windows 10 IoT预览版的安装,正式版Windows 10 IOT(OS版本 ...

  5. Windows 10 安装 Docker for Windows

    Docker for Windows是Docker社区版(CE)应用程序. Docker for Windows安装包包括在Windows系统上运行Docker所需的一切. 本主题介绍了预安装注意事项 ...

  6. windows 10开启bash on windows,配置sshd,部署hadoop

    1.安装Bash on Windows 这个参考官网步骤,很容易安装,https://msdn.microsoft.com/en-us/commandline/wsl/install_guide 安装 ...

  7. 在Windows 10 64-bit上安装Windows SDK 7.1和.NET4

    目的: 成功在window10上安装window sdk7.1 和 .NET Framework 4 需求: support some older software written in Visual ...

  8. Windows 10系统永久关闭Windows Defender Antivirus防病毒程序方法

    Win + R 键运行 gpedit.msc 找到 计算机配置 -> 管理模板 -> Windows 组件 -> Windows Defender 防病毒程序 右边双击 “关闭Win ...

  9. System.IO命名空间下常用的类

    System.IO System.IO.Directory 目录 System.IO.Path 文件路径(包含目录和文件名) System.IO.FileInfo 提供创建.复制.删除.移动和打开文件 ...

随机推荐

  1. sqlserver2017 SSAS配置远程访问不成功的问题

    sqlserver2017 SSAS通过IIS配置远程访问一直访问不成功的解决办法: 出现这个问题的原因从微软给出的更新包中说的就是: 从 SQL Server 2017 开始,Analysis Se ...

  2. 开发模型之V模型

    1.模型目的: V模型的目的在于改进软件开发的效率和效果. 2.常见理论性描述:  V模型从整体上看起来,就是一个V字型的结构,由左右两边组成. 左边的下划线分别代表了需求分析.概要设计.详细设计.编 ...

  3. Python爬虫——Request模块

    # 使用 Requests 发送网络请求# 1.导入 Requests 模块import requests# 2.尝试获取某个网页 # HTTP 请求类型r = requests.get('https ...

  4. FastDFS api介绍

    1. 命令行api介绍 FastDFS提供了可用于运维测试的命令行api,下面进行介绍: 1.1 fastdfs服务管理 tracker进程服务管理脚本 /etc/init.d/fdfs_tracke ...

  5. leetcode26: 删除排序数组中的重复项

    给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成. 示例 1 ...

  6. java8 先groupingBy 后map

    Map<Integer,List<String>> mapBanJI_UserNameList=list.stream().collect(Collectors.groupin ...

  7. Vmware Workstation实现CentOS6.10_x64 下ORACLE RAC 11.2.0.4的搭建

    想必大家在学习ORACLE 11g时,都想搭建一个RAC的实验环境.在搭建RAC实验环境时,会碰到诸如IP怎么规划.虚拟机环境下怎么共享磁盘.ASM磁盘创建,以及安装过程中会遇到这样那样的问题.搭建一 ...

  8. win10在Pycharm中安装scrapy

    查看官网说明 发现推荐是安装Anaconda 或 Miniconda,这东西有点大而全,感觉目前用不上.所以没这样做. 直接安装scrapy 如果直接装会报错的,参考文章就可以解决. 这里记一下组件下 ...

  9. 第四周助教工作总结——NWNU李泓毅

    1.    助教博客链接: https://www.cnblogs.com/NWNU-LHY/ 2.    作业要求链接: www.cnblogs.com/nwnu-daizh/p/10487329. ...

  10. 通过TABULATE过程制作汇总报表

    通过TABULATE过程制作汇总报表 制作基本汇总报表 TABULATE过程的基本语法如下: PROC TABULATE DATA=数据集 <选项>; CLASS 变量1 <变量2变 ...