/// <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) { ObjectCallingOn = objectCallingOn; MethodCalling = methodCalling; MethodCallingFrom = method; if (methodCalling.ReturnType != null && methodCalling.ReturnType != typeof (void)) { Result = method.CreateLocal( methodCalling.Name + "ReturnObject" + MethodBase.ObjectCounter.ToString(CultureInfo.InvariantCulture), methodCalling.ReturnType); } if (parameters != null) { Parameters = new VariableBase[parameters.Length]; for (int x = 0; x < parameters.Length; ++x) { if (parameters[x] is VariableBase) Parameters[x] = (VariableBase) parameters[x]; else Parameters[x] = MethodCallingFrom.CreateConstant(parameters[x]); } } else { Parameters = null; } }
/// <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) { ObjectCallingOn = objectCallingOn; ConstructorCalling = methodCalling; MethodCallingFrom = method; if (parameters != null) { Parameters = new VariableBase[parameters.Length]; for (int x = 0; x < parameters.Length; ++x) { if (parameters[x] is VariableBase) { Parameters[x] = (VariableBase)parameters[x]; } else { Parameters[x] = MethodCallingFrom.CreateConstant(parameters[x]); } } } else { Parameters = null; } }
/// <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) { ObjectCallingOn = objectCallingOn; MethodCalling = methodCalling; MethodCallingFrom = method; if (methodCalling.ReturnType != null && methodCalling.ReturnType != typeof(void)) { Result = method.CreateLocal( methodCalling.Name + "ReturnObject" + MethodBase.ObjectCounter.ToString(CultureInfo.InvariantCulture), methodCalling.ReturnType); } if (parameters != null) { Parameters = new VariableBase[parameters.Length]; for (int x = 0; x < parameters.Length; ++x) { if (parameters[x] is VariableBase) { Parameters[x] = (VariableBase)parameters[x]; } else { Parameters[x] = MethodCallingFrom.CreateConstant(parameters[x]); } } } else { Parameters = null; } }
public void CreateConstant() { Utilities.Reflection.Emit.Assembly Assembly = new Utilities.Reflection.Emit.Assembly("TestAssembly"); Utilities.Reflection.Emit.TypeBuilder TestType = Assembly.CreateType("TestType"); IMethodBuilder Method = TestType.CreateMethod("TestMethod"); VariableBase Local1 = Method.CreateLocal("Local1", typeof(int)); VariableBase Local2 = Method.CreateLocal("Local2", typeof(int)); Assert.NotNull(Method.CreateConstant(12)); }
/// <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) { ObjectCallingOn = objectCallingOn; ConstructorCalling = methodCalling; MethodCallingFrom = method; if (parameters != null) { Parameters = new VariableBase[parameters.Length]; for (int x = 0; x < parameters.Length; ++x) { if (parameters[x] is VariableBase) Parameters[x] = (VariableBase) parameters[x]; else Parameters[x] = MethodCallingFrom.CreateConstant(parameters[x]); } } else { Parameters = null; } }
/// <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) { Company.Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName); Company.Utilities.Reflection.Emit.Commands.If If1 = Method.If((VariableBase)SessionField, Comparison.NotEqual, null); { Company.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"); Company.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(); Company.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> /// 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> /// Sets up a property (non IEnumerable) /// </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 SetupSingleProperty(IMethodBuilder Method, Type BaseType, Reflection.Emit.BaseClasses.VariableBase ReturnValue, IProperty Property, IMapping Mapping) { Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName); Utilities.Reflection.Emit.FieldBuilder FieldLoaded = Fields.Find(x => x.Name == Property.DerivedFieldName + "_Loaded"); 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); { Utilities.Reflection.Emit.Commands.If If3 = Method.If(FieldLoaded, Comparison.Equal, Method.CreateConstant(false)); { //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 LoadPropertyMethod = typeof(Session).GetMethod("LoadProperty"); LoadPropertyMethod = LoadPropertyMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType }); VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertyMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") }); Field.Assign(ReturnVal); FieldLoaded.Assign(true); } If3.EndIf(); } If2.EndIf(); } If1.EndIf(); ReturnValue.Assign(Field); }
/// <summary> /// Sets up a property (non IEnumerable) /// </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 SetupSingleProperty(IMethodBuilder Method, Type BaseType, Reflection.Emit.BaseClasses.VariableBase ReturnValue, IProperty Property, IMapping Mapping) { Utilities.Reflection.Emit.FieldBuilder Field = Fields.Find(x => x.Name == Property.DerivedFieldName); Utilities.Reflection.Emit.FieldBuilder FieldLoaded = Fields.Find(x => x.Name == Property.DerivedFieldName + "_Loaded"); 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); { Utilities.Reflection.Emit.Commands.If If3 = Method.If(FieldLoaded, Comparison.Equal, Method.CreateConstant(false)); { //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 LoadPropertyMethod = typeof(Session).GetMethod("LoadProperty"); LoadPropertyMethod = LoadPropertyMethod.MakeGenericMethod(new Type[] { BaseType, Field.DataType }); VariableBase ReturnVal = ((VariableBase)SessionField).Call(LoadPropertyMethod, new object[] { Method.This, Property.Name, PropertyList.Call("ToArray") }); Field.Assign(ReturnVal); FieldLoaded.Assign(true); } If3.EndIf(); } If2.EndIf(); } If1.EndIf(); ReturnValue.Assign(Field); }