Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Viewing Metadata in C#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 722
    Comment on it

    Reflection is used to find information at run time. The classes that are used resides in the System.Reflection namespace.

     

    The System.Reflection namespace contains the classes that allows you to access information and to dynamically add types, values, and objects to the application.

     

     

     

     

    Benefits of Reflection:

    • It allows to view attribute information.

    • It allows examining the assemblies and instantiate its type.

    • It allows late binding of methods and properties.

    • It allows creating run times and perform manipulation from it.

     

     

    using System;
    
    [AttributeUsage(AttributeTargets.All)]
    public class HelpAttribute : System.Attribute
    {
       public readonly string Url;
       
       public string Topic   // Topic is a named parameter
       {
          get
          {
             return topic;
          }
          set
          {
             topic = value;
          }
       }
       
       public HelpAttribute(string url)   // url is a positional parameter
       {
          this.Url = url;
       }
       private string topic;
    }
    
    [HelpAttribute("Information on the class MyClass")]
    class MyClass
    {
    }
    namespace AttributeAppl
    {
       class Program
       {
          static void Main(string[] args)
          {
             System.Reflection.MemberInfo info = typeof(MyClass);
             object[] attributes = info.GetCustomAttributes(true);
             for (int i = 0; i < attributes.Length; i++)
             {
                System.Console.WriteLine(attributes[i]);
             }
             
             Console.ReadKey();
          }
       }
    }

     

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: