Fixing Brail Templates for VS Net wizards.
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Scopes / ScopeUtil.cs
blob63a1537738346f40621854b3b3bc662de2df86e7
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Framework.Scopes
17 using System;
19 internal class ScopeUtil
21 internal static ISessionScope FindPreviousScope(ISessionScope thisScope,
22 bool preferenceForTransactional)
24 return FindPreviousScope(thisScope, preferenceForTransactional, false);
27 internal static ISessionScope FindPreviousScope(ISessionScope thisScope,
28 bool preferenceForTransactional, bool doNotReturnSessionScope)
30 object[] items = ThreadScopeAccessor.Instance.CurrentStack.ToArray();
32 ISessionScope first = null;
34 for (int i = 0; i < items.Length; i++)
36 ISessionScope scope = items[i] as ISessionScope;
38 if (scope == thisScope) continue;
40 if (first == null) first = scope;
42 if (!preferenceForTransactional) break;
44 if (preferenceForTransactional && scope.ScopeType == SessionScopeType.Transactional)
46 return scope;
50 return doNotReturnSessionScope ? null : first;