/// <summary> /// Constructor /// </summary> /// <param name="ObjectCallingOn">Object calling on</param> /// <param name="Method">Method builder</param> /// <param name="MethodCalling">Method calling on the object</param> /// <param name="Parameters">List of parameters to send in</param> public Call(IMethodBuilder Method, VariableBase ObjectCallingOn, MethodInfo MethodCalling, object[] Parameters) : base() { this.ObjectCallingOn = ObjectCallingOn; this.MethodCalling = MethodCalling; this.MethodCallingFrom = Method; if (MethodCalling.ReturnType != null && MethodCalling.ReturnType != typeof(void)) { Result = Method.CreateLocal(MethodCalling.Name + "ReturnObject"+Utilities.Reflection.Emit.BaseClasses.MethodBase.ObjectCounter.ToString(CultureInfo.InvariantCulture), MethodCalling.ReturnType); } if (Parameters != null) { this.Parameters = new VariableBase[Parameters.Length]; for (int x = 0; x < Parameters.Length; ++x) { if (Parameters[x] is VariableBase) this.Parameters[x] = (VariableBase)Parameters[x]; else this.Parameters[x] = MethodCallingFrom.CreateConstant(Parameters[x]); } } else { this.Parameters = null; } }
/// <summary> /// Constructor /// </summary> /// <param name="LeftHandSide">Left hand side</param> /// <param name="Value">Value to store</param> public Assign(VariableBase LeftHandSide, object Value) : base() { Contract.Requires<ArgumentNullException>(LeftHandSide!=null,"LeftHandSide"); this.LeftHandSide = LeftHandSide; VariableBase TempValue = Value as VariableBase; this.RightHandSide = TempValue == null ? Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(Value) : TempValue; }
/// <summary> /// Constructor /// </summary> /// <param name="LeftHandSide">Left hand side</param> /// <param name="Value">Value to store</param> public Assign(VariableBase LeftHandSide, object Value) : base() { if (LeftHandSide == null) throw new ArgumentNullException("LeftHandSide"); this.LeftHandSide = LeftHandSide; if (!(Value is VariableBase)) this.RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(Value); else this.RightHandSide = (VariableBase)Value; }
/// <summary> /// Constructor /// </summary> /// <param name="EndIfLabel">End if label (for this else if)</param> /// <param name="ComparisonType">Comparison type</param> /// <param name="LeftHandSide">Left hand side</param> /// <param name="RightHandSide">Right hand side</param> public ElseIf(Label EndIfLabel, Comparison ComparisonType, VariableBase LeftHandSide, VariableBase RightHandSide) : base() { this.EndIfLabel = EndIfLabel; if (LeftHandSide != null) this.LeftHandSide = LeftHandSide; else this.LeftHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null); if (RightHandSide != null) this.RightHandSide = RightHandSide; else this.RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null); this.ComparisonType = ComparisonType; }
/// <summary> /// Calls a method on this variable /// </summary> /// <param name="MethodName">Method name</param> /// <param name="Parameters">Parameters sent in</param> /// <returns>Variable returned by the function (if one exists, null otherwise)</returns> public virtual VariableBase Call(string MethodName, object[] Parameters = null) { Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(MethodName),"MethodName"); List<Type> ParameterTypes = new List<Type>(); if (Parameters != null) { foreach (object Parameter in Parameters) { VariableBase TempParameter = Parameter as VariableBase; ParameterTypes.Add(TempParameter != null ? TempParameter.DataType : Parameter.GetType()); } } return Call(DataType.GetMethod(MethodName, ParameterTypes.ToArray()), Parameters); }
/// <summary> /// Constructor /// </summary> /// <param name="ComparisonType">Comparison type</param> /// <param name="LeftHandSide">Left hand side</param> /// <param name="RightHandSide">Right hand side</param> public While(Comparison ComparisonType, VariableBase LeftHandSide, VariableBase RightHandSide) : base() { ILGenerator Generator = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator; this.StartWhileLabel = Generator.DefineLabel(); this.EndWhileLabel = Generator.DefineLabel(); if (LeftHandSide != null) this.LeftHandSide = LeftHandSide; else this.LeftHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null); if (RightHandSide != null) this.RightHandSide = RightHandSide; else this.RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.CreateConstant(null); this.ComparisonType = ComparisonType; }
/// <summary> /// Creates a new object /// </summary> /// <param name="ObjectType">Object type</param> /// <param name="Variables">Variables to use</param> /// <returns>The new object</returns> public virtual VariableBase NewObj(Type ObjectType, object[] Variables = null) { SetCurrentMethod(); List <Type> VariableTypes = new List <Type>(); if (Variables != null) { foreach (object Variable in Variables) { VariableBase TempVariable = Variable as VariableBase; VariableTypes.Add(TempVariable != null ? TempVariable.DataType : Variable.GetType()); } } ConstructorInfo Constructor = ObjectType.GetConstructor(VariableTypes.ToArray()); return(NewObj(Constructor, Variables)); }
/// <summary> /// Constructor /// </summary> /// <param name="ObjectCallingOn">Object calling on</param> /// <param name="Method">Method builder</param> /// <param name="MethodCalling">Method calling on the object</param> /// <param name="Parameters">List of parameters to send in</param> public Call(IMethodBuilder Method, VariableBase ObjectCallingOn, ConstructorInfo MethodCalling, object[] Parameters) : base() { this.ObjectCallingOn = ObjectCallingOn; this.ConstructorCalling = MethodCalling; this.MethodCallingFrom = Method; if (Parameters != null) { this.Parameters = new VariableBase[Parameters.Length]; for (int x = 0; x < Parameters.Length; ++x) { if (Parameters[x] is VariableBase) this.Parameters[x] = (VariableBase)Parameters[x]; else this.Parameters[x] = MethodCallingFrom.CreateConstant(Parameters[x]); } } else { this.Parameters = null; } }
/// <summary> /// Creates a while statement /// </summary> /// <param name="LeftHandSide">Left hand side variable</param> /// <param name="ComparisonType">Comparison type</param> /// <param name="RightHandSide">Right hand side variable</param> /// <returns>The while object</returns> public virtual While While(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide) { SetCurrentMethod(); While TempCommand = new While(ComparisonType, LeftHandSide, RightHandSide); TempCommand.Setup(); Commands.Add(TempCommand); return(TempCommand); }
/// <summary> /// Unboxes a value to a specified type /// </summary> /// <param name="Value">Value to unbox</param> /// <param name="ValueType">Value type</param> public UnBox(VariableBase Value, Type ValueType) : base() { this.Value = Value; this.ValueType = ValueType; }
public virtual While While(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide) { SetCurrentMethod(); While TempCommand = new While(ComparisonType, LeftHandSide, RightHandSide); TempCommand.Setup(); Commands.Add(TempCommand); return TempCommand; }
public virtual VariableBase UnBox(VariableBase Value,Type ValueType) { UnBox TempCommand = new UnBox(Value, ValueType); TempCommand.Setup(); Commands.Add(TempCommand); ++ObjectCounter; return TempCommand.Result; }
public virtual void Throw(VariableBase Exception) { Throw TempCommand = new Throw(Exception); TempCommand.Setup(); Commands.Add(TempCommand); }
public virtual If If(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide) { SetCurrentMethod(); Utilities.Reflection.Emit.Commands.If TempCommand = new If(ComparisonType, LeftHandSide, RightHandSide); TempCommand.Setup(); Commands.Add(TempCommand); return TempCommand; }
public virtual void Call(VariableBase ObjectCallingOn, ConstructorInfo MethodCalling, object[] Parameters) { SetCurrentMethod(); Call TempCommand = new Call(this, ObjectCallingOn, MethodCalling, Parameters); TempCommand.Setup(); Commands.Add(TempCommand); ++ObjectCounter; }
public virtual VariableBase Call(VariableBase ObjectCallingOn, MethodInfo MethodCalling, object[] Parameters) { SetCurrentMethod(); Call TempCommand = new Call(this,ObjectCallingOn, MethodCalling, Parameters); TempCommand.Setup(); Commands.Add(TempCommand); ++ObjectCounter; return TempCommand.Result; }
public virtual void Assign(VariableBase LeftHandSide, object Value) { SetCurrentMethod(); Assign TempCommand = new Assign(LeftHandSide, Value); TempCommand.Setup(); Commands.Add(TempCommand); }
/// <summary> /// Sets up a property (List) /// </summary> /// <param name="Method">Method builder</param> /// <param name="BaseType">Base type for the object</param> /// <param name="ReturnValue">Return value</param> /// <param name="Property">Property info</param> /// <param name="Mapping">Mapping info</param> private void SetupListProperty(IMethodBuilder Method, Type BaseType, VariableBase ReturnValue, IProperty Property, IMapping Mapping) { Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName); Utilities.Reflection.Emit.Commands.If If1 = Method.If((VariableBase)SessionField, Comparison.NotEqual, null); { Utilities.Reflection.Emit.Commands.If If2 = Method.If(Field, Comparison.Equal, null); { //Load data VariableBase IDValue = Method.This.Call(BaseType.GetProperty(Mapping.IDProperty.Name).GetGetMethod()); VariableBase IDParameter = Method.NewObj(typeof(EqualParameter<>).MakeGenericType(Mapping.IDProperty.Type), new object[] { IDValue, "ID", "@" }); VariableBase PropertyList = Method.NewObj(typeof(List<IParameter>)); PropertyList.Call("Add", new object[] { IDParameter }); MethodInfo LoadPropertiesMethod = typeof(Session).GetMethod("LoadListProperties"); LoadPropertiesMethod = LoadPropertiesMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType.GetGenericArguments()[0] }); VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertiesMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") }); Field.Assign(ReturnVal); } If2.EndIf(); PropertyInfo CountProperty=Field.DataType.GetProperty("Count"); Utilities.Reflection.Emit.Commands.If If4 = Method.If(Field.Call(CountProperty.GetGetMethod()), Comparison.Equal, Method.CreateConstant(0)); { //Load data VariableBase IDValue = Method.This.Call(BaseType.GetProperty(Mapping.IDProperty.Name).GetGetMethod()); VariableBase IDParameter = Method.NewObj(typeof(EqualParameter<>).MakeGenericType(Mapping.IDProperty.Type), new object[] { IDValue, "ID", "@" }); VariableBase PropertyList = Method.NewObj(typeof(List<IParameter>)); PropertyList.Call("Add", new object[] { IDParameter }); MethodInfo LoadPropertiesMethod = typeof(Session).GetMethod("LoadProperties"); LoadPropertiesMethod = LoadPropertiesMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType.GetGenericArguments()[0] }); VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertiesMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") }); Field.Assign(ReturnVal); } If4.EndIf(); Utilities.Reflection.Emit.Commands.If If3 = Method.If(Field, Comparison.Equal, null); { Field.Assign(Method.NewObj(typeof(List<>).MakeGenericType(Property.Type).GetConstructor(Type.EmptyTypes))); } If3.EndIf(); } If1.EndIf(); ReturnValue.Assign(Field); }
/// <summary> /// Creates an if statement /// </summary> /// <param name="LeftHandSide">Left hand side variable</param> /// <param name="ComparisonType">Comparison type</param> /// <param name="RightHandSide">Right hand side variable</param> /// <returns>The if object</returns> public virtual If If(VariableBase LeftHandSide, Enums.Comparison ComparisonType, VariableBase RightHandSide) { SetCurrentMethod(); Utilities.Reflection.Emit.Commands.If TempCommand = new If(ComparisonType, LeftHandSide, RightHandSide); TempCommand.Setup(); Commands.Add(TempCommand); return(TempCommand); }
public override void Setup() { ILGenerator Generator = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator; if (RightHandSide.DataType.IsValueType && !LeftHandSide.DataType.IsValueType) { RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Box(RightHandSide); } else if (!RightHandSide.DataType.IsValueType && LeftHandSide.DataType.IsValueType) { RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.UnBox(RightHandSide, LeftHandSide.DataType); } else if (!RightHandSide.DataType.IsValueType && !LeftHandSide.DataType.IsValueType && RightHandSide.DataType != LeftHandSide.DataType) { RightHandSide = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Cast(RightHandSide, LeftHandSide.DataType); } if (LeftHandSide is FieldBuilder || LeftHandSide is IPropertyBuilder) Generator.Emit(OpCodes.Ldarg_0); if (RightHandSide is FieldBuilder || RightHandSide is IPropertyBuilder) Generator.Emit(OpCodes.Ldarg_0); RightHandSide.Load(Generator); if (RightHandSide.DataType != LeftHandSide.DataType) { if (ConversionOpCodes.ContainsKey(LeftHandSide.DataType)) { Generator.Emit(ConversionOpCodes[LeftHandSide.DataType]); } } LeftHandSide.Save(Generator); }
/// <summary> /// Defines an else if statement /// </summary> /// <param name="ComparisonType">Comparison type</param> /// <param name="LeftHandSide">left hand side value</param> /// <param name="RightHandSide">right hand side value</param> public virtual void ElseIf(VariableBase LeftHandSide, Comparison ComparisonType, VariableBase RightHandSide) { ILGenerator Generator = Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Generator; Generator.Emit(OpCodes.Br, EndIfFinalLabel); Generator.MarkLabel(EndIfLabel); EndIfLabel = Generator.DefineLabel(); Utilities.Reflection.Emit.BaseClasses.MethodBase.CurrentMethod.Commands.Add(new ElseIf(EndIfLabel, ComparisonType, LeftHandSide, RightHandSide)); }
/// <summary> /// Constructor /// </summary> /// <param name="Exception">Exception to throw</param> public Throw(VariableBase Exception) { this.Exception = Exception; }