是否有一个清单上的某个地方的共同属性,它是使用的对象 Serializable?

感谢

编辑~因为我问的是我遇到了一个存储过程中的属性ntiers中.

有帮助吗?

解决方案

是的,看起来msdn你请看 在这里,.

编辑:这种链路的唯一的答案吸。这里是工作提取所载的类型(同),有的属性在的名称。

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

其他提示

此外,您可以创建自己的属性。如果您正在搜索其他人的代码,那么在创建自己的代码时很容易感到困惑。

这是一个列表,但它并不完整。有超过200个属性。

我不知道完整的属性列表,但在MSDN中搜索属性可以产生有趣的结果。我倾向于浏览有趣属性类型的命名空间,然后查看它们以查看我可能使用它们的内容。我知道,这不是最有效的方法。

系统的MSDN条目。属性底部有一个列表。

您可能找不到所需的内容,因为您可能正在查看自定义属性。

http://www.code-magazine.com/Article.aspx ?quickid = 0307041

您可以使用Reflector浏览 mscorlib 程序集,并在 System.Attribute 下,展开派生类型节点。它将显示当前在Reflector中加载的所有程序集的所有属性。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top