Esempio n. 1
0
        private static Type?GetClrTypeImpl(IEdmModel edmModel, IEdmType edmType)
        {
            if (edmType is IEdmPrimitiveType edmPrimitiveType)
            {
                return(PrimitiveTypeHelper.GetClrType(edmPrimitiveType.PrimitiveKind));
            }

            Type?clrType = edmModel.GetAnnotationValue <Type>(edmType);

            if (clrType != null)
            {
                return(clrType);
            }

            if (edmType is IEdmCollectionType collectionType)
            {
                return(GetClrTypeImpl(edmModel, collectionType.ElementType.Definition));
            }

            foreach (IEdmModel refModel in edmModel.ReferencedModels)
            {
                if (refModel is EdmModel)
                {
                    clrType = GetClrTypeImpl(refModel, edmType);
                    if (clrType != null)
                    {
                        return(clrType);
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
        public static IEdmTypeReference GetEdmTypeReference(this IEdmModel edmModel, Type clrType)
        {
            IEdmTypeReference edmTypeRef;
            bool nullable;
            Type underlyingType = Nullable.GetUnderlyingType(clrType);

            if (underlyingType == null)
            {
                nullable = clrType.IsClass;
            }
            else
            {
                clrType  = underlyingType;
                nullable = true;
            }

            IEdmPrimitiveType primitiveEdmType = PrimitiveTypeHelper.GetPrimitiveType(clrType);

            if (primitiveEdmType == null)
            {
                var edmEnumType = (IEdmEnumType)edmModel.FindType(clrType.FullName);
                edmTypeRef = new EdmEnumTypeReference(edmEnumType, nullable);
            }
            else
            {
                edmTypeRef = EdmCoreModel.Instance.GetPrimitive(primitiveEdmType.PrimitiveKind, nullable);
            }

            return(edmTypeRef);
        }
Esempio n. 3
0
        public static IEdmTypeReference GetEdmTypeReference(Type clrType)
        {
            bool nullable;
            Type?underlyingType = Nullable.GetUnderlyingType(clrType);

            if (underlyingType == null)
            {
                nullable = clrType.IsClass;
            }
            else
            {
                clrType  = underlyingType;
                nullable = true;
            }

            if (clrType.IsEnum)
            {
                clrType = Enum.GetUnderlyingType(clrType);
            }

            IEdmPrimitiveType?primitiveEdmType = PrimitiveTypeHelper.GetPrimitiveType(clrType);

            if (primitiveEdmType == null)
            {
                throw new InvalidOperationException("Not found Edm type for Clr type " + clrType.FullName);
            }

            return(EdmCoreModel.Instance.GetPrimitive(primitiveEdmType.PrimitiveKind, nullable));
        }
        public PrimitiveArrayInfo(DumpPrimitiveArray org)
        {
            PrimitiveArrayID = org.PrimitiveArrayID;

            Type = org.Type;

            ElementDatas = new List <object>();
            for (var start = 0; start < org.ElementDatas.Length;)
            {
                var t = PrimitiveTypeHelper.GetPrimitiveValue(org.Type, org.ElementDatas, ref start);
                ElementDatas.Add(t);
            }
            if (Type == PrimitiveType.HPROF_BASIC_CHAR)
            {
                if (ElementDatas.Count > 0)
                {
                    //if (ElementDatas.Exists(c=>(short)c>255 || (short)c<0))//此处为Unicode编码
                    {
                        var temp = ElementDatas.Select(c => (short)c).ToArray();
                        var t2   = ByteConverter.Arr2Arr <short, byte>(temp);
                        StringData = Encoding.Unicode.GetString(t2);
                    }
                    // else//此处为ASCII编码
                    // {
                    //     var temp = ElementDatas.Select(c => (byte)(short)c).ToArray();
                    //     StringData = Encoding.Default.GetString(temp);
                    // }
                }
                else
                {
                    StringData = "";
                }
            }
        }
Esempio n. 5
0
        public static OePropertyAccessor CreatePropertyAccessor(IEdmProperty edmProperty, Expression expression, ParameterExpression parameter)
        {
            UnaryExpression   instance      = Expression.Convert(expression, typeof(Object));
            var               func          = (Func <Object, Object>)Expression.Lambda(instance, parameter).Compile();
            IEdmPrimitiveType primitiveType = PrimitiveTypeHelper.GetPrimitiveType(expression.Type);

            return(new OePropertyAccessor(edmProperty, func));
        }
Esempio n. 6
0
        public static OePropertyAccessor CreatePropertyAccessor(IEdmProperty edmProperty, MethodCallExpression indexExpression, ParameterExpression parameter, bool skipToken)
        {
            EdmPrimitiveTypeKind primitiveKind = edmProperty.Type.PrimitiveKind();
            Type propertyType = PrimitiveTypeHelper.GetClrType(primitiveKind);

            if (propertyType.IsValueType && edmProperty.Type.IsNullable)
            {
                propertyType = typeof(Nullable <>).MakeGenericType(propertyType);
            }

            var             lambda            = (Func <Object?, Object?>)Expression.Lambda(indexExpression, parameter).Compile();
            UnaryExpression convertExpression = Expression.Convert(indexExpression, propertyType);

            return(new OePropertyAccessor(edmProperty, lambda, convertExpression, skipToken));
        }
        public static Type GetClrType(this IEdmModel edmModel, IEdmType edmType)
        {
            if (edmType.TypeKind == EdmTypeKind.Primitive)
            {
                return(PrimitiveTypeHelper.GetClrType((edmType as IEdmPrimitiveType).PrimitiveKind));
            }

            OeValueAnnotation <Type> clrTypeAnnotation = edmModel.GetAnnotationValue <OeValueAnnotation <Type> >(edmType);

            if (clrTypeAnnotation != null)
            {
                return(clrTypeAnnotation.Value);
            }

            if (edmType is IEdmCollectionType collectionType)
            {
                return(edmModel.GetClrType(collectionType.ElementType.Definition));
            }

            throw new InvalidOperationException("Add type annotation for " + edmType.FullTypeName());
        }
        public override Expression Visit(ConvertNode nodeIn)
        {
            Expression e = TranslateNode(nodeIn.Source);

            if (e.NodeType == ExpressionType.Constant)
            {
                var constantExpression = e as ConstantExpression;
                if (constantExpression.Value == null && constantExpression.Type == typeof(Object))
                {
                    Type clrType;
                    EdmPrimitiveTypeKind primitiveTypeKind = nodeIn.TypeReference.PrimitiveKind();
                    if (primitiveTypeKind == EdmPrimitiveTypeKind.None)
                    {
                        if (nodeIn.TypeReference.IsEnum())
                        {
                            clrType = _edmModel.GetClrType(nodeIn.TypeReference.Definition);
                        }
                        else
                        {
                            throw new NotSupportedException(nodeIn.TypeReference.FullName());
                        }
                    }
                    else
                    {
                        clrType = PrimitiveTypeHelper.GetClrType(primitiveTypeKind);
                    }
                    if (nodeIn.TypeReference.IsNullable && clrType.IsValueType)
                    {
                        clrType = typeof(Nullable <>).MakeGenericType(clrType);
                    }

                    ConstantExpression newConstantExpression = Expression.Constant(null, clrType);
                    ReplaceConstant(constantExpression, newConstantExpression);
                    e = newConstantExpression;
                }
            }
            return(e);
        }
        private static AggProperty CreateEdmProperty(IEdmModel model, Type clrType, String name, bool isGroup)
        {
            Type underlyingType = Nullable.GetUnderlyingType(clrType);

            if (underlyingType != null)
            {
                clrType = underlyingType;
            }

            bool nullable = PrimitiveTypeHelper.IsNullable(clrType);
            IEdmTypeReference edmTypeRef;

            if (clrType.GetTypeInfo().IsEnum)
            {
                var edmEnumType = (IEdmEnumType)model.FindType(clrType.FullName);
                edmTypeRef = new EdmEnumTypeReference(edmEnumType, nullable);
            }
            else
            {
                edmTypeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrType, nullable);
            }
            return(new AggProperty(name, edmTypeRef, isGroup));
        }
Esempio n. 10
0
        public static IEdmTypeReference GetEdmTypeReference(Type clrType)
        {
            bool nullable;
            Type underlyingType = Nullable.GetUnderlyingType(clrType);

            if (underlyingType == null)
            {
                nullable = clrType.IsClass;
            }
            else
            {
                clrType  = underlyingType;
                nullable = true;
            }

            if (clrType.IsEnum)
            {
                clrType = Enum.GetUnderlyingType(clrType);
            }

            IEdmPrimitiveType primitiveEdmType = PrimitiveTypeHelper.GetPrimitiveType(clrType);

            return(EdmCoreModel.Instance.GetPrimitive(primitiveEdmType.PrimitiveKind, nullable));
        }
Esempio n. 11
0
        public ObjectInstanceInfo(DumpObjectInstance org, HeapFileAnalyzer analyzer)
        {
            ClassObjectID = org.ClassObjectID;
            if (analyzer.ClassObjectInfos.ContainsKey(org.ClassObjectID))
            {
                ClassObject = analyzer.ClassObjectInfos[org.ClassObjectID];
            }
            else if (analyzer.ClassNames.ContainsKey(org.ClassObjectID))
            {
                ClassObject = analyzer.ClassNames[org.ClassObjectID];
            }
            ObjectID = org.ObjectID;

            int length = org.Length;

            #region ClassObject方法 -ClassObjectInfo
            if (ClassObject is ClassObjectInfo)
            {
                int             templength = 0;
                ClassObjectInfo tempClass  = ClassObject as ClassObjectInfo;
                InstanceFields = new List <PrimitiveObjectInfo>();

                while (templength < length)
                {
                    if (tempClass.InstanceFields == null)
                    {
                        break;
                    }
                    foreach (var it in tempClass.InstanceFields)
                    {
                        var value = PrimitiveTypeHelper.GetPrimitiveValue(it.Type, org.InstanceFieldData, ref templength);
                        if (it.Type != PrimitiveType.HPROF_BASIC_OBJECT)
                        {
                            InstanceFields.Add(new PrimitiveObjectInfo()
                            {
                                Name   = it.Name,
                                NameID = it.NameID,
                                Type   = it.Type,
                                Value  = value,
                            });
                        }
                        else
                        {
                            InstanceFields.Add(new ReferenceObjectInfo()
                            {
                                Name            = it.Name,
                                NameID          = it.NameID,
                                Type            = it.Type,
                                Value           = value,
                                ReferenceTarget = null
                            });
                        }
                    }

                    if (!analyzer.ClassObjectInfos.ContainsKey(tempClass.SuperClassObjectID))
                    {
                        break;
                    }
                    tempClass = analyzer.ClassObjectInfos[tempClass.SuperClassObjectID];
                }
            }
            ;
            #endregion

            #region ClassObject方法 -string
            if (ClassObject is string)
            {
                InstanceFields = new List <PrimitiveObjectInfo>();
                if (ClassName == "java.lang.String")
                {
                    int templength = 0;

                    var value = PrimitiveTypeHelper.GetPrimitiveValue(PrimitiveType.HPROF_BASIC_OBJECT, org.InstanceFieldData, ref templength);
                    InstanceFields.Add(new ReferenceObjectInfo()
                    {
                        Name   = "data",
                        NameID = 0,
                        Type   = PrimitiveType.HPROF_BASIC_OBJECT,
                        Value  = value,
                    });
                }
            }
            ;

            if (ClassName == "android.text.SpannableString" && InstanceFields.Count == 0)
            {
                int templength = 0;

                var value = PrimitiveTypeHelper.GetPrimitiveValue(PrimitiveType.HPROF_BASIC_OBJECT, org.InstanceFieldData, ref templength);
                InstanceFields.Add(new ReferenceObjectInfo()
                {
                    Name   = "data",
                    NameID = 0,
                    Type   = PrimitiveType.HPROF_BASIC_OBJECT,
                    Value  = value,
                });
            }
            #endregion
        }