private void CreateProperty(Generators.TypeGenerator generator, System.Type returnType, ParameterInfo[] parameters) { var parameterTypes = parameters.Map(p => p.Type); Generators.PropertyGenerator.PropertyHolder accessor = null; System.Type type = null; var name = string.Concat(char.ToUpper(Name.First()), Name.Substring(1)); var builder = generator.Builder; System.Reflection.MethodAttributes attributes = GetAttributes(); if (IsGetter) { type = returnType; string hiddenName = string.Concat("get_", name); if ((attributes & System.Reflection.MethodAttributes.Virtual) == System.Reflection.MethodAttributes.Virtual) { generator.CheckImplementMethod(Name, parameterTypes, ref hiddenName, ref returnType, ref attributes); } System.Reflection.Emit.MethodBuilder getBul = builder.DefineMethod(hiddenName, attributes, returnType, parameterTypes); accessor = new Generators.PropertyGenerator.PropertyHolder(Generators.PropertyType.Get, new Generators.MethodGenerator(getBul, parameters, generator) { SyntaxBody = Body }); } if (IsSetter) { type = parameterTypes.FirstOrDefault(); accessor = new Generators.PropertyGenerator.PropertyHolder(Generators.PropertyType.Set, new Generators.MethodGenerator(builder.DefineMethod(string.Concat("set_", name), attributes, returnType, parameterTypes), parameters, generator) { SyntaxBody = Body }); } if (generator.TryGetProperty(Name, out Generators.PropertyGenerator property) == false) { var pb = generator.Builder.DefineProperty(name, System.Reflection.PropertyAttributes.None, type, null); property = new Generators.PropertyGenerator(generator, pb); property.SetCustomAttribute(typeof(Runtime.RegisterAttribute), Utils.ReflectionHelpers.Register_Attr_Ctor, new[] { Name }); generator.Add(property); } System.Reflection.Emit.PropertyBuilder propertyBuilder = property.GetBuilder(); if (IsGetter) { propertyBuilder.SetGetMethod(accessor.Method.GetBuilder()); } else if (IsSetter) { propertyBuilder.SetSetMethod(accessor.Method.GetBuilder()); } else { throw new System.Exception("Accessor not found"); } property.Accessors.Add(accessor); }
private void CreateFunction(Generators.TypeGenerator generator, System.Type returnType, ParameterInfo[] parameters) { var parameterTypes = parameters.Map(p => p.Type); //todo override toString and others var name = string.Concat(char.ToUpper(Name.First()), Name.Substring(1)); System.Reflection.MethodAttributes attributes = GetAttributes(); if ((attributes & System.Reflection.MethodAttributes.Virtual) == System.Reflection.MethodAttributes.Virtual) { generator.CheckImplementMethod(Name, parameterTypes, ref name, ref returnType, ref attributes); } // create method var method = generator.Builder.DefineMethod(name, attributes, returnType, parameterTypes); //set runtime method name Generators.MethodGenerator methodGen = new Generators.MethodGenerator(method, parameters, generator) { SyntaxBody = Body }; methodGen.SetCustomAttribute(typeof(Runtime.RegisterAttribute), Utils.ReflectionHelpers.Register_Attr_Ctor, new object[] { Name }); generator.Add(methodGen); }