How to use LocalReference class of Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST package

Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST.LocalReference

GeneratorUtil.cs

Source:GeneratorUtil.cs Github

copy

Full Screen

...20 using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;21 using Telerik.JustMock.Core.Castle.DynamicProxy.Tokens;22 internal static class GeneratorUtil23 {24 public static void CopyOutAndRefParameters(TypeReference[] dereferencedArguments, LocalReference invocation,25 MethodInfo method, MethodEmitter emitter)26 {27 var parameters = method.GetParameters();28 if (!parameters.Any(IsByRef))29 {30 return; //saving the need to create locals if there is no need31 }32 var arguments = StoreInvocationArgumentsInLocal(emitter, invocation);33 for (var i = 0; i < parameters.Length; i++)34 {35 if (IsByRef(parameters[i]) && !IsReadOnly(parameters[i]))36 {37 emitter.CodeBuilder.AddStatement(AssignArgument(dereferencedArguments, i, arguments));38 }39 }40 bool IsByRef(ParameterInfo parameter)41 {42 return parameter.ParameterType.GetTypeInfo().IsByRef;43 }44 bool IsReadOnly(ParameterInfo parameter)45 {46 // C# `in` parameters are also by-ref, but meant to be read-only.47 // The section "Metadata representation of in parameters" on the following page48 // defines how such parameters are marked:49 //50 // https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/readonly-ref.md51 //52 // This poses three problems for detecting them:53 //54 // * The C# Roslyn compiler marks `in` parameters with an `[in]` IL modifier,55 // but this isn't specified, nor is it used uniquely for `in` params.56 //57 // * `System.Runtime.CompilerServices.IsReadOnlyAttribute` is not defined on all58 // .NET platforms, so the compiler sometimes recreates that type in the same59 // assembly that contains the method having an `in` parameter. In other words,60 // it's an attribute one must check for by name (which is slow, as it implies61 // use of a `GetCustomAttributes` enumeration instead of a faster `IsDefined`).62 //63 // * A required custom modifier `System.Runtime.InteropServices.InAttribute`64 // is always present in those cases relevant for DynamicProxy (proxyable methods),65 // but not all targeted platforms support reading custom modifiers. Also,66 // support for cmods is generally flaky (at this time of writing, mid-2018).67 //68 // The above points inform the following detection logic: First, we rely on an IL69 // `[in]` modifier being present. This is a "fast guard" against non-`in` parameters:70 if ((parameter.Attributes & (ParameterAttributes.In | ParameterAttributes.Out)) == ParameterAttributes.In)71 {72 // Here we perform the actual check. We don't rely on cmods because support73 // for them is at current too unreliable in general, and because we wouldn't74 // be saving much time anyway.75 if (parameter.GetCustomAttributes(false).Any(IsIsReadOnlyAttribute))76 {77 return true;78 }79 }80 return false;81 bool IsIsReadOnlyAttribute(object attribute)82 {83 // The comparison by name is intentional; any assembly could define that attribute.84 // See explanation in comment above.85 return attribute.GetType().FullName == "System.Runtime.CompilerServices.IsReadOnlyAttribute";86 }87 }88 }89 private static ConvertExpression Argument(int i, LocalReference invocationArgs, TypeReference[] arguments)90 {91 return new ConvertExpression(arguments[i].Type, new LoadRefArrayElementExpression(i, invocationArgs));92 }93 private static AssignStatement AssignArgument(TypeReference[] dereferencedArguments, int i,94 LocalReference invocationArgs)95 {96 return new AssignStatement(dereferencedArguments[i], Argument(i, invocationArgs, dereferencedArguments));97 }98 private static AssignStatement GetArguments(LocalReference invocationArgs, LocalReference invocation)99 {100 return new AssignStatement(invocationArgs, new MethodInvocationExpression(invocation, InvocationMethods.GetArguments));101 }102 private static LocalReference StoreInvocationArgumentsInLocal(MethodEmitter emitter, LocalReference invocation)103 {104 var invocationArgs = emitter.CodeBuilder.DeclareLocal(typeof(object[]));105 emitter.CodeBuilder.AddStatement(GetArguments(invocationArgs, invocation));106 return invocationArgs;107 }108 }109}...

Full Screen

Full Screen

InvocationWithGenericDelegateContributor.cs

Source:InvocationWithGenericDelegateContributor.cs Github

copy

Full Screen

...63 invokeMethodOnTarget.CodeBuilder.AddStatement(64 SetDelegate(localReference, localTarget, closedDelegateType, closedMethodOnTarget));65 return localReference;66 }67 private AssignStatement SetDelegate(LocalReference localDelegate, ReferenceExpression localTarget,68 Type closedDelegateType, MethodInfo closedMethodOnTarget)69 {70 var delegateCreateDelegate = new MethodInvocationExpression(71 null,72 DelegateMethods.CreateDelegate,73 new TypeTokenExpression(closedDelegateType),74 localTarget,75 new MethodTokenExpression(closedMethodOnTarget));76 return new AssignStatement(localDelegate, new ConvertExpression(closedDelegateType, delegateCreateDelegate));77 }78 }79}...

Full Screen

Full Screen

AbstractCodeBuilder.cs

Source:AbstractCodeBuilder.cs Github

copy

Full Screen

...48 SetNonEmpty();49 stmts.Add(stmt);50 return this;51 }52 public LocalReference DeclareLocal(Type type)53 {54 var local = new LocalReference(type);55 ilmarkers.Add(local);56 return local;57 }58 public /*protected internal*/ void SetNonEmpty()59 {60 isEmpty = false;61 }62 internal void Generate(IMemberEmitter member, ILGenerator il)63 {64 foreach (var local in ilmarkers)65 {66 local.Generate(il);67 }68 foreach (var stmt in stmts)...

Full Screen

Full Screen

LocalReference

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 var local = new LocalReference(typeof(int));12 var expression = local == 1;13 Console.WriteLine(expression.ToString());14 }15 }16}17Hi, I have the same problem with the latest official release (2015.3.930.2). When can we expect the fix to be available?

Full Screen

Full Screen

LocalReference

Using AI Code Generation

copy

Full Screen

1using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 public void Method()10 {11 LocalReference local = new LocalReference(typeof(string));12 Console.WriteLine(local.LocalType);13 }14 }15}

Full Screen

Full Screen

LocalReference

Using AI Code Generation

copy

Full Screen

1{2 {3 private readonly TypeReference type;4 private readonly LocalBuilder local;5 public LocalReference(LocalBuilder local)6 {7 this.local = local;8 type = new TypeReference(local.LocalType);9 }10 {11 get { return type; }12 }13 public override void LoadAddressOfReference(ILGenerator gen)14 {15 gen.Emit(OpCodes.Ldloca, local);16 }17 public override void LoadReference(ILGenerator gen)18 {19 gen.Emit(OpCodes.Ldloc, local);20 }21 public override void StoreReference(ILGenerator gen)22 {23 gen.Emit(OpCodes.Stloc, local);24 }25 }26}27using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;28{29 {30 private readonly TypeReference type;31 private readonly LocalBuilder local;32 public LocalReference(LocalBuilder local)33 {34 this.local = local;35 type = new TypeReference(local.LocalType);36 }37 {38 get { return type; }39 }40 public override void LoadAddressOfReference(ILGenerator gen)41 {42 gen.Emit(OpCodes.Ldloca, local);43 }44 public override void LoadReference(ILGenerator gen)45 {46 gen.Emit(OpCodes.Ldloc, local);47 }48 public override void StoreReference(ILGenerator gen)49 {50 gen.Emit(OpCodes.Stloc, local);51 }52 }53}54using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;55{56 {57 private readonly TypeReference type;58 private readonly LocalBuilder local;59 public LocalReference(LocalBuilder local)60 {61 this.local = local;

Full Screen

Full Screen

LocalReference

Using AI Code Generation

copy

Full Screen

1{2 static void Main(string[] args)3 {4 var mock = Mock.Create<ISampleInterface>();5 var local = new LocalReference(typeof(ISampleInterface));6 var expression = Expression.Lambda<Func<ISampleInterface, bool>>(Expression.Equal(local, Expression.Constant(mock)), local);7 var func = expression.Compile();8 }9}10{11}12var mock = Mock.Create<ISampleInterface>();13var local = new LocalReference(typeof(ISampleInterface));14var expression = Expression.Lambda<Func<ISampleInterface, bool>>(Expression.Equal(local, Expression.Constant(mock)), local);15var func = expression.Compile();16var mock = Mock.Create<ISampleInterface>();17var local = new LocalReference(typeof(ISampleInterface));18var expression = Expression.Lambda<Func<ISampleInterface, bool>>(Expression.Equal(local, Expression.Constant(mock)), local);19var func = expression.Compile();

Full Screen

Full Screen

LocalReference

Using AI Code Generation

copy

Full Screen

1LocalReference localReference = new LocalReference(typeof(int));2ReturnStatement returnStatement = new ReturnStatement(localReference);3MethodEmitter methodEmitter = new MethodEmitter(emitter, "Add", typeof(int));4methodEmitter.CreateMethodBody(new Statement[]5{6 new AssignStatement(localReference, new MethodInvokeExpression(typeof(Math).GetMethod("Add", BindingFlags.Static | BindingFlags.Public), new Expression[]7 {8 new ArgumentReference(typeof(int), 0),9 new ArgumentReference(typeof(int), 1)10 })),11});12emitter.CreateType();13assemblyBuilder.Save("DynamicAssembly.dll");14Telerik.JustMock.Core (in Telerik.JustMock.Core.dll) Version: 2017.2.615.45 (2017.2.615.45)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run JustMockLite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful