Skip to main content

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

using Catalyst.BO.StudentProfileBO;

using Catalyst.BO.ReportBO;

using Catalyst.DAL.ReportDAO;

using System.Collections;

using System.Data;

namespace Catalyst.BO.Factory { public class CFactory {

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Catalyst.BO.StudentProfileBO;
using Catalyst.BO.ReportBO;
using Catalyst.DAL.ReportDAO;
using System.Collections;
using System.Data;

namespace Catalyst.BO.Factory
{
    public class CFactory
    {
        public static object getClassInstance(string key, params  object[] constructorArgs)
        {
            string assemblyPath = null;
            string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

            DataSet objDataset = getAssemblyInfo(key);
            if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
            {
                assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
            }

            Assembly assembly;
            Type type;

            if (assemblyPath != null && assemblyPath != string.Empty)
            {
                assembly = Assembly.LoadFile(assemblyPath);
                type = assembly.GetType(customClassName);
            }
            else // if no customisation
            {
                type = Type.GetType(key);
            }

            object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
            if (classInstance == null) throw new Exception("broke");
            return classInstance;
        }
    }
}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

using Catalyst.BO.StudentProfileBO;

using Catalyst.BO.ReportBO;

using Catalyst.DAL.ReportDAO;

using System.Collections;

using System.Data;

namespace Catalyst.BO.Factory { public class CFactory {

    public static object getClassInstance(string key, params  object[] constructorArgs)
    {
        string assemblyPath = null;
        string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using Catalyst.BO.StudentProfileBO;
using Catalyst.BO.ReportBO;
using Catalyst.DAL.ReportDAO;
using System.Collections;
using System.Data;

namespace Catalyst.BO.Factory
{
    public class CFactory
    {
        public static object getClassInstance(string key, params  object[] constructorArgs)
        {
            string assemblyPath = null;
            string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

            DataSet objDataset = getAssemblyInfo(key);
            if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
            {
                assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
            }

            Assembly assembly;
            Type type;

            if (assemblyPath != null && assemblyPath != string.Empty)
            {
                assembly = Assembly.LoadFile(assemblyPath);
                type = assembly.GetType(customClassName);
            }
            else // if no customisation
            {
                type = Type.GetType(key);
            }

            object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
            if (classInstance == null) throw new Exception("broke");
            return classInstance;
        }
    }
}
added 390 characters in body
Source Link
Kuntady Nithesh
  • 11.8k
  • 20
  • 65
  • 88

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

ADD :

I wrote the code like this

public static object getClassInstance(string key, params object[] constructorArgs)using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

using Catalyst.BO.StudentProfileBO;

using Catalyst.BO.ReportBO;

using Catalyst.DAL.ReportDAO;

using System.Collections;

using System.Data;

namespace Catalyst.BO.Factory { string assemblyPath = null;public class CFactory string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);{

    public static object getClassInstance(string key, params  object[] constructorArgs)
    {
        string assemblyPath = null;
        string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }
}

}

key passed to the function is "CReportBO". CReportBO is accessible in the function's scope . but in //if no customization section (i.e type = Type.GetType(key) ) , type returns me null . whats wrong ?

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

ADD :

I wrote the code like this

public static object getClassInstance(string key, params object[] constructorArgs) { string assemblyPath = null; string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }

key passed to the function is "CReportBO". CReportBO is accessible in the function's scope . but in //if no customization section (i.e type = Type.GetType(key) ) , type returns me null . whats wrong ?

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

ADD :

I wrote the code like this

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

using Catalyst.BO.StudentProfileBO;

using Catalyst.BO.ReportBO;

using Catalyst.DAL.ReportDAO;

using System.Collections;

using System.Data;

namespace Catalyst.BO.Factory { public class CFactory {

    public static object getClassInstance(string key, params  object[] constructorArgs)
    {
        string assemblyPath = null;
        string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }
}

}

key passed to the function is "CReportBO". CReportBO is accessible in the function's scope . but in //if no customization section (i.e type = Type.GetType(key) ) , type returns me null . whats wrong ?

added 1430 characters in body
Source Link
Kuntady Nithesh
  • 11.8k
  • 20
  • 65
  • 88

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

ADD :

I wrote the code like this

public static object getClassInstance(string key, params object[] constructorArgs) { string assemblyPath = null; string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }

key passed to the function is "CReportBO". CReportBO is accessible in the function's scope . but in //if no customization section (i.e type = Type.GetType(key) ) , type returns me null . whats wrong ?

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

I have function as below .

public static object getClassInstance(string key, object constructorParameter)
{
         // body here
}

Key variable will have my class name . I need to return the new instance of the class . If the constructorParm is null then i need to load the class with default constructor else with the constructor parameter passed. How do i do this ?

ADD :

I wrote the code like this

public static object getClassInstance(string key, params object[] constructorArgs) { string assemblyPath = null; string customClassName = key.Substring(0, 1) + "Custom" + key.Substring(1);

        DataSet objDataset = getAssemblyInfo(key);
        if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
        {
            assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
        }

        Assembly assembly;
        Type type;

        if (assemblyPath != null && assemblyPath != string.Empty)
        {
            assembly = Assembly.LoadFile(assemblyPath);
            type = assembly.GetType(customClassName);
        }
        else // if no customisation
        {
            type = Type.GetType(key);
        }

        object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
        if (classInstance == null) throw new Exception("broke");
        return classInstance;

    }

key passed to the function is "CReportBO". CReportBO is accessible in the function's scope . but in //if no customization section (i.e type = Type.GetType(key) ) , type returns me null . whats wrong ?

formatted code
Source Link
slugster
  • 50k
  • 14
  • 105
  • 150
Loading
Source Link
Kuntady Nithesh
  • 11.8k
  • 20
  • 65
  • 88
Loading