object CreateNullProxyForType(Type type) { var pcd = CreateSafeNullProxyDescriptorFor(type); Type proxyType = _proxyModule.GetTypeFromProxyClassDescriptor(pcd); return(StaticInstanceMixin.GetInstanceValueFor(proxyType)); }
void EmitCtorForSafeNullProxy(ILGenerator gen, Type returnType) { // The argument for the constructor is already on the stack (which is the return value // from the method call on the real subject). var pcd = SafeFactory.CreateSafeNullProxyDescriptorFor(returnType); var proxyType = _proxyModule.GetTypeFromProxyClassDescriptor(pcd); StaticInstanceMixin.PushInstanceOnStackFor(proxyType, gen); }
object GetMethodIndexProxy(Type subjectType) { Func <object> getFunc; if (!_computeMethodIndexGetFuncBySubject.TryGetValue(subjectType, out getFunc)) { var pcd = GetProxyClassDescriptorForSubjectType(subjectType); var proxyType = _proxyModule.GetTypeFromProxyClassDescriptor(pcd); getFunc = StaticInstanceMixin.GetInstanceValueFuncFor(proxyType); getFunc = _computeMethodIndexGetFuncBySubject.GetOrAdd(subjectType, getFunc); } return(getFunc()); }
public void DefaultInstanceIsNotThreadUnique() { var pcd = new ProxyClassDescriptor(new StaticInstanceMixin()); var proxyType = ProxyModule.Default.GetTypeFromProxyClassDescriptor(pcd); object instance = StaticInstanceMixin.GetInstanceValueFor(proxyType); var task = Task.Factory.StartNew(() => StaticInstanceMixin.GetInstanceValueFor(proxyType), TaskCreationOptions.LongRunning); task.Wait(); object instance2 = task.Result; Assert.That(instance, Is.TypeOf(proxyType)); Assert.That(instance, Is.SameAs(instance2)); }
public virtual void PushDefaultReturnValue(ILGenerator gen, Type returnType) { if (returnType.IsInterface()) { var pcd = SafeFactory.CreateSafeNullProxyDescriptorFor(returnType); var proxyType = _proxyModule.GetTypeFromProxyClassDescriptor(pcd); StaticInstanceMixin.PushInstanceOnStackFor(proxyType, gen); } else { gen.EmitLdDefaultValue(returnType); } }
void GenerateFromAction(ILGenerator gen) { var cmi = gen.DeclareLocal(_methodIndexProxyType.AsType()); StaticInstanceMixin.PushInstanceOnStackFor(_methodIndexProxyType, gen); gen.Emit(OpCodes.Stloc, cmi); //int DoesMethodExist(Action<T> exemplar); gen.Emit(OpCodes.Ldarg_1); // push exemplar gen.Emit(OpCodes.Ldloc, cmi); // push the ISubjectType gen.Emit(OpCodes.Callvirt, typeof(Action <>).MakeGenericType(_methodExistsSubjectType).GetMethod("Invoke")); gen.Emit(OpCodes.Ldloc, cmi); // push the IComputeMethodExistsResult gen.Emit(OpCodes.Callvirt, typeof(IComputeMethodIndexResult).GetProperty("MethodIndex").GetGetMethod()); gen.Emit(OpCodes.Call, _smiMethod); gen.Emit(OpCodes.Ret); }