public static object GetObject(this Thread key) { Contract.Requires <ArgumentNullException>(key != null); lock (g_pLookGetObj) { if (g_pGetObject == null) { ParameterExpression g_pThread = Expression.Parameter(typeof(Thread)); FieldInfo g_pField = ThreadUtils.GetObjectField(); g_pGetObject = Expression.Lambda <Func <Thread, object> >(Expression.Field(g_pThread, g_pField), g_pThread).Compile(); } } return(g_pGetObject(key)); }
public static void SetObject(this Thread key, object value) { Contract.Requires <ArgumentNullException>(key != null); lock (g_pLookSetObj) { if (g_pSetObject == null) { ParameterExpression g_pThread = Expression.Parameter(typeof(Thread)); FieldInfo g_pField = ThreadUtils.GetObjectField(); ParameterExpression g_pState = Expression.Parameter(typeof(object)); g_pSetObject = Expression.Lambda <Action <Thread, object> >(Expression.Assign(Expression.Field(g_pThread, g_pField), g_pState), g_pThread, g_pState).Compile(); } } g_pSetObject(key, value); }