Archive for Luglio 28th, 2008

test

CodeKeep C# Feed Luglio 28th, 2008

Description: test

Link: http://www.codekeep.net/snippets/7c0eba81-d87e-40ef-8b79-e906edee99dd.aspx

public long GetRegisteredUserCount(int countryId)
        {
            string sql = "select count(*) Ret from [user] u inner join UserWidget on u.id = userwidget.userid where u.CountryId = :country";
            ISQLQuery query = NHibernateSession.CreateSQLQuery(sql);
            query.SetInt32("country", countryId);
            query.AddScalar("Ret", NHibernateUtil.Int64);

            object result = query.UniqueResult();
            return result == null ? 0 : Convert.ToInt64(result);
        }

How to access the Call Stack C#

CodeKeep C# Feed Luglio 28th, 2008

Description: Access the call stack window content

Link: http://www.codekeep.net/snippets/1809f49c-c6a1-47ef-8c4a-6bc8e1a8faca.aspx

view plaincopy to clipboardprint?
// First create an instance of the call stack   
StackTrace callStack = new StackTrace();   
  
// Next select the frame we want...   
// 0 : current frame for the current method   
// 1 : Frame that called the current method   
// 2 : Frame that called the frame that called the current method   
// 3 : ...you get the idea!   
StackFrame frame = callStack.GetFrame(1);   
  
// Using StackFrame.GetMethod(), which returns a    
// MethodBase object, we can obtain detailed    
// information about about a method   
MethodBase method = frame.GetMethod();   
  
// Get the declaring type and method names    
string declaringType = method.DeclaringType.Name;   
string methodName = method.Name;  

source : http://neilkilbride.blogspot.com/2008/04/how-to-access-call-stack-c.html