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); }
public override bool IsBlocked(MethodDesc method) { Debug.Assert(method.IsTypicalMethodDefinition); var ecmaMethod = method as EcmaMethod; if (ecmaMethod == null) { return(true); } ModuleBlockingMode moduleBlockingMode = _blockedModules.GetOrCreateValue(ecmaMethod.Module).BlockingMode; if (moduleBlockingMode == ModuleBlockingMode.None) { return(false); } else if (moduleBlockingMode == ModuleBlockingMode.FullyBlocked) { return(true); } // We are blocking internal implementation details Debug.Assert(moduleBlockingMode == ModuleBlockingMode.BlockedInternals); var owningType = (EcmaType)ecmaMethod.OwningType; if (_blockedTypes.GetOrCreateValue(owningType).IsBlocked) { return(true); } MethodAttributes accessibility = ecmaMethod.Attributes & MethodAttributes.Public; if (accessibility != MethodAttributes.Family && accessibility != MethodAttributes.FamORAssem && accessibility != MethodAttributes.Public) { return(true); } // Methods on Array`1<T> are implementation details that implement the generic interfaces on // arrays. They should not generate metadata or be reflection invokable. // We could get rid of this special casing two ways: // * Make these method stop being regular EcmaMethods with Array<T> as their owning type, or // * Make these methods implement the interfaces explicitly (they would become private and naturally blocked) if (ecmaMethod.OwningType == ArrayOfTType) { return(true); } return(false); }
public static Type BuildPropertyObject(System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, Type> > obj) { string nameOfDLL = "magic.dll"; string nameOfAssembly = "magic_Assembly"; string nameOfModule = "magic_Module"; string nameOfType = "magic_Type"; System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName { Name = nameOfAssembly }; System.Reflection.Emit.AssemblyBuilder assemblyBuilder = System.Threading.Thread.GetDomain().DefineDynamicAssembly(assemblyName, System.Reflection.Emit.AssemblyBuilderAccess.RunAndSave); System.Reflection.Emit.ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(nameOfModule, nameOfDLL); System.Reflection.Emit.TypeBuilder typeBuilder = moduleBuilder.DefineType(nameOfType, System.Reflection.TypeAttributes.Public | System.Reflection.TypeAttributes.Class); foreach (var prop in obj) { string Name = prop.Key; Type DataType = prop.Value; System.Reflection.Emit.FieldBuilder field = typeBuilder.DefineField("_" + Name, DataType, System.Reflection.FieldAttributes.Private); System.Reflection.Emit.PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(Name, System.Reflection.PropertyAttributes.SpecialName, DataType, null); System.Reflection.MethodAttributes methodAttributes = System.Reflection.MethodAttributes.Public | System.Reflection.MethodAttributes.HideBySig | System.Reflection.MethodAttributes.SpecialName; System.Reflection.Emit.MethodBuilder methodBuilderGetter = typeBuilder.DefineMethod("get_" + Name, methodAttributes, DataType, new Type[] { }); System.Reflection.Emit.MethodBuilder methodBuilderSetter = typeBuilder.DefineMethod("set_" + Name, methodAttributes, typeof(void), new Type[] { DataType }); System.Reflection.Emit.ILGenerator ilGeneratorGetter = methodBuilderGetter.GetILGenerator(); ilGeneratorGetter.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); ilGeneratorGetter.Emit(System.Reflection.Emit.OpCodes.Ldfld, field); ilGeneratorGetter.Emit(System.Reflection.Emit.OpCodes.Ret); System.Reflection.Emit.ILGenerator ilGeneratorSetter = methodBuilderSetter.GetILGenerator(); ilGeneratorSetter.Emit(System.Reflection.Emit.OpCodes.Ldarg_0); ilGeneratorSetter.Emit(System.Reflection.Emit.OpCodes.Ldarg_1); ilGeneratorSetter.Emit(System.Reflection.Emit.OpCodes.Stfld, field); ilGeneratorSetter.Emit(System.Reflection.Emit.OpCodes.Ret); propertyBuilder.SetGetMethod(methodBuilderGetter); propertyBuilder.SetSetMethod(methodBuilderSetter); } // Yes! you must do this, it should not be needed but it is! Type dynamicType = typeBuilder.CreateType(); // Save to file assemblyBuilder.Save(nameOfDLL); return(dynamicType); }
public virtual System.Reflection.MethodAttributes GetAttributes() { System.Reflection.MethodAttributes attributes = System.Reflection.MethodAttributes.Public; if ((Modifiers & Modifiers.Private) == Modifiers.Private) { attributes = System.Reflection.MethodAttributes.Private; } if ((Modifiers & Modifiers.Static) == Modifiers.Static) { attributes |= System.Reflection.MethodAttributes.Static; } if ((Modifiers & Modifiers.Implement) == Modifiers.Implement) { attributes |= System.Reflection.MethodAttributes.Virtual | System.Reflection.MethodAttributes.HideBySig; } if ((Modifiers & Modifiers.Abstract) == Modifiers.Abstract) { attributes |= System.Reflection.MethodAttributes.Abstract; } return(attributes); }
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); }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[] parameterTypes) { return(default(System.Reflection.Emit.ConstructorBuilder)); }
public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes) { return(default(System.Reflection.Emit.ConstructorBuilder)); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] returnTypeRequiredCustomModifiers, System.Type[] returnTypeOptionalCustomModifiers, System.Type[] parameterTypes, System.Type[][] parameterTypeRequiredCustomModifiers, System.Type[][] parameterTypeOptionalCustomModifiers) { throw null; }
/// <summary> /// Is the given java class name + method name + method descriptor a virtual method? /// </summary> public bool IsImportedVirtualMethod(IClassLoader classLoader, Action<ClassFile> classLoaded, string name, string descriptor, out MethodAttributes methodAttributes, out string netName, out string baseDescriptor, out string baseSignature) { var cf = Resolve(classLoader, classLoaded, null); descriptor = Descriptors.StripMethodReturnType(descriptor); foreach (var importMethod in dexMethods) { var method = importMethod.Resolve(cf); if ((method.Name == name) && (Descriptors.StripMethodReturnType(method.Descriptor) == descriptor)) { methodAttributes = (MethodAttributes)importMethod.Method.Attributes; netName = importMethod.Method.Name; baseDescriptor = method.Descriptor; baseSignature = (method.Signature != null) ? method.Signature.Original : null; if (baseSignature == baseDescriptor) baseSignature = null; return true; } } methodAttributes = 0; netName = null; baseDescriptor = null; baseSignature = null; return false; }
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes) { throw null; }
public MethodBuilder DefinePInvokeMethod(string name, string dllName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { return(default(MethodBuilder)); }
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] returnTypeRequiredCustomModifiers, System.Type[] returnTypeOptionalCustomModifiers, System.Type[] parameterTypes, System.Type[][] parameterTypeRequiredCustomModifiers, System.Type[][] parameterTypeOptionalCustomModifiers, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw new PlatformNotSupportedException(); }
static public bool HasAttribute(System.Reflection.MethodAttributes ma, System.Reflection.MethodInfo m) { int a = (int)m.Attributes, b = (int)ma; return((a & b) == b); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention) { throw new PlatformNotSupportedException(); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Type returnType, System.Type[] parameterTypes) { throw new PlatformNotSupportedException(); }
public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes) { throw new PlatformNotSupportedException(); }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[] parameterTypes) { throw new PlatformNotSupportedException(); }
public MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { return(default(MethodBuilder)); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention) { return(default(System.Reflection.Emit.MethodBuilder)); }
public DynamicMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Type owner, bool skipVisibility) { }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Type returnType, System.Type[] parameterTypes) { return(default(System.Reflection.Emit.MethodBuilder)); }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[] parameterTypes, System.Type[][] requiredCustomModifiers, System.Type[][] optionalCustomModifiers) { throw null; }
static public string HasAttribute(System.Reflection.MethodAttributes ma, System.Reflection.MethodInfo m, string input) { return((HasAttribute(ma, m)) ? input : string.Empty); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes) { throw null; }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[] parameterTypes) { throw null; }
public MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, Type returnType, Type[] parameterTypes) { }
public System.Reflection.Emit.ConstructorBuilder DefineDefaultConstructor(System.Reflection.MethodAttributes attributes) { throw null; }
/// <summary> /// Fills the row from the array of bytes. /// </summary> unsafe public void FromRawData(byte [] buff, int offs) { if (buff == null) throw new Exception("buff == null"); if (offs + Size > buff.Length) throw new Exception("bounds"); this.RVA = LEBitConverter.ToUInt32(buff, offs); offs += RVA.Size; this.ImplFlags = (System.Reflection.MethodImplAttributes) LEBitConverter.ToUInt16(buff, offs); offs += sizeof (ushort); this.Flags = (System.Reflection.MethodAttributes) LEBitConverter.ToUInt16(buff, offs); offs += sizeof (ushort); this.Name = LEBitConverter.ToInt32(buff, offs); offs += 4; this.Signature = LEBitConverter.ToInt32(buff, offs); offs += 4; this.ParamList = LEBitConverter.ToInt32(buff, offs); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention) { throw null; }
public System.Reflection.Emit.MethodBuilder DefineGlobalMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] requiredReturnTypeCustomModifiers, System.Type[] optionalReturnTypeCustomModifiers, System.Type[] parameterTypes, System.Type[][] requiredParameterTypeCustomModifiers, System.Type[][] optionalParameterTypeCustomModifiers) { return(default(System.Reflection.Emit.MethodBuilder)); }
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Type returnType, System.Type[] parameterTypes) { throw null; }
public System.Reflection.Emit.MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type returnType, System.Type[] parameterTypes, System.Runtime.InteropServices.CallingConvention nativeCallConv, System.Runtime.InteropServices.CharSet nativeCharSet) { throw null; }