// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#if !FULL_AOT_RUNTIME
using System;
using System.Text;
using System.Reflection;
[ComVisible (true)]
[ComDefaultInterface (typeof (_TypeBuilder))]
[ClassInterface (ClassInterfaceType.None)]
+ [StructLayout (LayoutKind.Sequential)]
public sealed class TypeBuilder : Type, _TypeBuilder
{
#pragma warning disable 169
}
pmodule = mb;
- if (((attr & TypeAttributes.Interface) == 0) && (parent == null) && !IsCompilerContext)
+ if (((attr & TypeAttributes.Interface) == 0) && (parent == null))
this.parent = typeof (object);
// skip .<Module> ?
if (is_created)
return created.UnderlyingSystemType;
- if (!IsCompilerContext && IsEnum) {
+ if (IsEnum) {
if (underlying_type != null)
return underlying_type;
throw new InvalidOperationException (
public override bool IsDefined (Type attributeType, bool inherit)
{
- if (!is_created && !IsCompilerContext)
+ if (!is_created)
throw new NotSupportedException ();
/*
* MS throws NotSupported here, but we can't because some corlib
[ComVisible (true)]
public ConstructorBuilder DefineDefaultConstructor (MethodAttributes attributes)
{
- Type parent_type;
+ Type parent_type, old_parent_type;
if (parent != null)
parent_type = parent;
else
parent_type = pmodule.assemblyb.corlib_object_type;
+ old_parent_type = parent_type;
parent_type = parent_type.InternalResolve ();
+ /*This avoids corlib to have self references.*/
+ if (parent_type == typeof (object) || parent_type == typeof (ValueType))
+ parent_type = old_parent_type;
+
ConstructorInfo parent_constructor =
parent_type.GetConstructor (
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
create_internal_class (this);
}
- if (IsEnum && !IsCompilerContext) {
+ if (IsEnum) {
if (underlying_type == null && (attributes & FieldAttributes.Static) == 0)
underlying_type = type;
}
public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)
{
- return DefineProperty (name, attributes, returnType, null, null, parameterTypes, null, null);
+ return DefineProperty (name, attributes, 0, returnType, null, null, parameterTypes, null, null);
}
+
+#if NET_4_0
+ public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
+ {
+ return DefineProperty (name, attributes, callingConvention, returnType , null, null, parameterTypes, null, null);
+ }
+#endif
- public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
+ public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
+ {
+ return DefineProperty (name, attributes, 0, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
+ }
+
+ public PropertyBuilder DefineProperty (string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
{
check_name ("name", name);
if (parameterTypes != null)
throw new ArgumentNullException ("parameterTypes");
check_not_created ();
- PropertyBuilder res = new PropertyBuilder (this, name, attributes, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
+ PropertyBuilder res = new PropertyBuilder (this, name, attributes, callingConvention, returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
if (properties != null) {
- PropertyBuilder[] new_properties = new PropertyBuilder [properties.Length+1];
- System.Array.Copy (properties, new_properties, properties.Length);
- new_properties [properties.Length] = res;
- properties = new_properties;
+ Array.Resize (ref properties, properties.Length + 1);
+ properties [properties.Length - 1] = res;
} else {
- properties = new PropertyBuilder [1];
- properties [0] = res;
+ properties = new PropertyBuilder [1] { res };
}
return res;
}
if (is_created)
return created.GetConstructors (bindingAttr);
- if (!IsCompilerContext)
- throw new NotSupportedException ();
-
- return GetConstructorsInternal (bindingAttr);
+ throw new NotSupportedException ();
}
internal ConstructorInfo[] GetConstructorsInternal (BindingFlags bindingAttr)
{
if (is_created)
return created.GetEvents (bindingAttr);
- if (!IsCompilerContext)
- throw new NotSupportedException ();
- return new EventInfo [0]; /*FIXME shouldn't we return the events here?*/
+ throw new NotSupportedException ();
}
// This is only used from MonoGenericInst.initialize().
public override Type[] GetNestedTypes (BindingFlags bindingAttr)
{
- if (!is_created && !IsCompilerContext)
+ if (!is_created)
throw new NotSupportedException ();
bool match;
}
}
- //
- // Used internally by mcs only
- //
- internal void SetCharSet (TypeAttributes ta)
- {
- this.attrs = ta;
- }
-
public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
{
if (customBuilder == null)
// we should ignore it since it can be any value anyway...
throw new Exception ("Error in customattr");
}
- string first_type_name = customBuilder.Ctor.GetParameters()[0].ParameterType.FullName;
+
+ var ctor_type = customBuilder.Ctor is ConstructorBuilder ? ((ConstructorBuilder)customBuilder.Ctor).parameters[0] : customBuilder.Ctor.GetParameters()[0].ParameterType;
int pos = 6;
- if (first_type_name == "System.Int16")
+ if (ctor_type.FullName == "System.Int16")
pos = 4;
int nnamed = (int)data [pos++];
nnamed |= ((int)data [pos++]) << 8;
return created.GetInterfaceMap (interfaceType);
}
- internal override bool IsCompilerContext {
- get {
- return pmodule.assemblyb.IsCompilerContext;
- }
- }
-
internal override Type InternalResolve ()
{
check_created ();
if (constructor == null)
throw new NullReferenceException (); //MS raises this instead of an ArgumentNullException
+ if (!constructor.DeclaringType.IsGenericTypeDefinition)
+ throw new ArgumentException ("constructor declaring type is not a generic type definition", "constructor");
+ if (constructor.DeclaringType != type.GetGenericTypeDefinition ())
+ throw new ArgumentException ("constructor declaring type is not the generic type definition of type", "constructor");
+
ConstructorInfo res = type.GetConstructor (constructor);
if (res == null)
throw new ArgumentException ("constructor not found");
if (field is FieldOnTypeBuilderInst)
throw new ArgumentException ("The specified field must be declared on a generic type definition.", "field");
+ if (field.DeclaringType != type.GetGenericTypeDefinition ())
+ throw new ArgumentException ("field declaring type is not the generic type definition of type", "method");
+
FieldInfo res = type.GetField (field);
if (res == null)
throw new System.Exception ("field not found");
return res;
}
+ internal TypeCode GetTypeCodeInternal () {
+ if (parent == pmodule.assemblyb.corlib_enum_type) {
+ for (int i = 0; i < num_fields; ++i) {
+ FieldBuilder f = fields [i];
+ if (!f.IsStatic)
+ return Type.GetTypeCode (f.FieldType);
+ }
+ throw new InvalidOperationException ("Enum basetype field not defined");
+ } else {
+ return Type.GetTypeCodeInternal (this);
+ }
+ }
+
+
void _TypeBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException ();
{
throw new NotImplementedException ();
}
+
+ internal override bool IsUserType {
+ get {
+ return false;
+ }
+ }
}
}
+#endif