[ComVisible (true)]
[ComDefaultInterface (typeof (_EnumBuilder))]
[ClassInterface (ClassInterfaceType.None)]
- public sealed class EnumBuilder : Type, _EnumBuilder {
+ public sealed class EnumBuilder :
+#if NET_4_5
+ TypeInfo
+#else
+ Type
+#endif
+ , _EnumBuilder
+ {
private TypeBuilder _tb;
private FieldBuilder _underlyingField;
private Type _underlyingType;
return false;
}
}
+
+#if NET_4_5
+ public override bool IsConstructedGenericType {
+ get { return false; }
+ }
+
+ public override bool IsAssignableFrom (TypeInfo typeInfo)
+ {
+ return base.IsAssignableFrom (typeInfo);
+ }
+#endif
+
}
}
#endif
{
[ComVisible (true)]
[StructLayout (LayoutKind.Sequential)]
- public sealed class GenericTypeParameterBuilder : Type
+ public sealed class GenericTypeParameterBuilder :
+#if NET_4_5
+ TypeInfo
+#else
+ Type
+#endif
{
#region Sync with reflection.h
private TypeBuilder tbuilder;
[ComDefaultInterface (typeof (_TypeBuilder))]
[ClassInterface (ClassInterfaceType.None)]
[StructLayout (LayoutKind.Sequential)]
- public sealed class TypeBuilder : Type, _TypeBuilder
+ public sealed class TypeBuilder :
+#if NET_4_5
+ TypeInfo
+#else
+ Type
+#endif
+ , _TypeBuilder
{
#pragma warning disable 169
#region Sync with reflection.h
return false;
}
}
+
+#if NET_4_5
+ public override bool IsConstructedGenericType {
+ get { return false; }
+ }
+
+ public override bool IsAssignableFrom (TypeInfo typeInfo)
+ {
+ return base.IsAssignableFrom (typeInfo);
+ }
+#endif
}
}
#endif
// Authors:
// Marek Safar <marek.safar@gmail.com>
//
-// Copyright 2011 Xamarin Inc.
+// Copyright (C) 2013 Xamarin Inc (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
{
public static TypeInfo GetTypeInfo (this Type type)
{
- return new TypeDelegator (type);
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ // This is odd but that's what .net does
+ var reflectable = (IReflectableType) type;
+ return reflectable.GetTypeInfo ();
}
}
}
* depends on them.
*/
[StructLayout (LayoutKind.Sequential)]
- internal class MonoGenericClass : Type
+ sealed class MonoGenericClass :
+#if NET_4_5
+ TypeInfo
+#else
+ Type
+#endif
{
#region Keep in sync with object-internals.h
#pragma warning disable 649
}
}
+#if NET_4_5
+ public override bool IsConstructedGenericType {
+ get { return typeImpl.IsConstructedGenericType; }
+ }
+
+ public override bool IsAssignableFrom (TypeInfo typeInfo)
+ {
+ if (typeInfo == null)
+ throw new ArgumentNullException ("typeInfo");
+
+ return IsAssignableFrom (typeInfo.AsType ());
+ }
+#endif
+
}
}
return this;
}
- static readonly BindingFlags declaredFlags = BindingFlags.DeclaredOnly |
+ const BindingFlags declaredFlags = BindingFlags.DeclaredOnly |
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance;
public virtual IEnumerable<MemberInfo> DeclaredMembers {
get {
- var ret = new List<MemberInfo> ();
- ret.AddRange (DeclaredConstructors);
- ret.AddRange (DeclaredEvents);
- ret.AddRange (DeclaredFields);
- ret.AddRange (DeclaredMethods);
- ret.AddRange (DeclaredProperties);
- return ret.AsReadOnly ();
+ return GetMembers (declaredFlags);
}
}
public virtual Type[] GenericTypeParameters {
get {
if (!ContainsGenericParameters)
- return new Type [0];
+ return EmptyTypes;
+
return GetGenericArguments ();
}
}
- static bool list_contains (IEnumerable<Type> types, Type type)
- {
- foreach (var t in types) {
- if (t == type)
- return true;
- }
-
- return false;
- }
-
public virtual IEnumerable<Type> ImplementedInterfaces {
get {
- var all = GetInterfaces ();
- var baseIfaces = BaseType != null ? BaseType.GetInterfaces () : new Type [0];
- foreach (var iface in all)
- if (!list_contains (baseIfaces, iface))
- yield return iface;
+ return GetInterfaces ();
}
}
[Serializable]
[StructLayout (LayoutKind.Sequential)]
- sealed class MonoType : Type, ISerializable
+ sealed class MonoType :
+#if NET_4_5
+ TypeInfo
+#else
+ Type
+#endif
+ , ISerializable
{
[NonSerialized]
MonoTypeInfo type_info;
--- /dev/null
+//
+// IntrospectionExtensionsTest.cs:
+//
+// Authors:
+// Marek Safar (marek.safar@gmail.com)
+//
+// (C) 2013
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_4_5
+
+using System;
+using System.Reflection;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Reflection
+{
+ [TestFixture]
+ public class IntrospectionExtensionsTest
+ {
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void GetTypeInfo_NullArgument ()
+ {
+ IntrospectionExtensions.GetTypeInfo (null);
+ }
+
+ [Test]
+ public void GetTypeInfo_SystemType ()
+ {
+ var t = typeof (double);
+ Assert.AreSame (t, IntrospectionExtensions.GetTypeInfo (t));
+ }
+ }
+}
+
+#endif
\ No newline at end of file
System.Reflection/CustomAttributeDataTest.cs
System.Reflection/EventInfoTest.cs
System.Reflection/FieldInfoTest.cs
+System.Reflection/IntrospectionExtensionsTest.cs
System.Reflection/MethodBaseTest.cs
System.Reflection/MethodInfoTest.cs
System.Reflection/MonoGenericClassTest.cs