protected void ParseProperty(string code)
 {
     const string propertyName = "AProperty";
     ContentType = new MediaType();
     var type = ParseType(code);
     var prop = type.Members.SingleOrDefault(m => m.Name == propertyName);
     Parser.Parse(prop, ContentType);
     Property = ContentType.GenericProperties.SingleOrDefault(p => p.Alias == propertyName.CamelCase());
 }
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.MediaTypes;
     Generator = new PropertyInfoGenerator(
         Configuration, 
         TestDataTypeProvider.All
     );
     attribute = new CodeAttributeDeclaration();
     property = new GenericProperty{Alias="anEntity"};
 }
 protected void SetType(CodeMemberProperty propNode, GenericProperty property)
 {
     var hasType = property.Type != null &&
                   Config.TypeMappings.ContainsKey(property.Type.ToLower());
     var typeName = hasType 
         ? Config.TypeMappings[property.Type.ToLower()]
         : Config.TypeMappings.DefaultType;
     if (typeName == null)
         throw new Exception("TypeMappings/Default not set. Cannot guess default property type.");
     propNode.Type = new CodeTypeReference(typeName);
 }
        public void Generate_Adds_Getter()
        {
            var property = new GenericProperty { Alias = "aProperty" };
            var propNode = new CodeMemberProperty { Type = new CodeTypeReference("String") };

            var generator = new InterfacePropertyBodyGenerator(CodeGeneratorConfiguration.Create().DocumentTypes);
            generator.Generate(propNode, property);

            Assert.IsTrue(propNode.HasGet);
            Assert.AreEqual(0, propNode.GetStatements.Count);
        }
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.DocumentTypes;
     Generator = new InterfacePropertyDeclarationGenerator(
         Configuration,
         TestDataTypeProvider.All,
         new EntityDescriptionGenerator(Configuration)
     );
     Candidate = codeProperty = new CodeMemberProperty();
     property = new GenericProperty { Alias = "aProperty" };
 }
 private void AddDataType(CodeMemberProperty propNode, GenericProperty property)
 {
     var dataType = DataTypes.SingleOrDefault(dt =>
         String.Compare(dt.DefinitionId, property.Definition, IgnoreCase) == 0 ||
         String.Compare(dt.DataTypeName, property.Definition, IgnoreCase) == 0);
     var dataTypeValue = dataType != null
         ? dataType.DataTypeName
         : Config.DefaultDefinitionId;
     if (dataTypeValue == null)
         throw new Exception("TypeMappings/DefaultDefinitionId not set. Cannot guess default definition.");
     AddAttribute(propNode, "DataType", dataTypeValue);
 }
 public void SetUp()
 {
     codeGenConfig = CodeGeneratorConfiguration.Create();
     Configuration = codeGenConfig.MediaTypes;
     Generator = new PropertyInfoGenerator(
         Configuration, 
         TestDataTypeProvider.All,
         new EntityDescriptionGenerator(Configuration)
     );
     Candidate = codeProperty = new CodeMemberProperty();
     property = new GenericProperty{Alias="anEntity"};
 }
        private void AddDataType(CodeAttributeDeclaration attribute, GenericProperty property)
        {
            var dataType = dataTypes.SingleOrDefault(dt =>
            String.Compare(dt.DefinitionId, property.Definition, IgnoreCase) == 0 ||
            String.Compare(dt.DataTypeName, property.Definition, IgnoreCase) == 0);
            var dataTypeValue = dataType != null
                ? dataType.DataTypeName
                : Config.TypeMappings.DefaultDefinitionId;
            if (dataTypeValue == null)
                throw new Exception("TypeMappings/DefaultDefinitionId not set. Cannot guess default definition.");

            AddAttributePrimitiveArgument(attribute, "Definition", dataTypeValue);
        }
        protected string GeneratePropertyAndGetBodyText()
        {
            var property = new GenericProperty {Alias = "aProperty"};
            var propNode = new CodeMemberProperty {Type = new CodeTypeReference("String")};
            var generator = CreateGenerator();

            generator.Generate(propNode, property);

            var ns = CodeGenerationHelper.CreateNamespaceWithTypeAndProperty(propNode);
            var builder = CodeGenerationHelper.GenerateCode(ns);

            var code = builder.ToString();
            var returnIndex = code.IndexOf("return");
            var endIndex = code.IndexOf(";", returnIndex);
            var body = code.Substring(returnIndex, endIndex - returnIndex + 1);
            return body;
        }
        public void Generate_Body_GetsContentPropertyValueOfType()
        {
            var property = new GenericProperty {Alias = "aProperty"};
            var propNode = new CodeMemberProperty {Type = new CodeTypeReference("String")};
            var generator = new PropertyBodyGenerator(new CodeGeneratorConfiguration().MediaTypes);
            
            generator.Generate(propNode, property);

            var ns = CodeGenerationHelper.CreateNamespaceWithTypeAndProperty(propNode);
            var builder = CodeGenerationHelper.GenerateCode(ns);

            var code = builder.ToString();
            var returnIndex = code.IndexOf("return");
            var endIndex = code.IndexOf(";", returnIndex);
            var body = code.Substring(returnIndex, endIndex - returnIndex + 1);

            Assert.AreEqual(
                "return Content.GetPropertyValue<String>(\"aProperty\");",
                body
                );
        }
Esempio n. 11
0
        public override void Parse(AstNode node, ContentType contentType)
        {
            var propNode = (PropertyDeclaration) node;
            var definitionId = AttributeValue(propNode, "DataType");
            var dataType = FindDataTypeDefinition(definitionId) ?? defaultDataType;

            if (dataType == null)
                throw new Exception("Default datatype could not be found. Set a known datatype in TypeMappings.DefaultDefinitionId.");

            var property = new GenericProperty
            {
                Alias = propNode.Name.CamelCase(),
                Name = AttributeValue(propNode, "DisplayName", propNode.Name.SplitPascalCase()),
                Description = AttributeValue(propNode, "Description"),
                Definition = dataType.DefinitionId,
                Type = dataType.DataTypeId,
                Tab = AttributeValue(propNode, "Category"),
                Mandatory = FindAttribute(propNode.Attributes, "Required") != null,
                Validation = AttributeValue(propNode, "RegularExpression")
            };
            contentType.GenericProperties.Add(property);
        }
Esempio n. 12
0
        public override void Parse(AstNode node, ContentType contentType)
        {
            var propNode = (PropertyDeclaration)node;
            var attribute = FindAttribute(propNode.Attributes, "GenericProperty");

            var definitionId = AttributeArgumentValue<string>(attribute, "Definition", null);
            var dataType = FindDataTypeDefinition(definitionId) ?? DefaultDataType;

            if (dataType == null)
                throw new Exception("Default datatype could not be found. Set a known datatype in TypeMappings.DefaultDefinitionId.");

            var property = new GenericProperty
            {
                Alias = propNode.Name.CamelCase(),
                Name = AttributeArgumentValue(attribute, "DisplayName", propNode.Name.SplitPascalCase()),
                Description = AttributeArgumentValue<string>(attribute, "Description", null),
                Definition = dataType.DefinitionId,
                Type = dataType.DataTypeId,
                Tab = AttributeArgumentValue<string>(attribute, "Tab", null),
                Mandatory = AttributeArgumentValue(attribute, "Mandatory", false),
                Validation = AttributeArgumentValue<string>(attribute, "Validation", null)
            };
            contentType.GenericProperties.Add(property);
        }
 private void AddCategory(CodeMemberProperty propNode, GenericProperty property)
 {
     if (String.IsNullOrWhiteSpace(property.Tab))
         return;
     AddAttribute(propNode, "Category", property.Tab);
 }
 private void DeserializeProperty(XContainer propElement)
 {
     var prop = new GenericProperty
     {
         Name = propElement.ElementValue("Name"),
         Alias = propElement.ElementValue("Alias"),
         Type = propElement.ElementValue("Type"),
         Definition = propElement.ElementValue("Definition"),
         Tab = propElement.ElementValue("Tab"),
         Mandatory = Convert.ToBoolean(propElement.ElementValue("Mandatory")),
         Validation = propElement.ElementValue("Validation"),
         Description = propElement.ElementValue("Description")
     };
     type.GenericProperties.Add(prop);
 }
 private void SerializeProperty(XElement propsElement, GenericProperty property)
 {
     var prop = new XElement("GenericProperty",
         CreateElement("Name", property.Name),
         CreateElement("Alias", property.Alias),
         CreateElement("Type", property.Type),
         CreateElement("Definition", property.Definition),
         CreateElement("Tab", property.Tab),
         CreateElement("Mandatory", property.Mandatory.ToString()),
         CreateElement("Validation", property.Validation),
         new XElement("Description", new XCData(property.Description ?? ""))
         );
     propsElement.Add(prop);
 }
 private void AddValidation(CodeMemberProperty propNode, GenericProperty property)
 {
     if (String.IsNullOrWhiteSpace(property.Validation))
         return;
     AddAttribute(propNode, "RegularExpression", property.Validation);
 }
 private void AddRequired(CodeMemberProperty propNode, GenericProperty property)
 {
     if (property.Mandatory)
         AddAttribute(propNode, "Required");
 }