Q
.NET属性列表
11
A
回答
11
是的,看看msdn你有没有覆盖请看here。
编辑:此链接只回答吸。这是所有可加载类型(gac)的名称中都有Attribute的工作提取器。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var process = new Process();
//your path may vary
process.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\gacutil.exe";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = "/l";
process.Start();
var consoleOutput = process.StandardOutput;
var assemblyList = new List<string>();
var startAdding = false;
while (consoleOutput.EndOfStream == false)
{
var line = consoleOutput.ReadLine();
if (line.IndexOf("The Global Assembly Cache contains the following assemblies", StringComparison.OrdinalIgnoreCase) >= 0)
{
startAdding = true;
continue;
}
if (startAdding == false)
{
continue;
}
//add any other filter conditions (framework version, etc)
if (line.IndexOf("System.", StringComparison.OrdinalIgnoreCase) < 0)
{
continue;
}
assemblyList.Add(line.Trim());
}
var collectedRecords = new List<string>();
var failedToLoad = new List<string>();
Console.WriteLine($"Found {assemblyList.Count} assemblies");
var currentItem = 1;
foreach (var gacAssemblyInfo in assemblyList)
{
Console.SetCursorPosition(0, 2);
Console.WriteLine($"On {currentItem} of {assemblyList.Count} ");
Console.SetCursorPosition(0, 3);
Console.WriteLine($"Loading {gacAssemblyInfo}");
currentItem++;
try
{
var asm = Assembly.Load(gacAssemblyInfo);
foreach (Type t in asm.GetTypes())
{
if (t.Name.EndsWith("Attribute", StringComparison.OrdinalIgnoreCase))
{
collectedRecords.Add($"{t.FullName} - {t.Assembly.FullName}");
}
}
}
catch (Exception ex)
{
failedToLoad.Add($"FAILED to load {gacAssemblyInfo} - {ex}");
Console.SetCursorPosition(1, 9);
Console.WriteLine($"Failure to load count: {failedToLoad.Count}");
Console.SetCursorPosition(4, 10);
Console.WriteLine($"Last Fail: {gacAssemblyInfo}");
}
}
var fileBase = System.IO.Path.GetRandomFileName();
var goodFile = $"{fileBase}_good.txt";
var failFile = $"{fileBase}_failedToLoad.txt";
System.IO.File.WriteAllLines(goodFile, collectedRecords);
System.IO.File.WriteAllLines(failFile, failedToLoad);
Console.SetCursorPosition(0, 15);
Console.WriteLine($"Matching types: {goodFile}");
Console.WriteLine($"Failures: {failFile}");
Console.WriteLine("Press ENTER to exit");
Console.ReadLine();
}
}
}
2
Here is a list,但它不完整。有超过200个属性。
2
我不知道属性的完整列表,但在MSDN中搜索属性可以产生有趣的结果。我倾向于浏览有趣的属性类型的名称空间,然后去查看它们,看看我可以使用它们。我知道不是最有效的方法。
System.Attribute的MSDN条目在底部有一个列表。
1
您可能无法找到您要查找的内容,因为您可能正在查看自定义属性。
3
此外,还可以创建自己的属性。如果您正在通过其他人的代码进行搜索,那么创建自己的代码时很容易感到困惑。
1
您可以使用反射来浏览mscorlib
组装,并在System.Attribute
,扩大派生类型节点。它将显示当前在Reflector中加载的所有程序集的所有属性。
相关问题
- 1. 可序列化属性.NET
- 2. .net和属性属性
- 3. 具有关系表属性的下拉列表[MVC .NET]
- 4. PropertyGrid属性列表
- 5. 列表/ Properties(属性)
- 6. 在列表属性
- 7. Maven属性列表
- 8. 属性在.NET
- 9. HttpBrowserCapabilities.Crawler属性.NET
- 10. 属性文件中的属性列表
- 11. 如何获取属性属性列表?
- 12. .NET XML序列化的可选属性
- 13. Protobuf-net - 仅序列化几个属性
- 14. .net方法属性
- 15. .NET WinForms锚属性
- 16. 将类属性映射到表中的通用列.NET
- 17. .NET:获取属性名称属性
- 18. Enumerable或列表属性
- 19. SyntaxError:missing}属性列表后jquery
- 20. 使列表(T)属性
- 21. 列表视图属性
- 22. 访问属性列表
- 23. C#:通用列表属性
- 24. 清单属性列表
- 25. 嵌套属性列表框
- 26. 添加属性到列表?
- 27. Java Swing UI属性列表?
- 28. C#属性的类列表
- 29. eglCreateContext中的属性列表
- 30. 检查属性列表
我所看到的只是“用在像对象中的属性?” - 该帖子被剥夺了其可序列化属性。我虽然他问的是可空数(?和??) – StingyJack 2008-10-07 17:28:10
删除了评论和更新的答案,一旦误解被清除,准确的信息 – 2008-10-07 17:28:32