internal static object GetHostObjectValue(Type lmrType, object rawValue) { // NOTE: This is just a "for testing purposes" approximation of what the real DkmClrValue.HostObjectValue // will return. We will need to update this implementation to match the real behavior we add // specialized support for additional types. var typeCode = Metadata.Type.GetTypeCode(lmrType); return((lmrType.IsPointer || lmrType.IsEnum || typeCode != TypeCode.DateTime || typeCode != TypeCode.Object) ? rawValue : null); }
private static bool IsMscorlibType(this Type type, string @namespace, string name) { // Ignore IsMscorlib for now since type.Assembly returns // System.Runtime.dll for some types in mscorlib.dll. // TODO: Re-enable commented out check. return(type.IsType( @namespace, name ) /*&& type.Assembly.IsMscorlib()*/ ); }
internal static bool IsIDynamicMetaObjectProvider(this Type type) { foreach (var @interface in type.GetInterfaces()) { if (@interface.IsType("System.Dynamic", "IDynamicMetaObjectProvider")) { return(true); } } return(false); }
/// <summary> /// Returns type argument if the type is /// Nullable<T>, otherwise null. /// </summary> internal static Type GetNullableTypeArgument(this Type type) { if (type.IsMscorlibType("System", "Nullable`1")) { var typeArgs = type.GetGenericArguments(); if (typeArgs.Length == 1) { return(typeArgs[0]); } } return(null); }
internal static bool IsOrInheritsFrom(this Type type, string @namespace, string name) { do { if (type.IsType(@namespace, name)) { return(true); } type = type.BaseType; }while (type != null); return(false); }
internal static DkmClrValue GetNullableValue( this DkmClrValue value, Type nullableTypeArg, DkmInspectionContext inspectionContext ) { var valueType = value.Type.GetLmrType(); if (valueType.Equals(nullableTypeArg)) { return(value); } return(value.GetNullableValue(inspectionContext)); }
internal static Type GetInterfaceListEntry(this Type interfaceType, Type declaration) { Debug.Assert(interfaceType.IsInterface); if (!interfaceType.IsGenericType || !declaration.IsGenericType) { return(interfaceType); } var index = Array.IndexOf(declaration.GetInterfacesOnType(), interfaceType); Debug.Assert(index >= 0); var result = declaration.GetGenericTypeDefinition().GetInterfacesOnType()[index]; Debug.Assert(interfaceType.GetGenericTypeDefinition().Equals(result.GetGenericTypeDefinition())); return(result); }
internal static Type GetBaseTypeOrNull( this Type underlyingType, DkmClrAppDomain appDomain, out DkmClrType type ) { Debug.Assert( (underlyingType.BaseType != null) || underlyingType.IsPointer || underlyingType.IsArray, "BaseType should only return null if the underlyingType is a pointer or array." ); underlyingType = underlyingType.BaseType; type = (underlyingType != null) ? DkmClrType.Create(appDomain, underlyingType) : null; return(underlyingType); }
private unsafe static object Dereference(IntPtr ptr, Type elementType) { // Only handling a subset of types currently. switch (Metadata.Type.GetTypeCode(elementType)) { case TypeCode.Int32: return(*(int *)ptr); case TypeCode.Object: if (ptr == IntPtr.Zero) { throw new InvalidOperationException("Dereferencing null"); } return(Marshal.PtrToStructure(ptr, ((TypeImpl)elementType).Type)); default: throw new InvalidOperationException(); } }
/// <summary> /// Substitute references to type parameters from 'typeDef' /// with type arguments from 'typeArgs' in type 'type'. /// </summary> internal static Type Substitute(this Type type, Type typeDef, Type[] typeArgs) { Debug.Assert(typeDef.IsGenericTypeDefinition); Debug.Assert(typeDef.GetGenericArguments().Length == typeArgs.Length); if (type.IsGenericType) { var builder = ArrayBuilder <Type> .GetInstance(); foreach (var t in type.GetGenericArguments()) { builder.Add(t.Substitute(typeDef, typeArgs)); } var typeDefinition = type.GetGenericTypeDefinition(); return(typeDefinition.MakeGenericType(builder.ToArrayAndFree())); } else if (type.IsArray) { var elementType = type.GetElementType(); elementType = elementType.Substitute(typeDef, typeArgs); var n = type.GetArrayRank(); return((n == 1) ? elementType.MakeArrayType() : elementType.MakeArrayType(n)); } else if (type.IsPointer) { var elementType = type.GetElementType(); elementType = elementType.Substitute(typeDef, typeArgs); return(elementType.MakePointerType()); } else if (type.IsGenericParameter) { if (type.DeclaringType.Equals(typeDef)) { var ordinal = type.GenericParameterPosition; return(typeArgs[ordinal]); } } return(type); }
internal static bool IsOrInheritsFrom(this Type type, Type baseType) { Debug.Assert(type != null); Debug.Assert(baseType != null); Debug.Assert(!baseType.IsInterface); if (type.IsInterface) { return(false); } do { if (type.Equals(baseType)) { return(true); } type = type.BaseType; }while (type != null); return(false); }
private unsafe static object Dereference(IntPtr ptr, Type elementType) { // Only handling a subset of types currently. switch (Metadata.Type.GetTypeCode(elementType)) { case TypeCode.Int32: return(*(int *)ptr); case TypeCode.Object: if (ptr == IntPtr.Zero) { throw new InvalidOperationException("Dereferencing null"); } var destinationType = elementType.IsPointer ? (Environment.Is64BitProcess ? typeof(long) : typeof(int)) : ((TypeImpl)elementType).Type; return(Marshal.PtrToStructure(ptr, destinationType)); default: throw new InvalidOperationException(); } }
internal static bool IsTupleCompatible(this Type type, out int cardinality) { if ( type.IsGenericType && AreNamesEqual(type.Namespace, "System") && type.Name.StartsWith(TupleTypeNamePrefix, StringComparison.Ordinal) ) { var typeArguments = type.GetGenericArguments(); int n = typeArguments.Length; if ((n > 0) && (n <= TupleFieldRestPosition)) { if (!AreNamesEqual(type.Name, TupleTypeNamePrefix + n)) { cardinality = 0; return(false); } if (n < TupleFieldRestPosition) { cardinality = n; return(true); } var restType = typeArguments[n - 1]; int restCardinality; if (restType.IsTupleCompatible(out restCardinality)) { cardinality = n - 1 + restCardinality; return(true); } } } cardinality = 0; return(false); }
protected override PropertyInfo GetPropertyImpl( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers ) { Debug.Assert(binder == null, "NYI"); Debug.Assert(returnType == null, "NYI"); Debug.Assert(types == null, "NYI"); Debug.Assert(modifiers == null, "NYI"); return(new PropertyInfoImpl( Type.GetProperty( name, (System.Reflection.BindingFlags)bindingAttr, binder: null, returnType: null, types: new System.Type[0], modifiers: new System.Reflection.ParameterModifier[0] ) )); }
private static Type GetAncestorType(Type type, string ancestorTypeName) { if (type.FullName == ancestorTypeName) { return(type); } // Search interfaces. foreach (var @interface in type.GetInterfaces()) { var ancestorType = GetAncestorType(@interface, ancestorTypeName); if (ancestorType != null) { return(ancestorType); } } // Search base type. var baseType = type.BaseType; if (baseType != null) { return(GetAncestorType(baseType, ancestorTypeName)); } return(null); }
public override bool IsSubclassOf(Type c) { throw new NotImplementedException(); }
public override bool IsAssignableFrom(Type c) { throw new NotImplementedException(); }
internal static bool IsDynamicDebugViewEmptyException(this Type type) { return(type.IsType("Microsoft.CSharp.RuntimeBinder", "DynamicDebugViewEmptyException")); }
public override bool IsDefined(Type attributeType, bool inherit) { throw new NotImplementedException(); }
private static Type GetAncestorType(Type type, string ancestorTypeName) { if (type.FullName == ancestorTypeName) { return type; } // Search interfaces. foreach (var @interface in type.GetInterfaces()) { var ancestorType = GetAncestorType(@interface, ancestorTypeName); if (ancestorType != null) { return ancestorType; } } // Search base type. var baseType = type.BaseType; if (baseType != null) { return GetAncestorType(baseType, ancestorTypeName); } return null; }
internal abstract bool IsPrimitiveType(Type type);
internal static bool IsIEnumerable(this Type type) { return(type.IsMscorlibType("System.Collections", "IEnumerable")); }
internal static bool IsIEnumerableOfT(this Type type) { return(type.IsMscorlibType("System.Collections.Generic", "IEnumerable`1")); }
public override bool Equals(Type o) { return(o != null && o.GetType() == this.GetType() && ((TypeImpl)o).Type == this.Type); }
internal static bool IsNullable(this Type type) { return(type.GetNullableTypeArgument() != null); }
internal static bool IsTypeVariables(this Type type) { return(type.IsType(null, "<>c__TypeVariables")); }
internal static bool IsComObject(this Type type) { return(type.IsType("System", "__ComObject")); }
protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) { throw new NotImplementedException(); }
protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) { Debug.Assert(binder == null, "NYI"); Debug.Assert(returnType == null, "NYI"); Debug.Assert(types == null, "NYI"); Debug.Assert(modifiers == null, "NYI"); return new PropertyInfoImpl(Type.GetProperty(name, (System.Reflection.BindingFlags)bindingAttr, binder: null, returnType: null, types: new System.Type[0], modifiers: new System.Reflection.ParameterModifier[0])); }
protected override ConstructorInfo GetConstructorImpl(System.Reflection.BindingFlags bindingAttr, Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, System.Reflection.ParameterModifier[] modifiers) { throw new NotImplementedException(); }
internal abstract bool IsPredefinedType(Type type);
internal StaticMembersExpansion(Type runtimeType, Expansion members) { _runtimeType = runtimeType; _members = members; }
internal static object GetHostObjectValue(Type lmrType, object rawValue) { // NOTE: This is just a "for testing purposes" approximation of what the real DkmClrValue.HostObjectValue // will return. We will need to update this implementation to match the real behavior we add // specialized support for additional types. var typeCode = Metadata.Type.GetTypeCode(lmrType); return (lmrType.IsPointer || lmrType.IsEnum || typeCode != TypeCode.DateTime || typeCode != TypeCode.Object) ? rawValue : null; }
public override bool Equals(Type o) { return o != null && o.GetType() == this.GetType() && ((TypeImpl)o).Type == this.Type; }
private unsafe static object Dereference(IntPtr ptr, Type elementType) { // Only handling a subset of types currently. switch (Metadata.Type.GetTypeCode(elementType)) { case TypeCode.Int32: return *(int*)ptr; case TypeCode.Object: if (ptr == IntPtr.Zero) { throw new InvalidOperationException("Dereferencing null"); } var destinationType = elementType.IsPointer ? (Environment.Is64BitProcess ? typeof(long) : typeof(int)) : ((TypeImpl)elementType).Type; return Marshal.PtrToStructure(ptr, destinationType); default: throw new InvalidOperationException(); } }
public override System.Reflection.InterfaceMapping GetInterfaceMap(Type interfaceType) { throw new NotImplementedException(); }
public override object[] GetCustomAttributes(Type attributeType, bool inherit) { throw new NotImplementedException(); }
internal static bool IsDynamicProperty(this Type type) { return(type.IsType("Microsoft.CSharp.RuntimeBinder", "DynamicProperty")); }
internal static bool IsEmptyResultsViewException(this Type type) { return(type.IsType("System.Linq", "SystemCore_EnumerableDebugViewEmptyException")); }