gpt4 book ai didi

.NET 属性列表

转载 作者:行者123 更新时间:2023-12-04 00:01:48 25 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

4年前关闭。




Improve this question




在对象中使用的常见属性的某处是否有列表 Serializable ?

谢谢

编辑~我问的原因是我在 ntiers ORMS 中遇到了一个 StoredProcedure 属性。

最佳答案

是的,看msdn有没有请看here .

编辑:这个链接只回答很烂。这是名称中包含 Attribute 的所有可加载类型 (gac) 的有效提取器。

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();
}
}
}

关于.NET 属性列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/179488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com