How to use Emit method of Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST.ExpressionStatement class

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

ClassProxyInstanceContributor.cs

Source:ClassProxyInstanceContributor.cs Github

copy

Full Screen

...18 using System.Reflection;19#if FEATURE_SERIALIZATION20 using System.Runtime.Serialization;21#endif22 using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters;23 using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.CodeBuilders;24 using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;25 using Telerik.JustMock.Core.Castle.DynamicProxy.Internal;26 using Telerik.JustMock.Core.Castle.DynamicProxy.Tokens;27 internal class ClassProxyInstanceContributor : ProxyInstanceContributor28 {29#if FEATURE_SERIALIZATION30 private readonly bool delegateToBaseGetObjectData;31 private readonly bool implementISerializable;32 private ConstructorInfo serializationConstructor;33 private readonly IList<FieldReference> serializedFields = new List<FieldReference>();34#endif35 public ClassProxyInstanceContributor(Type targetType, IList<MethodInfo> methodsToSkip, Type[] interfaces,36 string typeId)37 : base(targetType, interfaces, typeId)38 {39#if FEATURE_SERIALIZATION40 if (targetType.IsSerializable)41 {42 implementISerializable = true;43 delegateToBaseGetObjectData = VerifyIfBaseImplementsGetObjectData(targetType, methodsToSkip);44 }45#endif46 }47 protected override Reference GetTargetReference(ClassEmitter emitter)48 {49 return SelfReference.Self;50 }51 public override void Generate(ClassEmitter @class, ProxyGenerationOptions options)52 {53 var interceptors = @class.GetField("__interceptors");54#if FEATURE_SERIALIZATION55 if (implementISerializable)56 {57 ImplementGetObjectData(@class);58 Constructor(@class);59 }60#endif61 ImplementProxyTargetAccessor(@class, interceptors);62 foreach (var attribute in targetType.GetTypeInfo().GetNonInheritableAttributes())63 {64 @class.DefineCustomAttribute(attribute.Builder);65 }66 }67#if FEATURE_SERIALIZATION68 protected override void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData,69 FieldReference field)70 {71 serializedFields.Add(field);72 base.AddAddValueInvocation(serializationInfo, getObjectData, field);73 }74 protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo,75 ArgumentReference streamingContext, ClassEmitter emitter)76 {77 codebuilder.AddStatement(new ExpressionStatement(78 new MethodInvocationExpression(79 serializationInfo,80 SerializationInfoMethods.AddValue_Bool,81 new ConstReference("__delegateToBase").ToExpression(),82 new ConstReference(delegateToBaseGetObjectData).83 ToExpression())));84 if (delegateToBaseGetObjectData == false)85 {86 EmitCustomGetObjectData(codebuilder, serializationInfo);87 return;88 }89 EmitCallToBaseGetObjectData(codebuilder, serializationInfo, streamingContext);90 }91 private void EmitCustomGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo)92 {93 var members = codebuilder.DeclareLocal(typeof(MemberInfo[]));94 var data = codebuilder.DeclareLocal(typeof(object[]));95 var getSerializableMembers = new MethodInvocationExpression(96 null,97 FormatterServicesMethods.GetSerializableMembers,98 new TypeTokenExpression(targetType));99 codebuilder.AddStatement(new AssignStatement(members, getSerializableMembers));100 // Sort to keep order on both serialize and deserialize side the same, c.f DYNPROXY-ISSUE-127101 var callSort = new MethodInvocationExpression(102 null,103 TypeUtilMethods.Sort,104 members.ToExpression());105 codebuilder.AddStatement(new AssignStatement(members, callSort));106 var getObjectData = new MethodInvocationExpression(107 null,108 FormatterServicesMethods.GetObjectData,109 SelfReference.Self.ToExpression(),110 members.ToExpression());111 codebuilder.AddStatement(new AssignStatement(data, getObjectData));112 var addValue = new MethodInvocationExpression(113 serializationInfo,114 SerializationInfoMethods.AddValue_Object,115 new ConstReference("__data").ToExpression(),116 data.ToExpression());117 codebuilder.AddStatement(new ExpressionStatement(addValue));118 }119 private void EmitCallToBaseGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo,120 ArgumentReference streamingContext)121 {122 var baseGetObjectData = targetType.GetMethod("GetObjectData",123 new[] { typeof(SerializationInfo), typeof(StreamingContext) });124 codebuilder.AddStatement(new ExpressionStatement(125 new MethodInvocationExpression(baseGetObjectData,126 serializationInfo.ToExpression(),127 streamingContext.ToExpression())));128 }129 private void Constructor(ClassEmitter emitter)130 {131 if (!delegateToBaseGetObjectData)132 {133 return;134 }135 GenerateSerializationConstructor(emitter);136 }137 private void GenerateSerializationConstructor(ClassEmitter emitter)138 {139 var serializationInfo = new ArgumentReference(typeof(SerializationInfo));140 var streamingContext = new ArgumentReference(typeof(StreamingContext));141 var ctor = emitter.CreateConstructor(serializationInfo, streamingContext);142 ctor.CodeBuilder.AddStatement(143 new ConstructorInvocationStatement(serializationConstructor,144 serializationInfo.ToExpression(),145 streamingContext.ToExpression()));146 foreach (var field in serializedFields)147 {148 var getValue = new MethodInvocationExpression(serializationInfo,149 SerializationInfoMethods.GetValue,150 new ConstReference(field.Reference.Name).ToExpression(),151 new TypeTokenExpression(field.Reference.FieldType));...

Full Screen

Full Screen

AbstractCodeBuilder.cs

Source:AbstractCodeBuilder.cs Github

copy

Full Screen

...10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14namespace Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.CodeBuilders15{16 using System;17 using System.Collections.Generic;18 using System.Reflection.Emit;19 using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;20 internal abstract class AbstractCodeBuilder21 {22 private readonly ILGenerator generator;23 private readonly List<Reference> ilmarkers;24 private readonly List<Statement> stmts;25 private bool isEmpty;26 protected AbstractCodeBuilder(ILGenerator generator)27 {28 this.generator = generator;29 stmts = new List<Statement>();30 ilmarkers = new List<Reference>();31 isEmpty = true;32 }33 //NOTE: should we make this obsolete if no one is using it?34 public /*protected internal*/ ILGenerator Generator35 {36 get { return generator; }37 }38 internal bool IsEmpty39 {40 get { return isEmpty; }41 }42 public AbstractCodeBuilder AddExpression(Expression expression)43 {44 return AddStatement(new ExpressionStatement(expression));45 }46 public AbstractCodeBuilder AddStatement(Statement stmt)47 {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)69 {70 stmt.Emit(member, il);71 }72 }73 }74}...

Full Screen

Full Screen

ExpressionStatement.cs

Source:ExpressionStatement.cs Github

copy

Full Screen

...10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14namespace Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST15{16 using System.Reflection.Emit;17 internal class ExpressionStatement : Statement18 {19 private readonly Expression expression;20 public ExpressionStatement(Expression expression)21 {22 this.expression = expression;23 }24 public override void Emit(IMemberEmitter member, ILGenerator gen)25 {26 // TODO: Should it discard any possible return value with a pop?27 expression.Emit(member, gen);28 }29 }30}...

Full Screen

Full Screen

Emit

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.Core.Castle.DynamicProxy.Generators.Emitters.SimpleAST;7{8 {9 public void Method1()10 {11 ExpressionStatement statement = new ExpressionStatement();12 statement.Emit(null);13 }14 }15}

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.

Most used method in ExpressionStatement

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful