C# Generics

//Main Program - Calling the GetResults Method
string mesaiBitisSaati = CommonClass.GetResults<string>(SystemCodes.MZB, 1);

//CommonClass - GetOneResult Method
public static T GetResults<T>(SystemCodes sistemKodu, decimal parametreKodu)
{
            try
            {
                object param = GetOneResult(sistemKodu, parametreKodu);
                return (T)Convert.ChangeType(param, typeof(T));
            }
            catch
            {
                return default(T);
            }
}

//CommonClass - GetOneResult Method 
public static string GetOneResult(SystemCodes sistemKodu, decimal parametreKodu)
{
            try
            {
                using (ProbelTESTEntities context = EntityProvider<ProbelTESTEntities>.NewContainer())
                {
                    TEST_TABLE param = context.TEST_TABLE.Where(x => x.SISTEM_ID == (decimal)sistemKodu &&
                                                                                        x.DEPARTMENT_ID == CommonInfos.ActiveUser.Department.Id &&
                                                                                        x.KODU == parametreKodu)
                                                                                        .SingleOrDefault();
                    return param.Assigned() ? param.DEGERI.ToUpper() : null;
                }
            }
            catch
            {
                return null;

            }

}

Comments

Popular posts from this blog

Solution for "Can not obtain Oracle client information from registry"

Solution for the fault: "System.Diagnostics.Process.Start is not working on IIS, but working on ASP.NET Development Server"