예제 #1
0
        /// <summary>
        /// Creates a TagGroupDefinitionAttribute CodeDOM declaration.
        /// </summary>
        /// <param name="tagGroup">Guerill tag group definition.</param>
        /// <param name="definitionSize">Alternative calculated size of the definition, overrides fieldSet.size</param>
        /// <returns>A CodeDOM attribute declaration.</returns>
        public static CodeAttributeDeclaration CreateAttributeDeclaration(tag_group tagGroup, int definitionSize = 0)
        {
            // Get the latest field set from the guerilla definition.
            tag_field_set fieldSet = tagGroup.Definition.TagFieldSets[tagGroup.Definition.GetFieldSetIndexClosestToH2Xbox()];

            // Setup a TagGroupDefinitionAttribute attribute using the definition info.
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(TagGroupDefinitionAttribute).Name, new CodeAttributeArgument[]
            {
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("sizeOf: {0}", (definitionSize != 0 ? definitionSize : fieldSet.size)))),
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("version: {0}", tagGroup.version))),
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("groupTag: \"{0}\"", tagGroup.GroupTag)))
            });

            // Return the new attribute declaration.
            return(attribute);
        }
        /// <summary>
        /// Creates a TagBlockDefinitionAttribute CodeDOM declaration.
        /// </summary>
        /// <param name="definition">Guerilla tag block definition.</param>
        /// <param name="definitionSize">Alternative calculated size of the definition, overrides definition.TagFieldSets[x].size</param>
        /// <returns>A CodeDOM attribute declaration.</returns>
        public static CodeAttributeDeclaration CreateAttributeDeclaration(TagBlockDefinition definition, int definitionSize = 0)
        {
            // Get the latest field set from the guerilla definition.
            tag_field_set fieldSet = definition.TagFieldSets[definition.GetFieldSetIndexClosestToH2Xbox()];

            // Setup a TagBlockDefinitionAttribute attribute using the definition info.
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(TagBlockDefinitionAttribute).Name, new CodeAttributeArgument[]
            {
                // CodeDOM doesn't seem to support named parameters so we are going to do some h4x here...
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("sizeOf: {0}", (definitionSize != 0 ? definitionSize : fieldSet.size)))),
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("alignment: {0}", fieldSet.alignment_bit != 0 ? (1 << fieldSet.alignment_bit) : 4))),
                new CodeAttributeArgument(new CodeSnippetExpression(string.Format("maxBlockCount: {0}", definition.s_tag_block_definition.maximum_element_count)))
            });

            // Return the new attribute declaration.
            return(attribute);
        }