//
// Dual licensed under the terms of the MIT X11 or GNU GPL
//
-// Copyright 2009, 2010 Novell, Inc
+// Copyright 2009-2011 Novell, Inc
+// Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
//
using System;
}
if (cad.Count > 0) {
- string ns, name;
foreach (var ca in cad) {
- importer.GetCustomAttributeTypeName (ca, out ns, out name);
- if (name != "DynamicAttribute" && ns != CompilerServicesNamespace)
+ var dt = ca.Constructor.DeclaringType;
+ if (dt.Name != "DynamicAttribute" && dt.Namespace != CompilerServicesNamespace)
continue;
if (ca.ConstructorArguments.Count == 0) {
public abstract void AddCompiledType (TypeBuilder builder, TypeSpec spec);
protected abstract MemberKind DetermineKindFromBaseType (MetaType baseType);
protected abstract bool HasVolatileModifier (MetaType[] modifiers);
- public abstract void GetCustomAttributeTypeName (CustomAttributeData cad, out string typeNamespace, out string typeName);
public FieldSpec CreateField (FieldInfo fi, TypeSpec declaringType)
{
break;
default:
// Ignore private fields (even for error reporting) to not require extra dependencies
- if (IgnorePrivateMembers || HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
+ if ((IgnorePrivateMembers && !declaringType.IsStruct) ||
+ HasAttribute (CustomAttributeData.GetCustomAttributes (fi), "CompilerGeneratedAttribute", CompilerServicesNamespace))
return null;
mod = Modifiers.PRIVATE;
if (!is_params && p.IsOptional) {
object value = p.RawDefaultValue;
var ptype = types[i];
- if ((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter && (value != null || TypeManager.IsReferenceType (ptype))) {
+ if ((p.Attributes & ParameterAttributes.HasDefault) != 0 && ptype.Kind != MemberKind.TypeParameter && (value != null || TypeSpec.IsReferenceType (ptype))) {
if (value == null) {
default_value = Constant.CreateConstant (ptype, null, Location.Null);
} else {
spec = new PropertySpec (MemberKind.Property, declaringType, new ImportedMemberDefinition (pi, type, this), type, pi, mod);
if (!is_valid_property) {
- spec.IsNotRealProperty = true;
+ spec.IsNotCSharpCompatible = true;
return spec;
}
if (!assembly_2_definition.TryGetValue (assembly, out found)) {
// This can happen in dynamic context only
- var def = new ImportedAssemblyDefinition (assembly, this);
+ var def = new ImportedAssemblyDefinition (assembly);
assembly_2_definition.Add (assembly, def);
def.ReadAttributes ();
found = def;
if (attributesData.Count == 0)
return false;
- string ns, name;
foreach (var attr in attributesData) {
- GetCustomAttributeTypeName (attr, out ns, out name);
- if (name == attrName && ns == attrNamespace)
+ var dt = attr.Constructor.DeclaringType;
+ if (dt.Name == attrName && dt.Namespace == attrNamespace)
return true;
}
if (spec.BaseType != null) {
var bifaces = spec.BaseType.Interfaces;
if (bifaces != null) {
+ //
+ // Before adding base class interfaces close defined interfaces
+ // on type parameter
+ //
+ var tp = spec as TypeParameterSpec;
+ if (tp != null && tp.InterfacesDefined == null) {
+ tp.InterfacesDefined = TypeSpec.EmptyTypes;
+ }
+
foreach (var iface in bifaces)
spec.AddInterface (iface);
}
if (attrs.Count == 0)
return null;
- string name, ns;
foreach (var ca in attrs) {
- GetCustomAttributeTypeName (ca, out ns, out name);
- if (name != "DecimalConstantAttribute" || ns != CompilerServicesNamespace)
+ var dt = ca.Constructor.DeclaringType;
+ if (dt.Name != "DecimalConstantAttribute" || dt.Namespace != CompilerServicesNamespace)
continue;
var value = new decimal (
// It should not throw any loading exception
IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (mi);
- string ns, name;
foreach (var a in attrs) {
- importer.GetCustomAttributeTypeName (a, out ns, out name);
+ var dt = a.Constructor.DeclaringType;
+ string name = dt.Name;
if (name == "ObsoleteAttribute") {
- if (ns != "System")
+ if (dt.Namespace != "System")
continue;
if (bag == null)
}
if (name == "ConditionalAttribute") {
- if (ns != "System.Diagnostics")
+ if (dt.Namespace != "System.Diagnostics")
continue;
if (bag == null)
}
if (name == "CLSCompliantAttribute") {
- if (ns != "System")
+ if (dt.Namespace != "System")
continue;
if (bag == null)
// Type only attributes
if (mi.MemberType == MemberTypes.TypeInfo || mi.MemberType == MemberTypes.NestedType) {
if (name == "DefaultMemberAttribute") {
- if (ns != "System.Reflection")
+ if (dt.Namespace != "System.Reflection")
continue;
if (bag == null)
}
if (name == "AttributeUsageAttribute") {
- if (ns != "System")
+ if (dt.Namespace != "System")
continue;
if (bag == null)
// Interface only attribute
if (name == "CoClassAttribute") {
- if (ns != "System.Runtime.InteropServices")
+ if (dt.Namespace != "System.Runtime.InteropServices")
continue;
if (bag == null)
{
readonly Module module;
bool cls_compliant;
- readonly MetadataImporter importer;
- public ImportedModuleDefinition (Module module, MetadataImporter importer)
+ public ImportedModuleDefinition (Module module)
{
this.module = module;
- this.importer = importer;
}
#region Properties
{
IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (module);
- string ns, name;
foreach (var a in attrs) {
- importer.GetCustomAttributeTypeName (a, out ns, out name);
- if (name == "CLSCompliantAttribute") {
- if (ns != "System")
+ var dt = a.Constructor.DeclaringType;
+ if (dt.Name == "CLSCompliantAttribute") {
+ if (dt.Namespace != "System")
continue;
cls_compliant = (bool) a.ConstructorArguments[0].Value;
{
readonly Assembly assembly;
readonly AssemblyName aname;
- readonly MetadataImporter importer;
bool cls_compliant;
bool contains_extension_methods;
List<AssemblyName> internals_visible_to;
Dictionary<IAssemblyDefinition, AssemblyName> internals_visible_to_cache;
- public ImportedAssemblyDefinition (Assembly assembly, MetadataImporter importer)
+ public ImportedAssemblyDefinition (Assembly assembly)
{
this.assembly = assembly;
this.aname = assembly.GetName ();
- this.importer = importer;
}
#region Properties
IList<CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes (assembly);
- string ns, name;
foreach (var a in attrs) {
- importer.GetCustomAttributeTypeName (a, out ns, out name);
-
+ var dt = a.Constructor.DeclaringType;
+ var name = dt.Name;
if (name == "CLSCompliantAttribute") {
- if (ns == "System") {
- try {
- cls_compliant = (bool) a.ConstructorArguments[0].Value;
- } catch {
- }
+ if (dt.Namespace == "System") {
+ cls_compliant = (bool) a.ConstructorArguments[0].Value;
}
continue;
}
if (name == "InternalsVisibleToAttribute") {
- if (ns != MetadataImporter.CompilerServicesNamespace)
+ if (dt.Namespace != MetadataImporter.CompilerServicesNamespace)
continue;
- string s;
- try {
- s = a.ConstructorArguments[0].Value as string;
- } catch {
- s = null;
- }
-
+ string s = a.ConstructorArguments[0].Value as string;
if (s == null)
continue;
}
if (name == "ExtensionAttribute") {
- if (ns == MetadataImporter.CompilerServicesNamespace)
+ if (dt.Namespace == MetadataImporter.CompilerServicesNamespace)
contains_extension_methods = true;
continue;
if ((t.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate && importer.IgnorePrivateMembers)
continue;
- imported = importer.CreateNestedType (t, declaringType);
+ try {
+ imported = importer.CreateNestedType (t, declaringType);
+ } catch (Exception e) {
+ throw new InternalErrorException (e, "Could not import nested type `{0}' from `{1}'",
+ t.FullName, declaringType.MemberDefinition.DeclaringAssembly.FullName);
+ }
+
cache.AddMemberImported (imported);
}
}
}
+ //
+ // Load base interfaces first to minic behaviour of compiled members
+ //
+ if (declaringType.IsInterface && declaringType.Interfaces != null) {
+ foreach (var iface in declaringType.Interfaces) {
+ cache.AddInterface (iface);
+ }
+ }
+
if (!onlyTypes) {
//
// The logic here requires methods to be returned first which seems to work for both Mono and .NET
cache.AddMemberImported (imported);
}
}
-
- if (declaringType.IsInterface && declaringType.Interfaces != null) {
- foreach (var iface in declaringType.Interfaces) {
- cache.AddInterface (iface);
- }
- }
}
}