帮助使用System.Reflection [英] Help with using System.Reflection

查看:94
本文介绍了帮助使用System.Reflection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我是C#的初学者,并且已经在www.learningvisualstudio.net上研究了Bob tabor的视频。但现在我找到了一本关于Patrice Pelland的visual c#2005 express版的书。但是有一个任务就是制作一个web浏览器。

他给我们一些关于大会的代码。

这是代码



Hello ,

I am a beginner in C# and have studied the video''s from Bob tabor on www.learningvisualstudio.net. But now I found a book about visual c# 2005 express edition from Patrice Pelland. But there is a task about to make a webbrowser.
He give us some code about the Assembly.
Here is the code

public string AssemblyTitle
    {
    get
        {
        // Get all Title attributes on this assembly
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
        // If there is at least one Title attribute
        if (attributes.Length > 0)
            {
            // Select the first one
            AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
            // If it is not an empty string, return it
            if (titleAttribute.Title != "")
                return titleAttribute.Title;
            }
        // If there was no Title attribute, or if the Title attribute was the empty string, return the .exe name
        return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
        }
    }
public string AssemblyVersion
    {
    get
        {
        return Assembly.GetExecutingAssembly().GetName().Version.ToString();
        }
    }
public string AssemblyDescription
    {
    get
        {
        // Get all Description attributes on this assembly
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
        // If there aren't any Description attributes, return an empty string
        if (attributes.Length == 0)
            return "";
        // If there is a Description attribute, return its value
        return ((AssemblyDescriptionAttribute)attributes[0]).Description;
        }
    }
public string AssemblyProduct
    {
    get
        {
        // Get all Product attributes on this assembly
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
        // If there aren't any Product attributes, return an empty string
        if (attributes.Length == 0)
            return "";
        // If there is a Product attribute, return its value
        return ((AssemblyProductAttribute)attributes[0]).Product;
        }
    }
public string AssemblyCopyright
    {
    get
        {
        // Get all Copyright attributes on this assembly
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
        // If there aren't any Copyright attributes, return an empty string
        if (attributes.Length == 0)
            return "";
        // If there is a Copyright attribute, return its value
        return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
        }
    }
public string AssemblyCompany
    {
    get
        {
        // Get all Company attributes on this assembly
        object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
        // If there aren't any Company attributes, return an empty string
        if (attributes.Length == 0)
            return "";
        // If there is a Company attribute, return its value
        return ((AssemblyCompanyAttribute)attributes[0]).Company;
        }
    }









他没有给我们解释为什么何时使用这个代码。有人可以提供如何搜索信息的建议。我在谷歌搜索,但它是如此多的信息,我在迷路。你是怎么学习c#代码的?我对基本的东西都了如指掌。类(OOP),方法等。我不是那些想要复制和粘贴代码的人,因为我想学点东西。



问候,



Samir



代码重新格式化以提供缩进 - OriginalGriff [/ edit]





He didn''t give us a explanation why en when to use this code. Can someone give advice how to search for information. I was searching on google but it is so many information that I am in a lost. How did you guys learn the c# code. I know everything about the basic stuff. Classes (OOP) , methods and etc.. I am not someone that want to copy and paste code, because I want to learn something.

regards,

Samir

[edit]Code reformatted to give indentation - OriginalGriff[/edit]

推荐答案

如果你知道基本内容的所有内容。类(OOP),方法等等。然后你应该认识到这个东西:它只是没有制定者的字符串属性。



那么你把它放在哪里代码?在你的班上。

你什么时候使用代码?当你想从程序集中读取该属性时。

为什么要使用代码?请参阅何时。



所有代码都是您可以在项目的属性页面中的应用程序选项卡装配信息下设置的返回信息。 按钮。
If you "know everything about the basic stuff. Classes (OOP) , methods and etc.." then you should recognise this stuff: it''s all just string properties with no setter.

So where do you put the code? In your class.
When do you use the code? When you want to read that attribute from your assembly.
Why to use the code? See "when".

All the code does is return information that you can set in the Properties page of your project, under the "Application" tab, "Assembly Information" button.


这篇关于帮助使用System.Reflection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆