Пример #1
0
        public override uint GetFieldOffset(object item)
        {
            FieldDeclaration      field         = item as FieldDeclaration;
            INestedTypeDefinition nestedTypeDef = item as INestedTypeDefinition;
            uint result = field != null?MemberHelper.ComputeFieldOffset(field.FieldDefinition, field.FieldDefinition.ContainingTypeDefinition) : MemberHelper.ComputeFieldOffset(nestedTypeDef, this.TypeDefinition);

            // This distinguishes between anonymous nested types, where we need to walk upwards to the surrounding type,
            // and nested types that have their own field name, where we must not do this
            // the current AST representation requires such a complicated approach
            bool            nestedTypeHasFieldName = false;
            ITypeDefinition containingDef          = this.ContainingTypeDeclaration.TypeDefinition;

            foreach (ITypeDefinitionMember member in containingDef.Members)
            {
                IFieldDefinition fieldMember = member as IFieldDefinition;
                if (fieldMember != null && fieldMember.Type.ResolvedType == this.TypeDefinition && !String.IsNullOrEmpty(fieldMember.Name.Value))
                {
                    nestedTypeHasFieldName = true;
                    break;
                }
            }
            if (!nestedTypeHasFieldName)
            {
                result += this.ContainingTypeDeclaration.GetFieldOffset(this.TypeDefinition);
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Use compute field offset to get the offset.
        /// </summary>
        /// <param name="item"> Field whose offset is of concern. </param>
        /// <returns></returns>
        public override uint GetFieldOffset(object item)
        {
            FieldDeclaration field = item as FieldDeclaration;

            if (field != null)
            {
                return(MemberHelper.ComputeFieldOffset(field.FieldDefinition, field.FieldDefinition.ContainingTypeDefinition));
            }
            else
            {
                return(MemberHelper.ComputeFieldOffset((INestedTypeDefinition)item, this.TypeDefinition));
            }
        }