- int n = 0;
-
- if (!members_defined){
- if (DefineMembers (container))
- n = method_builders.Count;
- } else
- n = method_builders.Count;
-
- MethodInfo [] mi = new MethodInfo [n];
-
- method_builders.CopyTo (mi, 0);
-
- return mi;
- }
-
- // Hack around System.Reflection as found everywhere else
- public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
- MemberFilter filter, object criteria)
- {
- ArrayList members = new ArrayList ();
-
- if ((mt & MemberTypes.Method) != 0) {
- foreach (MethodBuilder mb in method_builders)
- if (filter (mb, criteria))
- members.Add (mb);
- }
-
- if ((mt & MemberTypes.Property) != 0) {
- foreach (PropertyBuilder pb in property_builders)
- if (filter (pb, criteria))
- members.Add (pb);
- }
-
- if ((mt & MemberTypes.Event) != 0) {
- foreach (MyEventBuilder eb in event_builders)
- if (filter (eb, criteria))
- members.Add (eb);
- }
-
- if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
- MemberList parent_mi;
-
- parent_mi = TypeContainer.FindMembers (
- TypeBuilder.BaseType, mt, bf, filter, criteria);
-
- members.AddRange (parent_mi);
- }
-
- return new MemberList (members);
- }
-
- public override MemberCache MemberCache {
- get {
- return member_cache;
- }
- }
-
- //
- // Populates the methods in the interface
- //
- void PopulateMethod (TypeContainer parent, DeclSpace decl_space, InterfaceMethod im)
- {
- Type return_type = this.ResolveType (im.ReturnType, false, im.Location);
- Type [] arg_types = im.ParameterTypes (this);
- MethodBuilder mb;
- Parameter [] p;
- int i;
-
- if (return_type == null)
- return;
-
- if (return_type.IsPointer && !UnsafeOK (this))
- return;
-
- if (arg_types == null)
- return;
-
- foreach (Type t in arg_types){
-
- if (t == null)
- return;
-
- if (t.IsPointer && !UnsafeOK (this))
- return;
- }
-
- //
- // Create the method
- //
- mb = TypeBuilder.DefineMethod (
- im.Name, interface_method_attributes,
- return_type, arg_types);
-
- InternalParameters ip = new InternalParameters (arg_types, im.Parameters);
-
- if (!RegisterMethod (mb, ip, arg_types)) {
- Error111 (im);
- return;
- }
-
- //
- // Define each type attribute (in/out/ref) and
- // the argument names.
- //
- p = im.Parameters.FixedParameters;
- if (p != null){
- for (i = 0; i < p.Length; i++)
- mb.DefineParameter (i + 1, p [i].Attributes, p [i].Name);
-
- if (i != arg_types.Length)
- Console.WriteLine ("Implement the type definition for params");
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- return_type, ModFlags, false);
-
- if (im.OptAttributes != null)
- Attribute.ApplyAttributes (ec, mb, im, im.OptAttributes, Location);
- }
-
- //
- // Populates the properties in the interface
- //
- void PopulateProperty (TypeContainer parent, DeclSpace decl_space, InterfaceProperty ip)
- {
- PropertyBuilder pb;
- MethodBuilder get = null, set = null;
- ip.Type = this.ResolveTypeExpr (ip.Type, false, ip.Location);
- Type prop_type = ip.Type.Type;
- Type [] setter_args = new Type [1];
-
- if (prop_type == null)
- return;
-
- if (prop_type.IsPointer && !UnsafeOK (this))
- return;
-
- setter_args [0] = prop_type;
-
- //
- // FIXME: properties are missing the following
- // flags: hidebysig newslot specialname
- //
- pb = TypeBuilder.DefineProperty (
- ip.Name, PropertyAttributes.None,
- prop_type, null);
-
- if (ip.HasGet){
- get = TypeBuilder.DefineMethod (
- "get_" + ip.Name, property_attributes ,
- prop_type, null);
-
- //
- // HACK because System.Reflection.Emit is lame
- //
- Type [] null_types = null;
- InternalParameters inp = new InternalParameters
- (null_types, Parameters.EmptyReadOnlyParameters);
-
- if (!RegisterMethod (get, inp, null)) {
- Error111 (ip);
- return;
- }
-
- pb.SetGetMethod (get);
- }
-
- if (ip.HasSet){
- setter_args [0] = prop_type;
-
- set = TypeBuilder.DefineMethod (
- "set_" + ip.Name, property_attributes,
- TypeManager.void_type, setter_args);
-
- set.DefineParameter (1, ParameterAttributes.None, "value");
- pb.SetSetMethod (set);
-
- //
- // HACK because System.Reflection.Emit is lame
- //
- Parameter [] parms = new Parameter [1];
- parms [0] = new Parameter (ip.Type, "value", Parameter.Modifier.NONE, null);
- InternalParameters ipp = new InternalParameters (
- this, new Parameters (parms, null, Location.Null));
-
- if (!RegisterMethod (set, ipp, setter_args)) {
- Error111 (ip);
- return;
- }
- }
-
- EmitContext ec = new EmitContext (parent, decl_space, Location, null,
- null, ModFlags, false);
-
- if (ip.OptAttributes != null)
- Attribute.ApplyAttributes (ec, pb, ip, ip.OptAttributes, Location);
-
- TypeManager.RegisterProperty (pb, get, set);
- property_builders.Add (pb);
- }
-
- //
- // Populates the events in the interface
- //
- void PopulateEvent (TypeContainer parent, DeclSpace decl_space, InterfaceEvent ie)
- {
- //
- // FIXME: We need to do this after delegates have been
- // declared or we declare them recursively.
- //
- MyEventBuilder eb;
- MethodBuilder add = null, remove = null;
- ie.Type = this.ResolveTypeExpr (ie.Type, false, ie.Location);
- Type event_type = ie.Type.Type;
-
- if (event_type == null)
- return;
-
- if (event_type.IsPointer && !UnsafeOK (this))
- return;
-
- Type [] parameters = new Type [1];
- parameters [0] = event_type;
-
- eb = new MyEventBuilder (TypeBuilder, ie.Name,
- EventAttributes.None, event_type);
-
- //
- // Now define the accessors
- //
- string add_name = "add_" + ie.Name;
-
- add = TypeBuilder.DefineMethod (
- add_name, property_attributes, null, parameters);
- add.DefineParameter (1, ParameterAttributes.None, "value");
- eb.SetAddOnMethod (add);