Exemplo n.º 1
0
        /// <summary>
        /// Determines the offset of the specified property
        /// </summary>
        /// <param name="property">An expression to select the property</param>
        /// <returns>The offset specified on the property</returns>
        public static int StartsAt <T>(Expression <Func <T, object> > property)
        {
            SerializableMemberAttribute memberAttr = null;

            Expression body = property.Body;

            // Since we're using Func<T, object> value types will have a Convert expression wrapping the access
            if (body.NodeType == ExpressionType.Convert)
            {
                body = (body as UnaryExpression).Operand;
            }

            if (body.NodeType == ExpressionType.MemberAccess)
            {
                memberAttr = (body as MemberExpression).Member
                             .GetCustomAttribute <SerializableMemberAttribute>();
            }

            if (memberAttr == null)
            {
                throw new Exception("Can't find the start of the specified member");
            }

            return(memberAttr.Offset);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines the offset of the property in the specified type
        /// </summary>
        /// <param name="t">The type to inspect</param>
        /// <param name="propertyName">The property on the type</param>
        /// <returns>The offset specified on the property</returns>
        public static int StartsAt(Type t, string propertyName)
        {
            SerializableMemberAttribute memberAttr = null;

            var member = t.GetMember(propertyName);

            if (member.Length > 0)
            {
                memberAttr = member[0].GetCustomAttribute <SerializableMemberAttribute>();
            }

            if (memberAttr == null)
            {
                throw new Exception("Can't find the start of the specified member");
            }

            return(memberAttr.Offset);
        }
Exemplo n.º 3
0
 protected virtual bool CheckAqlaModelId(SerializableMemberAttribute attr, RuntimeTypeModel model)
 {
     return(CheckAqlaModelId(attr.ModelId, model));
 }