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);
        }
Exemplo n.º 2
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);
        }
    public static int test()
    {
        GenericProperty <Integer> gp = new GenericProperty <Integer>();

        gp.Property = 1;
        return(gp.Property);
    }
        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
                );
        }
 private void AddRequired(CodeMemberProperty propNode, GenericProperty property)
 {
     if (property.Mandatory)
     {
         AddAttribute(propNode, "Required");
     }
 }
 private void AddValidation(CodeMemberProperty propNode, GenericProperty property)
 {
     if (String.IsNullOrWhiteSpace(property.Validation))
     {
         return;
     }
     AddAttribute(propNode, "RegularExpression", property.Validation);
 }
        public void GetHashCode_should_return_value_for_class_with_generic_property()
        {
            var instance = new GenericProperty <int> {
                Prop = 1
            };

            Assert.NotEqual(0, instance.GetHashCode());
        }
 private void AddCategory(CodeMemberProperty propNode, GenericProperty property)
 {
     if (String.IsNullOrWhiteSpace(property.Tab))
     {
         return;
     }
     AddAttribute(propNode, "Category", property.Tab);
 }
Exemplo n.º 9
0
        private 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());
        }
Exemplo n.º 10
0
        private bool doesPropertyTypeAliasExist(GenericProperty gpData)
        {
            bool        hasAlias = cType.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
            ContentType ct       = cType;

            while (ct.MasterContentType > 0)
            {
                ct       = new ContentType(ct.MasterContentType);
                hasAlias = ct.getPropertyType(Casing.SafeAliasWithForcingCheck(gpData.Alias.Trim())) != null;
            }
            return(!hasAlias);
        }
 public void SetUp()
 {
     codeGenConfig = new CodeGeneratorConfiguration();
     Configuration = codeGenConfig.MediaTypes;
     Generator     = new PropertyInfoGenerator(
         Configuration,
         TestDataTypeProvider.All
         );
     attribute = new CodeAttributeDeclaration();
     property  = new GenericProperty {
         Alias = "anEntity"
     };
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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"
     };
 }
Exemplo n.º 14
0
 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"
     };
 }
        public void Equals_should_return_value_for_class_with_generic_property()
        {
            var first = new GenericProperty <int>();

            first.Prop = 1;
            var second = new GenericProperty <int>();

            second.Prop = 1;
            var third = new GenericProperty <int>();

            third.Prop = 2;

            Assert.True(first.Equals(second));
            Assert.False(first.Equals(third));
        }
Exemplo n.º 16
0
        public void Equality_operator_should_return_true_for_equal_class_with_generic_property()
        {
            var first = new GenericProperty <int>();

            first.Prop = 1;
            var second = new GenericProperty <int>();

            second.Prop = 1;

            Assert.True(first == second);
#pragma warning disable CS1718 // Comparison made to same variable
            // ReSharper disable once EqualExpressionComparison
            Assert.False(first != first);
#pragma warning restore CS1718 // Comparison made to same variable
        }
        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);
        }
        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 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);
        }
        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);
        }
        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);
        }
        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);
        }
Exemplo n.º 23
0
        static void GenerateData()
        {
            PersistenceManager pm = new PersistenceManager();

            pm.BuildDatabase();

            // All primitive types and the storable value types in .NET
            // support the IConvertible interface. You can just store them.
            GenericProperty <string> gp1 = new GenericProperty <string>("String");

            gp1.Value = "StringVal";
            pm.MakePersistent(gp1);
            GenericProperty <decimal> gp2 = new GenericProperty <decimal>("Decimal");

            gp2.Value = 1.23m;
            pm.MakePersistent(gp2);
            GenericProperty <DateTime> gp3 = new GenericProperty <DateTime>("DateTime");

            gp3.Value = DateTime.Now;
            pm.MakePersistent(gp3);
            GenericProperty <int> gp4 = new GenericProperty <int>("Integer");

            gp4.Value = 234;
            pm.MakePersistent(gp4);

            // Any type having a type converter, which can convert to/from string
            // can be stored using this technology.
            GenericProperty <UserDefinedType> gp5 = new GenericProperty <UserDefinedType>("User Defined Type");
            UserDefinedType udt = new UserDefinedType();

            udt.A     = 234;
            udt.B     = 33.3;
            gp5.Value = udt;
            pm.MakePersistent(gp5);

            pm.Save();
        }
Exemplo n.º 24
0
 protected abstract void RenderGenericProperty(GenericProperty prop);
Exemplo n.º 25
0
 protected bool Equals(GenericProperty other)
 {
     return(base.Equals(other) && string.Equals(Type, other.Type) && string.Equals(Definition, other.Definition) && string.Equals(Tab, other.Tab) && Mandatory.Equals(other.Mandatory) && string.Equals(Validation, other.Validation));
 }
Exemplo n.º 26
0
 protected override void RenderGenericProperty(GenericProperty prop)
 {
     WriteIndented($"{prop.AccessModifier.ToString().ToLower()} {prop.DataTypeString} {prop.Name} {{ get; set; }}");
 }
Exemplo n.º 27
0
 protected bool Equals(GenericProperty other)
 {
     return base.Equals(other) && string.Equals(Type, other.Type) && string.Equals(Definition, other.Definition) && string.Equals(Tab, other.Tab) && Mandatory.Equals(other.Mandatory) && string.Equals(Validation, other.Validation);
 }
Exemplo n.º 28
0
 set => this.SetValue(GenericProperty, value);