Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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;
        }
    }




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]
Posted
Updated 31-Mar-13 5:59am
v2

1 solution

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.
 
Share this answer
 
Comments
samir5000 31-Mar-13 13:27pm    
I have my webbrowser with a splashscreen. And I placed this code under the splashscreen.cs.
I know that it returns a value if it's true. But what I mean is I have never used this code and namespace. How do you get your information to use for example this code. Assembly is the Class and used the methods inside this class. But how to get info about the class and methods individually. I want to understand this class and methods.
OriginalGriff 1-Apr-13 3:31am    
No, Assembly is not the class: the Assembly is the EXE or DLL (or whatever) you are building, and comprised a number of namespaces with their contained classes.

These methods just access the data held in the currently executing assembly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900