Информация об изменениях

Сообщение Re: Бесполезная рефлексия от 31.10.2023 14:36

Изменено 31.10.2023 16:06 Shmj

Re: Бесполезная рефлексия
Здравствуйте, Разраб, Вы писали:

Р>Как с помощью рефлексии получить названия аргументов и xml документацию?


Вот как GPT ответил на ваш вопрос: https://chat.openai.com/share/2a7d2fc4-e521-46d0-8893-13fdfee2bc26

Сам код:

using System;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

class Program
{
    static void Main()
    {
        // 1. Получаем информацию о методе
        var method = typeof(System.Diagnostics.ProcessStartInfo).GetConstructor(new[] { typeof(string), typeof(string) });
        if (method != null)
        {
            Console.WriteLine($"Method: {method.Name}");
            
            var parameters = method.GetParameters();
            foreach (var param in parameters)
            {
                Console.WriteLine($"Parameter: {param.Name} of type {param.ParameterType}");
            }
        }

        // 2. Получаем XML-документацию
        var assembly = typeof(System.Diagnostics.ProcessStartInfo).Assembly;
        var xmlFile = $"{new Uri(assembly.CodeBase).AbsolutePath}.xml"; // Путь к XML файлу

        var xdoc = XDocument.Load(xmlFile);
        var xmlMember = xdoc.Descendants("member")
            .FirstOrDefault(m => m.Attribute("name").Value == $"M:{method.DeclaringType.FullName}.ctor(System.String,System.String)");

        if (xmlMember != null)
        {
            Console.WriteLine($"Documentation: {xmlMember.Value}");
        }
    }
}
Re: Бесполезная рефлексия
Здравствуйте, Разраб, Вы писали:

Р>Как с помощью рефлексии получить названия аргументов и xml документацию?


Вот как GPT ответил на ваш вопрос: https://chat.openai.com/share/2a7d2fc4-e521-46d0-8893-13fdfee2bc26

Сам код:

using System;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

class Program
{
    static void Main()
    {
        // 1. Получаем информацию о методе
        var method = typeof(System.Diagnostics.ProcessStartInfo).GetConstructor(new[] { typeof(string), typeof(string) });
        if (method != null)
        {
            Console.WriteLine($"Method: {method.Name}");
            
            var parameters = method.GetParameters();
            foreach (var param in parameters)
            {
                Console.WriteLine($"Parameter: {param.Name} of type {param.ParameterType}");
            }
        }

        // 2. Получаем XML-документацию
        var assembly = typeof(System.Diagnostics.ProcessStartInfo).Assembly;
        var xmlFile = $"{new Uri(assembly.CodeBase).AbsolutePath}.xml"; // Путь к XML файлу

        var xdoc = XDocument.Load(xmlFile);
        var xmlMember = xdoc.Descendants("member")
            .FirstOrDefault(m => m.Attribute("name").Value == $"M:{method.DeclaringType.FullName}.ctor(System.String,System.String)");

        if (xmlMember != null)
        {
            Console.WriteLine($"Documentation: {xmlMember.Value}");
        }
    }
}


Просьба высказать свое мнение — GPT понял ваш вопрос или просто выдал готовое решение из базы по ключевым словам?