コード例 #1
0
        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);
        }
コード例 #2
0
 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()*/
            );
 }
コード例 #3
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsIDynamicMetaObjectProvider(this Type type)
 {
     foreach (var @interface in type.GetInterfaces())
     {
         if (@interface.IsType("System.Dynamic", "IDynamicMetaObjectProvider"))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 /// <summary>
 /// Returns type argument if the type is
 /// Nullable&lt;T&gt;, 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);
 }
コード例 #5
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 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);
 }
コード例 #6
0
        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));
        }
コード例 #7
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: DkmClrValue.cs プロジェクト: tinaschrepfer/roslyn
        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();
            }
        }
コード例 #10
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
        /// <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);
        }
コード例 #11
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
        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);
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
ファイル: TypeImpl.cs プロジェクト: belav/roslyn
 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]
                    )
                ));
 }
コード例 #15
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);
        }
コード例 #16
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 public override bool IsSubclassOf(Type c)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 public override bool IsAssignableFrom(Type c)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsDynamicDebugViewEmptyException(this Type type)
 {
     return(type.IsType("Microsoft.CSharp.RuntimeBinder", "DynamicDebugViewEmptyException"));
 }
コード例 #19
0
ファイル: FieldInfoImpl.cs プロジェクト: elemk0vv/roslyn-1
 public override bool IsDefined(Type attributeType, bool inherit)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
ファイル: DkmClrValue.cs プロジェクト: XieShuquan/roslyn
 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;
 }
コード例 #21
0
ファイル: ResultProvider.cs プロジェクト: CAPCHIK/roslyn
 internal abstract bool IsPrimitiveType(Type type);
コード例 #22
0
 internal abstract bool IsPrimitiveType(Type type);
コード例 #23
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsIEnumerable(this Type type)
 {
     return(type.IsMscorlibType("System.Collections", "IEnumerable"));
 }
コード例 #24
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsIEnumerableOfT(this Type type)
 {
     return(type.IsMscorlibType("System.Collections.Generic", "IEnumerable`1"));
 }
コード例 #25
0
 public override bool Equals(Type o)
 {
     return(o != null && o.GetType() == this.GetType() && ((TypeImpl)o).Type == this.Type);
 }
コード例 #26
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsNullable(this Type type)
 {
     return(type.GetNullableTypeArgument() != null);
 }
コード例 #27
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsTypeVariables(this Type type)
 {
     return(type.IsType(null, "<>c__TypeVariables"));
 }
コード例 #28
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsComObject(this Type type)
 {
     return(type.IsType("System", "__ComObject"));
 }
コード例 #29
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
 {
     throw new NotImplementedException();
 }
コード例 #30
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 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]));
 }
コード例 #31
0
ファイル: TypeImpl.cs プロジェクト: elemk0vv/roslyn-1
 protected override ConstructorInfo GetConstructorImpl(System.Reflection.BindingFlags bindingAttr, Binder binder, System.Reflection.CallingConventions callConvention, Type[] types, System.Reflection.ParameterModifier[] modifiers)
 {
     throw new NotImplementedException();
 }
コード例 #32
0
ファイル: Formatter.cs プロジェクト: GloryChou/roslyn
 internal abstract bool IsPredefinedType(Type type);
コード例 #33
0
ファイル: MemberExpansion.cs プロジェクト: GloryChou/roslyn
 internal StaticMembersExpansion(Type runtimeType, Expansion members)
 {
     _runtimeType = runtimeType;
     _members = members;
 }
コード例 #34
0
ファイル: DkmClrValue.cs プロジェクト: XieShuquan/roslyn
 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;
 }
コード例 #35
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 public override bool Equals(Type o)
 {
     return o != null && o.GetType() == this.GetType() && ((TypeImpl)o).Type == this.Type;
 }
コード例 #36
0
ファイル: DkmClrValue.cs プロジェクト: XieShuquan/roslyn
 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();
     }
 }
コード例 #37
0
ファイル: TypeImpl.cs プロジェクト: Rickinio/roslyn
 public override System.Reflection.InterfaceMapping GetInterfaceMap(Type interfaceType)
 {
     throw new NotImplementedException();
 }
コード例 #38
0
ファイル: FieldInfoImpl.cs プロジェクト: elemk0vv/roslyn-1
 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
 {
     throw new NotImplementedException();
 }
コード例 #39
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsDynamicProperty(this Type type)
 {
     return(type.IsType("Microsoft.CSharp.RuntimeBinder", "DynamicProperty"));
 }
コード例 #40
0
 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
 {
     throw new NotImplementedException();
 }
コード例 #41
0
ファイル: TypeHelpers.cs プロジェクト: tsasioglu/roslyn
 internal static bool IsEmptyResultsViewException(this Type type)
 {
     return(type.IsType("System.Linq", "SystemCore_EnumerableDebugViewEmptyException"));
 }