Exemple #1
0
        /// <summary>
        /// Creates a PaddingAttribute CodeDOM declaration.
        /// </summary>
        /// <param name="fieldType">Guerilla field type.</param>
        /// <param name="length">Length of the padding field.</param>
        /// <returns>A CodeCOM attribute delcaration.</returns>
        public static CodeAttributeDeclaration CreateAttributeDeclaration(field_type fieldType, int length)
        {
            // Create an expression for the padding type parameter.
            CodeFieldReferenceExpression attPadType = new CodeFieldReferenceExpression(
                new CodeTypeReferenceExpression(typeof(PaddingType).Name),
                PaddingAttribute.PaddingTypeFromFieldType(fieldType).ToString());

            // Create the PaddingAttribute attribute using the parameters.
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(
                typeof(PaddingAttribute).Name,
                new CodeAttributeArgument(attPadType),
                new CodeAttributeArgument(new CodePrimitiveExpression(length)));

            // Return the attribute instance.
            return(attribute);
        }
Exemple #2
0
        public static int GetPaddingFieldSize(FieldInfo field)
        {
            // Get the custom attributes associated with this field.
            object[]         attributes = field.GetCustomAttributes(typeof(PaddingAttribute), false);
            PaddingAttribute padding    = (PaddingAttribute)attributes.First(x => x.GetType() == typeof(PaddingAttribute));

            // Return the padding size of the field.
            if (padding != null)
            {
                return(padding.Length);
            }
            else
            {
                // There is no PaddingAttribute associated with this field.
                Console.WriteLine("[PaddingAttribute::GetPaddingFieldSize()] Tried to retrieve padding attribute from field '{0}' and failed!", field.Name);
                return(0);
            }
        }