static T GetOrRegisterHolder() { if (ms_key == null) { return(default(T)); } var funcPtr = default(IntPtr); if (InstanceGetters.TryGet(ms_key, out funcPtr)) { using (InstanceGetters.DisableProcessing()) return(GetHolderCore(ms_t, funcPtr)); } else { var funcPtrTmp = default(IntPtr); using (InstanceGetters.DisableProcessing()) funcPtrTmp = GetFunctionPointerCore(ms_t); while (!InstanceGetters.GetOrAdd(ms_key, funcPtrTmp, out funcPtr)) { ; } using (InstanceGetters.DisableProcessing()) return(GetHolderCore(ms_t, funcPtr)); } }
public bool TryRemove(IndirectionInfo info, out Work method) { method = default(Work); var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <BodyOfNonPublicMethod, Dictionary <string, Work> > > >(); if (holder.Source.Value == null) { return(false); } var dict = holder.Source.Value; lock (dict) { using (InstanceGetters.DisableProcessing()) { var _ = default(Delegate); if (!m_holder.TryRemove(info, out _)) { return(false); } var key = info + ""; if (!dict.ContainsKey(key)) { return(false); } method = dict[key]; dict.Remove(key); return(true); } } }
public Work AddOrUpdate(IndirectionInfo info, Work method) { var holder = LooseCrossDomainAccessor.GetOrRegister <GenericHolder <TaggedBag <BodyOfNonPublicMethod, Dictionary <string, Work> > > >(); if (holder.Source.Value == null) { holder.Source = TaggedBagFactory <BodyOfNonPublicMethod> .Make(new Dictionary <string, Work>()); } var dict = holder.Source.Value; lock (dict) { using (InstanceGetters.DisableProcessing()) { var key = info + ""; holder.Source.Value[key] = method; var wrapAndInvoke = CreateWrapAndInvokeMethod(IndirectionDelegate, key); m_holder.AddOrUpdate(info, wrapAndInvoke); dict[key] = method; return(method); } } }
public static void Register <T>() where T : InstanceHolder <T> { LooseCrossDomainAccessor <T> .Register(); lock (ms_unloadMethods) using (InstanceGetters.DisableProcessing()) ms_unloadMethods.Add(LooseCrossDomainAccessor <T> .Unload); }
public static bool TryGet <T>(out T holder) where T : InstanceHolder <T> { holder = LooseCrossDomainAccessor <T> .HolderOrDefault; if (holder == null && !InstanceGetters.IsDisabledProcessing()) { holder = GetOrRegister <T>(); } return(holder != null); }
public static void ExecuteOriginal(Action action) { if (action == null) { throw new ArgumentNullException("action"); } using (InstanceGetters.DisableProcessing()) action(); }
public static TDelegate SafelyCast <TDelegate>(Delegate source) where TDelegate : class { if (source == null) { return(null); } using (InstanceGetters.DisableProcessing()) return(source.Cast <TDelegate>(typeof(InstanceGetters).Module)); }
public static T ExecuteOriginal <T>(Func <T> func) { if (func == null) { throw new ArgumentNullException("func"); } using (InstanceGetters.DisableProcessing()) return(func()); }
static TargetSettingValue() { using (InstanceGetters.DisableProcessing()) { var all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var method in typeof(TargetSettingValue <TIndirection>).GetMethods(all)) { RuntimeHelpers.PrepareMethod(method.MethodHandle, new[] { typeof(TIndirection).TypeHandle }); } } }
protected override void Dispose(bool disposing) { lock (m_dict) { if (disposing) { using (InstanceGetters.DisableProcessing()) m_dict.Clear(); } } }
static TaggedBag() { using (InstanceGetters.DisableProcessing()) { var all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var method in typeof(TaggedBag <TTag, TValue>).GetMethods(all)) { RuntimeHelpers.PrepareMethod(method.MethodHandle, new[] { typeof(TTag).TypeHandle, typeof(TValue).TypeHandle }); } } }
static LooseCrossDomainAccessor() { using (InstanceGetters.DisableProcessing()) { var all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var method in typeof(LooseCrossDomainAccessor <T>).GetMethods(all)) { RuntimeHelpers.PrepareMethod(method.MethodHandle, new[] { typeof(T).TypeHandle }); } } }
static IndirectionHolder() { using (InstanceGetters.DisableProcessing()) { var all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var method in typeof(IndirectionHolder <TDelegate>).GetMethods(all)) { RuntimeHelpers.PrepareMethod(method.MethodHandle, new[] { typeof(TDelegate).TypeHandle }); } } }
public static T GetOrRegister <T>() where T : InstanceHolder <T> { var holder = LooseCrossDomainAccessor <T> .HolderOrRegistered; if (holder != null) { lock (ms_unloadMethods) using (InstanceGetters.DisableProcessing()) ms_unloadMethods.Add(LooseCrossDomainAccessor <T> .Unload); } return(holder); }
public TDelegate AddOrUpdate(IndirectionInfo info, TDelegate method) { lock (m_dict) { using (InstanceGetters.DisableProcessing()) { var key = info + ""; m_dict[key] = method; return(method); } } }
public static void Register() { if (ms_key == null) { return; } var funcPtr = default(IntPtr); using (InstanceGetters.DisableProcessing()) funcPtr = GetFunctionPointerCore(ms_t); InstanceGetters.TryAdd(ms_key, funcPtr); }
public void SetInstantiation(MethodBase target, Type[] sig, Type[] typeGenericArgs, Type[] methodGenericArgs) { using (InstanceGetters.DisableProcessing()) { if (target == null) { throw new ArgumentNullException("target"); } sig = sig.ReplaceGenericParameter(target.DeclaringType, typeGenericArgs, target, methodGenericArgs); Instantiation = sig.Select(_ => _.ToString()).ToArray(); } }
public static void Clear() { lock (ms_unloadMethods) { using (InstanceGetters.DisableProcessing()) { foreach (var unloadMethod in ms_unloadMethods) { unloadMethod(); } } } }
static InstanceHolder() { using (InstanceGetters.DisableProcessing()) { var all = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var method in typeof(InstanceHolder <T>).GetMethods(all).Where(_ => !_.IsAbstract)) { RuntimeHelpers.PrepareMethod(method.MethodHandle, new[] { typeof(T).TypeHandle }); } // Prepare JIT here if the type has been already known explicitly. new FallthroughException(); } }
public static BehaviorSetting ExcludeGeneric() { var repository = InstanceGetters.NewIndirectionAssemblyRepository(); var indAsmInfos = repository.FindAll(); var preps = indAsmInfos.SelectMany(_ => _.GetTypes()). Where(_ => _.GetInterface(typeof(IBehaviorPreparable).FullName) != null). Where(_ => !_.IsGenericType). Where(_ => _.GetConstructor(Type.EmptyTypes) != null). Select(_ => Activator.CreateInstance(_)). Cast <IBehaviorPreparable>();; var setting = new BehaviorSetting(); foreach (var prep in preps) { setting.Include(prep); } return(setting); }
public IndirectionHolderUntyped(IndirectionHolder <Delegate> holder, Type indDlgt) { using (InstanceGetters.DisableProcessing()) { if (holder == null) { throw new ArgumentNullException("holder"); } if (!indDlgt.IsSubclassOf(typeof(Delegate))) { throw new ArgumentException("The parameter must be a delegate type.", "indDlgt"); } m_holder = holder; IndirectionDelegate = indDlgt; } }
public bool TryRemove(IndirectionInfo info, out TDelegate method) { method = default(TDelegate); lock (m_dict) { using (InstanceGetters.DisableProcessing()) { var key = info + ""; if (!m_dict.ContainsKey(key)) { return(false); } method = m_dict[key]; m_dict.Remove(key); return(true); } } }
static Holder() { using (InstanceGetters.DisableProcessing()) { // Using AppDomainID is an easy way to synchronize the stubbed method that is in same AppDomain with profiler side. // In managed code, _dummyField (CLR v2.0.50727)/_pDomain (CLR v4.0.30319) field that belongs AppDomain class indicates that. // See also this QA: [How to get current application domain id?](https://social.msdn.microsoft.com/Forums/en-US/2e2bc361-8a4f-4973-b4fc-3c79adbe0351/how-to-get-current-application-domain-id?forum=netfxtoolsdev) var appDomainIdField = typeof(AppDomain).GetField("_dummyField", BindingFlags.NonPublic | BindingFlags.Instance); if (appDomainIdField == null) { appDomainIdField = typeof(AppDomain).GetField("_pDomain", BindingFlags.NonPublic | BindingFlags.Instance); } if (appDomainIdField == null) { throw new NotSupportedException(string.Format("This runtime 'v{0}' is not supported.", typeof(object).Assembly.ImageRuntimeVersion)); } Value = (IntPtr)appDomainIdField.GetValue(AppDomain.CurrentDomain); } }
static bool TryGetHolder(out T holder) { holder = default(T); if (ms_key == null) { return(false); } var funcPtr = default(IntPtr); if (!InstanceGetters.TryGet(ms_key, out funcPtr)) { holder = null; return(false); } else { using (InstanceGetters.DisableProcessing()) holder = GetHolderCore(ms_t, funcPtr); return(true); } }
public void Dispose() { Dispose(true); using (InstanceGetters.DisableProcessing()) GC.SuppressFinalize(this); }