using System.Collections;
using System.Security;
using System.Security.Permissions;
+using System.Diagnostics.SymbolStore;
namespace System.Reflection.Emit {
-
- public sealed class TypeBuilder : Type {
+#if NET_2_0
+ [ComVisible (true)]
+ [ComDefaultInterface (typeof (_TypeBuilder))]
+#endif
+ [ClassInterface (ClassInterfaceType.None)]
+ public sealed class TypeBuilder : Type, _TypeBuilder {
#region Sync with reflection.h
private string tname;
private string nspace;
[MonoTODO]
public override Type UnderlyingSystemType {
get {
- // This should return the type itself for non-enum types but
- // that breaks mcs.
+
+ // Return this as requested by Zoltan.
+
+ return this;
+
+#if false
+ // Dont know what to do with the rest, should be killed:
+ // See bug: 75008.
+ //
+ ////// This should return the type itself for non-enum types but
+ ////// that breaks mcs.
if (fields != null) {
foreach (FieldBuilder f in fields) {
if ((f != null) && (f.Attributes & FieldAttributes.Static) == 0)
}
}
throw new InvalidOperationException ("Underlying type information on enumeration is not specified.");
+#endif
}
}
attrs |= TypeAttributes.HasSecurity;
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public void AddInterfaceImplementation( Type interfaceType) {
if (interfaceType == null)
throw new ArgumentNullException ("interfaceType");
CallingConventions callConvention, Type[] types,
ParameterModifier[] modifiers)
{
+ check_created ();
+
if (ctors == null)
return null;
return res;
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent, Type[] interfaces) {
return DefineNestedType (name, attr, parent, interfaces, PackingSize.Unspecified, UnspecifiedTypeSize);
}
return DefineNestedType (name, attr, parent, null, packsize, UnspecifiedTypeSize);
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public ConstructorBuilder DefineConstructor (MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
return DefineConstructor (attributes, callingConvention, parameterTypes, null, null);
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
#if NET_2_0 || BOOTSTRAP_NET_2_0
public
#else
return cb;
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public ConstructorBuilder DefineDefaultConstructor (MethodAttributes attributes)
{
Type parent_type;
return cb;
}
- public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
- return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
- }
-
private void append_method (MethodBuilder mb) {
if (methods != null) {
if (methods.Length == num_methods) {
num_methods ++;
}
+ public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
+ return DefineMethod (name, attributes, CallingConventions.Standard, returnType, parameterTypes);
+ }
+
public MethodBuilder DefineMethod( string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
return DefineMethod (name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
}
nativeCallConv, nativeCharSet);
}
+#if NET_2_0
+ public MethodBuilder DefineMethod (string name, MethodAttributes attributes) {
+ return DefineMethod (name, attributes, CallingConventions.Standard);
+ }
+
+ public MethodBuilder DefineMethod (string name, MethodAttributes attributes, CallingConventions callConv) {
+ return DefineMethod (name, attributes, callConv, null, null);
+ }
+#endif
+
public void DefineMethodOverride( MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) {
if (methodInfoBody == null)
throw new ArgumentNullException ("methodInfoBody");
}
public PropertyBuilder DefineProperty( string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes) {
+ return DefineProperty (name, attributes, returnType, null, null, parameterTypes, null, null);
+ }
+
+#if NET_2_0
+ public
+#else
+ internal
+#endif
+ PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers) {
check_name ("name", name);
if (parameterTypes != null)
foreach (Type param in parameterTypes)
throw new ArgumentNullException ("parameterTypes");
check_not_created ();
- PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, parameterTypes);
+ PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
if (properties != null) {
PropertyBuilder[] new_properties = new PropertyBuilder [properties.Length+1];
return res;
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public ConstructorBuilder DefineTypeInitializer() {
return DefineConstructor (MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, null);
}
public Type CreateType() {
/* handle nesting_type */
- check_not_created ();
+ if (created != null)
+ return created;
+
+ create_generic_class ();
// Fire TypeResolve events for fields whose type is an unfinished
// value type.
foreach (ConstructorBuilder ctor in ctors)
ctor.fixup ();
}
-
+
created = create_runtime_class (this);
if (created != null)
return created;
return this;
}
+ internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
+ {
+ symbolWriter.OpenNamespace (this.Namespace);
+
+ if (methods != null) {
+ for (int i = 0; i < num_methods; ++i) {
+ MethodBuilder metb = (MethodBuilder) methods[i];
+ metb.GenerateDebugInfo (symbolWriter);
+ }
+ }
+
+ if (ctors != null) {
+ foreach (ConstructorBuilder ctor in ctors)
+ ctor.GenerateDebugInfo (symbolWriter);
+ }
+
+ symbolWriter.CloseNamespace ();
+ }
+
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
{
if (ctors == null)
int nnamed = (int)data [pos++];
nnamed |= ((int)data [pos++]) << 8;
for (int i = 0; i < nnamed; ++i) {
- byte named_type = data [pos++];
+ //byte named_type = data [pos++];
+ pos ++;
byte type = data [pos++];
int len;
string named_name;
if (type == 0x55) {
len = CustomAttributeBuilder.decode_len (data, pos, out pos);
- string named_typename = CustomAttributeBuilder.string_from_bytes (data, pos, len);
+ //string named_typename =
+ CustomAttributeBuilder.string_from_bytes (data, pos, len);
pos += len;
// FIXME: Check that 'named_type' and 'named_typename' match, etc.
// See related code/FIXME in mono/mono/metadata/reflection.c
switch ((CharSet)value) {
case CharSet.None:
case CharSet.Ansi:
+ attrs &= ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass);
break;
case CharSet.Unicode:
+ attrs &= ~TypeAttributes.AutoClass;
attrs |= TypeAttributes.UnicodeClass;
break;
case CharSet.Auto:
+ attrs &= ~TypeAttributes.UnicodeClass;
attrs |= TypeAttributes.AutoClass;
break;
default:
cattrs [0] = customBuilder;
}
}
+
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
}
return pmodule.get_next_table_index (obj, table, inc);
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
public override InterfaceMapping GetInterfaceMap (Type interfaceType)
{
if (created == null)
{
if (name == null)
throw new ArgumentNullException (argName);
- if (name == "")
- throw new ArgumentException (argName, "Empty name is not legal.");
+ if (name.Length == 0)
+ throw new ArgumentException ("Empty name is not legal", argName);
if (name.IndexOf ((char)0) != -1)
- throw new ArgumentException (argName, "Illegal name.");
+ throw new ArgumentException ("Illegal name", argName);
}
public override String ToString ()
return base.IsAssignableFrom (c);
}
+#if NET_2_0
+ [ComVisible (true)]
+#endif
[MonoTODO]
public override bool IsSubclassOf (Type c)
{
return base.IsSubclassOf (c);
}
+ [MonoTODO ("arrays")]
+ internal bool IsAssignableTo (Type c)
+ {
+ if (c == this)
+ return true;
+
+ if (c.IsInterface) {
+ if (interfaces == null)
+ return false;
+ foreach (Type t in interfaces)
+ if (c.IsAssignableFrom (t))
+ return true;
+ return false;
+ }
+
+ if (parent == null)
+ return c == typeof (object);
+ else
+ return c.IsAssignableFrom (parent);
+ }
+
#if NET_2_0 || BOOTSTRAP_NET_2_0
public bool IsCreated () {
return is_created;
return base.GetGenericTypeDefinition ();
}
- public override bool HasGenericArguments {
- get {
- throw new NotImplementedException ();
- }
- }
-
public override bool ContainsGenericParameters {
get {
return generic_params != null;
}
}
- public GenericTypeParameterBuilder[] DefineGenericParameters (string[] names)
+ public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
{
setup_generic_class ();
{
return DefineMethod (name, attributes, CallingConventions.Standard, null, null);
}
+
+ public static ConstructorInfo GetConstructor (Type instanciated, ConstructorInfo ctor)
+ {
+ ConstructorInfo res = instanciated.GetConstructor (ctor);
+ if (res == null)
+ throw new System.Exception ("constructor not found");
+ else
+ return res;
+ }
+
+ public static MethodInfo GetMethod (Type instanciated, MethodInfo meth)
+ {
+ MethodInfo res = instanciated.GetMethod (meth);
+ if (res == null)
+ throw new System.Exception ("method not found");
+ else
+ return res;
+ }
+
+ public static FieldInfo GetField (Type instanciated, FieldInfo fld)
+ {
+ FieldInfo res = instanciated.GetField (fld);
+ if (res == null)
+ throw new System.Exception ("field not found");
+ else
+ return res;
+ }
#endif
+
+ void _TypeBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
+ {
+ throw new NotImplementedException ();
+ }
+
+ void _TypeBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
+ {
+ throw new NotImplementedException ();
+ }
+
+ void _TypeBuilder.GetTypeInfoCount (out uint pcTInfo)
+ {
+ throw new NotImplementedException ();
+ }
+
+ void _TypeBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
+ {
+ throw new NotImplementedException ();
+ }
}
}