Beispiel #1
0
 static bool FieldMatchesOptions(int fieldIndex, CachedSnapshot data, FieldFindOptions options)
 {
     if (options == FieldFindOptions.OnlyStatic)
     {
         return(data.fieldDescriptions.isStatic[fieldIndex]);
     }
     if (options == FieldFindOptions.OnlyInstance)
     {
         return(!data.fieldDescriptions.isStatic[fieldIndex]);
     }
     return(false);
 }
Beispiel #2
0
        static bool FieldMatchesOptions(FieldDescription field, FieldFindOptions options)
        {
            if (field.isStatic && options == FieldFindOptions.OnlyStatic)
            {
                return(true);
            }
            if (!field.isStatic && options == FieldFindOptions.OnlyInstance)
            {
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        static public IEnumerable <int> AllFieldArrayIndexOf(int iTypeArrayIndex, CachedSnapshot data, FieldFindOptions findOptions, bool includeBase)
        {
            int baseTypeIndex = data.typeDescriptions.baseOrElementTypeIndex[iTypeArrayIndex];

            bool isValueType = data.typeDescriptions.HasFlag(iTypeArrayIndex, TypeFlags.kValueType);

            //yield all fields from base type
            if (includeBase &&
                baseTypeIndex != -1 &&
                !isValueType)
            {
                int baseArrayIndex = data.typeDescriptions.TypeIndex2ArrayIndex(baseTypeIndex);
                foreach (var iField in AllFieldArrayIndexOf(baseArrayIndex, data, findOptions, includeBase))
                {
                    yield return(iField);
                }
            }
            int iTypeIndex = data.typeDescriptions.typeIndex[iTypeArrayIndex];

            foreach (var iField in data.typeDescriptions.fieldIndices[iTypeArrayIndex])
            {
                if (!FieldMatchesOptions(iField, data, findOptions))
                {
                    continue;
                }

                if (data.fieldDescriptions.typeIndex[iField] == iTypeIndex && isValueType)
                {
                    // this happens in primitive types like System.Single, which is a weird type that has a field of its own type.
                    continue;
                }

                if (data.fieldDescriptions.offset[iField] == -1)
                {
                    // this is how we encode TLS fields. We don't support TLS fields yet.
                    continue;
                }

                yield return(iField);
            }
        }
 public static void AllFieldArrayIndexOf(ref List <int> fieldsBuffer, int ITypeArrayIndex, CachedSnapshot data, FieldFindOptions findOptions, bool includeBase)
 {
     //make sure we clear before we start crawling
     fieldsBuffer.Clear();
     RecurseCrawlFields(ref fieldsBuffer, ITypeArrayIndex, data, findOptions, includeBase);
 }
        static void RecurseCrawlFields(ref List <int> fieldsBuffer, int ITypeArrayIndex, CachedSnapshot data, FieldFindOptions fieldFindOptions, bool crawlBase)
        {
            bool isValueType = data.typeDescriptions.HasFlag(ITypeArrayIndex, TypeFlags.kValueType);

            if (crawlBase)
            {
                int baseTypeIndex = data.typeDescriptions.baseOrElementTypeIndex[ITypeArrayIndex];
                if (crawlBase && baseTypeIndex != -1 && !isValueType)
                {
                    int baseArrayIndex = data.typeDescriptions.TypeIndex2ArrayIndex(baseTypeIndex);
                    RecurseCrawlFields(ref fieldsBuffer, baseArrayIndex, data, fieldFindOptions, true);
                }
            }


            int iTypeIndex   = data.typeDescriptions.typeIndex[ITypeArrayIndex];
            var fieldIndices = data.typeDescriptions.fieldIndices[ITypeArrayIndex];

            for (int i = 0; i < fieldIndices.Length; ++i)
            {
                var iField = fieldIndices[i];

                if (!FieldMatchesOptions(iField, data, fieldFindOptions))
                {
                    continue;
                }

                if (data.fieldDescriptions.typeIndex[iField] == iTypeIndex && isValueType)
                {
                    // this happens in primitive types like System.Single, which is a weird type that has a field of its own type.
                    continue;
                }

                if (data.fieldDescriptions.offset[iField] == -1) //TODO: verify this assumption
                {
                    // this is how we encode TLS fields. We don't support TLS fields yet.
                    continue;
                }

                fieldsBuffer.Add(iField);
            }
        }
Beispiel #6
0
        static public IEnumerable <FieldDescription> AllFieldsOf(TypeDescription typeDescription, TypeDescription[] typeDescriptions, FieldFindOptions findOptions)
        {
            if (typeDescription.isArray)
            {
                yield break;
            }

            if (findOptions != FieldFindOptions.OnlyStatic && typeDescription.baseOrElementTypeIndex != -1 && !typeDescription.isValueType)
            {
                var baseTypeDescription = typeDescriptions [typeDescription.baseOrElementTypeIndex];
                foreach (var field in AllFieldsOf(baseTypeDescription, typeDescriptions, findOptions))
                {
                    yield return(field);
                }
            }

            foreach (var field in typeDescription.fields)
            {
                if (!FieldMatchesOptions(field, findOptions))
                {
                    continue;
                }

                if (field.typeIndex == typeDescription.typeIndex && typeDescription.isValueType)
                {
                    // this happens in primitive types like System.Single, which is a weird type that has a field of its own type.
                    continue;
                }

                if (field.offset == -1)
                {
                    // this is how we encode TLS fields. We don't support TLS fields yet.
                    continue;
                }

                yield return(field);
            }
        }
Beispiel #7
0
        static public IEnumerable <FieldDescription> AllFieldsOf(TypeDescription typeDescription, TypeDescription[] typeDescriptions, FieldFindOptions findOptions)
        {
            if (typeDescription.isArray)
            {
                yield break;
            }

            if (findOptions != FieldFindOptions.OnlyStatic && typeDescription.baseOrElementTypeIndex != -1)
            {
                var baseTypeDescription = typeDescriptions [typeDescription.baseOrElementTypeIndex];
                foreach (var field in AllFieldsOf(baseTypeDescription, typeDescriptions, findOptions))
                {
                    yield return(field);
                }
            }

            foreach (var field in typeDescription.fields.Where(f => FieldMatchesOptions(f, findOptions)))
            {
                yield return(field);
            }
        }