static ControlAccessor() { SafeField fldControls = null; MethodInfo fnClear = null; SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate { fnClear = GetMethod("Clear"); fldControls = new SafeField(typeof(ControlCollection).GetField("_controls", BindingFlags.Instance | BindingFlags.NonPublic)); }); s_miClear = fnClear; ControlsArrayField = fldControls; CreateControlCollectionDelegate fnBaseCreateControlCollection = null; AddedControlDelegate fnBaseAddedControl = null; RemovedControlDelegate fnBaseRemovedControl = null; VoidMethodDelegate fnBaseClearNamingContainer = null; SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate { fnBaseCreateControlCollection = (CreateControlCollectionDelegate)Delegate.CreateDelegate(typeof(CreateControlCollectionDelegate), GetMethod("CreateControlCollection")); fnBaseAddedControl = (AddedControlDelegate)Delegate.CreateDelegate(typeof(AddedControlDelegate), GetMethod("AddedControl")); fnBaseRemovedControl = (RemovedControlDelegate)Delegate.CreateDelegate(typeof(RemovedControlDelegate), GetMethod("RemovedControl")); fnBaseClearNamingContainer = (VoidMethodDelegate)Delegate.CreateDelegate(typeof(VoidMethodDelegate), GetMethod("ClearNamingContainer")); }); BaseCreateControlCollection = fnBaseCreateControlCollection; BaseAddedControl = fnBaseAddedControl; BaseRemovedControl = fnBaseRemovedControl; BaseClearNamingContainer = fnBaseClearNamingContainer; }
static ControlAccessor() { SafeField fldControls = null; MethodInfo fnClear = null; SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate { fnClear = GetMethod("Clear"); fldControls = new SafeField(typeof(ControlCollection).GetField("_controls", BindingFlags.Instance | BindingFlags.NonPublic)); }); s_miClear = fnClear; ControlsArrayField = fldControls; CreateControlCollectionDelegate fnBaseCreateControlCollection = null; AddedControlDelegate fnBaseAddedControl = null; RemovedControlDelegate fnBaseRemovedControl = null; VoidMethodDelegate fnBaseClearNamingContainer = null; SecurityCritical.ExecutePrivileged(new PermissionSet(PermissionState.Unrestricted), delegate { fnBaseCreateControlCollection = (CreateControlCollectionDelegate)Delegate.CreateDelegate(typeof(CreateControlCollectionDelegate), GetMethod("CreateControlCollection")); fnBaseAddedControl = (AddedControlDelegate)Delegate.CreateDelegate(typeof(AddedControlDelegate), GetMethod("AddedControl")); fnBaseRemovedControl = (RemovedControlDelegate)Delegate.CreateDelegate(typeof(RemovedControlDelegate), GetMethod("RemovedControl")); fnBaseClearNamingContainer = (VoidMethodDelegate)Delegate.CreateDelegate(typeof(VoidMethodDelegate), GetMethod("ClearNamingContainer")); }); BaseCreateControlCollection = fnBaseCreateControlCollection; BaseAddedControl = fnBaseAddedControl; BaseRemovedControl = fnBaseRemovedControl; BaseClearNamingContainer = fnBaseClearNamingContainer; }