System.Security.SecurityFrame.GetStack C# (CSharp) Method

GetStack() static public method

static public GetStack ( int skipFrames ) : ArrayList
skipFrames int
return System.Collections.ArrayList
		static public ArrayList GetStack (int skipFrames)
		{
			Array stack = _GetSecurityStack (skipFrames+2);
			ArrayList al = new ArrayList ();
			for (int i = 0; i < stack.Length; i++) {
				object o = stack.GetValue (i);
				// null are unused slots allocated in the runtime
				if (o == null)
					break;
				al.Add (new SecurityFrame ((RuntimeSecurityFrame)o));
			}
			return al;
		}
	}

Usage Example

Beispiel #1
0
        // The number of frames to skip depends on who's calling
        // - CodeAccessPermission.Demand (imperative)
        // - PermissionSet.Demand (imperative)
        // - SecurityManager.InternalDemand (declarative)
        internal void CasOnlyDemand(int skip)
        {
            Assembly  current = null;
            AppDomain domain  = null;

            if (_ignored == null)
            {
                // special case when directly called from CodeAccessPermission.Demand
                _ignored = new bool [list.Count];
            }

            ArrayList frames = SecurityFrame.GetStack(skip);

            if ((frames != null) && (frames.Count > 0))
            {
                SecurityFrame first = ((SecurityFrame)frames [0]);
                current = first.Assembly;
                domain  = first.Domain;
                // skip ourself, Demand and other security runtime methods
                foreach (SecurityFrame sf in frames)
                {
                    if (ProcessFrame(sf, ref current, ref domain))
                    {
                        if (AllIgnored())
                        {
                            return;                             // reached Assert
                        }
                    }
                }
                SecurityFrame last = ((SecurityFrame)frames [frames.Count - 1]);
                CheckAssembly(current, last);
                CheckAppDomain(domain, last);
            }

            // Is there a CompressedStack to handle ?
            CompressedStack stack = Thread.CurrentThread.GetCompressedStack();

            if ((stack != null) && !stack.IsEmpty())
            {
                foreach (SecurityFrame frame in stack.List)
                {
                    if (ProcessFrame(frame, ref current, ref domain))
                    {
                        if (AllIgnored())
                        {
                            return;                             // reached Assert
                        }
                    }
                }
            }
        }