Пример #1
0
        /// <summary>
        /// Creates a new field for the specified type and adds it to the current code object.
        /// </summary>
        /// <param name="fieldType">Guerilla field type of the field.</param>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="attributeCollection">Collection of attributes to be put on the field.</param>
        public void AddField(field_type fieldType, string fieldName, CodeAttributeDeclarationCollection attributeCollection = null)
        {
            // Get the underlying type for this field.
            Type standardFieldType = ValueTypeDictionary[fieldType];

            // Create a new code member field for the tag field.
            CodeMemberField field = new CodeMemberField(MutationCodeFormatter.CreateShortCodeTypeReference(standardFieldType, MutationNamespaces), fieldName);

            field.Attributes = MemberAttributes.Public;

            // Add any attributes for this field.
            field.CustomAttributes = attributeCollection;

            // Add the field to the class definition.
            this.CodeClass.Members.Add(field);
        }
Пример #2
0
        /// <summary>
        /// Creates a new tag block field and adds it to the current code object.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="blockTypeName">Name of the underlying tag block definition type.</param>
        /// <param name="attributeCollection">Collection of attributes to be put on the field.</param>
        public void AddTagBlockField(string fieldName, string blockTypeName, CodeAttributeDeclarationCollection attributeCollection = null)
        {
            // Create a new code type reference to reference the tag_block data type.
            CodeTypeReference tagBlockType = MutationCodeFormatter.CreateShortCodeTypeReference(ValueTypeDictionary[field_type._field_block], MutationNamespaces);

            tagBlockType.TypeArguments.Add(blockTypeName);

            // Create a new code member field for the tag field.
            CodeMemberField field = new CodeMemberField(tagBlockType, fieldName);

            field.Attributes = MemberAttributes.Public;

            // Add any attributes for this field.
            field.CustomAttributes = attributeCollection;

            // Add the field to the class definition.
            this.CodeClass.Members.Add(field);
        }
Пример #3
0
        /// <summary>
        /// Creates a new Explanation field using the information provided.
        /// </summary>
        /// <param name="fieldName">Name of the explanation field.</param>
        /// <param name="blockName">Name of the explanation block.</param>
        /// <param name="explanation">Explanation for the block.</param>
        /// <param name="attributeCollection">Collection of attributes to be put on the field.</param>
        public void AddExplanationField(string fieldName, string blockName = "", string explanation = "", CodeAttributeDeclarationCollection attributeCollection = null)
        {
            // Get the underlying type for this field.
            Type standardFieldType = ValueTypeDictionary[field_type._field_explanation];

            // Create a new code member field for the explanation block.
            CodeMemberField field = new CodeMemberField(MutationCodeFormatter.CreateShortCodeTypeReference(standardFieldType, MutationNamespaces), fieldName);

            field.Attributes = MemberAttributes.Public;

            // Create a list of parameters to give to the explanation constructor.
            List <CodeExpression> initializers = new List <CodeExpression>();

            // Check if the block name is present.
            if (blockName != string.Empty)
            {
                // Create a code expression for the block name initializer.
                initializers.Add(new CodeSnippetExpression(string.Format("name: \"{0}\"", blockName)));
            }

            // Check if the explanation is present.
            if (MutationCodeFormatter.IsValidFieldName(explanation) == true)
            {
                // Create a code expression for the explanation initializer.
                initializers.Add(new CodeSnippetExpression(string.Format("explanation: {0}", MutationCodeFormatter.CreateCodeSafeStringLiteral(explanation))));
            }

            // Create the init expression which will call the constructor of the Explanation object.
            field.InitExpression = new CodeObjectCreateExpression(MutationCodeFormatter.CreateShortCodeTypeReference(standardFieldType, MutationNamespaces), initializers.ToArray());

            // Add any attributes for this field.
            field.CustomAttributes = attributeCollection;

            // Add the field to the class definition.
            this.CodeClass.Members.Add(field);
        }