Click here to Skip to main content
15,895,772 members
Articles / Programming Languages / C#

How to automate work when working with a Typed Dataset against a database (CSC)

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
22 Nov 2006CPOL2 min read 32.6K   462   15  
DatasetAdaptor encapsulates a dataset and permits automating the work between the database and the dataset.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Runtime.Remoting;

namespace DataDigest.Datas.Helper
{
    /// <summary>
    /// This class contains some usefull methods to work a bit with reflexion...
    /// </summary>
    /// <author>
    /// Blaise Braye
    /// </author>
    public static class HlpReflexion
    {

        /// <summary>
        /// Get classes in the executing assembly in the given namespace
        /// </summary>
        /// <param name="nameSpace">the namespace to crawl</param>
        /// <returns></returns>
        public static List<Type> GetClasses(string nameSpace)
        {
            return GetClasses(Assembly.GetExecutingAssembly(), nameSpace);
        }

        /// <summary>
        /// Get classes of an the assembly type which are contained in a namespace
        /// </summary>
        /// <param name="assembly">the type which link us with the assembly to crawl</param>
        /// <param name="nameSpace">the namespace to crawl</param>
        /// <returns></returns>
        public static List<Type> GetClasses(Type type, string nameSpace)
        {
            return GetClasses(type.Assembly, nameSpace);
        }

        /// <summary>
        /// Get classes of an assembly which are contained in a namespace
        /// </summary>
        /// <param name="assembly">the assembly to crawl</param>
        /// <param name="nameSpace">the namespace to crawl</param>
        /// <returns></returns>
        public static List<Type> GetClasses(Assembly assembly, string nameSpace)
        {
            List<Type> types = new List<Type>();
            foreach (Type type in assembly.GetTypes())
            {
                if (type.Namespace == nameSpace)
                    types.Add(type);
            }

            return types;
        }

        /// <summary>
        /// Activate an object with the given type
        /// </summary>
        /// <param name="type">type of object to instanciate</param>
        /// <returns></returns>
        public static object CreateInstance(Type type)
        {
            ObjectHandle oh = Activator.CreateInstanceFrom(type.Assembly.CodeBase, type.FullName);
            return oh.Unwrap();
        }

        /// <summary>
        /// allow late binding with calling a method on an object by reflection
        /// </summary>
        /// <param name="obj">the Object wich contains the method to call</param>
        /// <param name="methodName">the name of the method to call</param>
        /// <param name="vars">the params of the called method</param>
        public static void InvokeMethod(object obj, string methodName, params object[] vars)
        {

            BindingFlags flags = BindingFlags.InvokeMethod | BindingFlags.Instance |
                            BindingFlags.Public | BindingFlags.Static;

            obj.GetType().InvokeMember(
                methodName,
                flags,
                default(Binder),
                obj,
                vars);



        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Other UMH
Belgium Belgium
* Bachelor of Information Management at ISAT Charleroi in Belgium.
* Master II of Information science at UMH Mons.

I spend my time in small projects which can help me or small enterprises and
I am very interested in designing projects
with specifications of UML or in applying usual design patterns.

Comments and Discussions