public void ETagProperty()
        {
            // Create the DSD to register type descriptors
            DomainServiceDescription dsd = DomainServiceDescription.GetDescription(typeof(TMPT_DomainService));

            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(TMPT_MockEntity1));

            PropertyDescriptor descriptor = properties["ETag"];

            Assert.IsNotNull(descriptor,
                             "There should be a property descriptor for ETag.");
            Assert.AreEqual(typeof(string), descriptor.PropertyType,
                            "The ETag type should be a string.");

            EditableAttribute editableAttribute = (EditableAttribute)descriptor.Attributes[typeof(EditableAttribute)];

            Assert.IsNotNull(editableAttribute,
                             "The ETag should have an EditableAttribute.");
            Assert.IsFalse(editableAttribute.AllowEdit,
                           "The ETag should not allow editing.");
            Assert.IsFalse(editableAttribute.AllowInitialValue,
                           "The ETag should not allow an initial value.");

            DisplayAttribute displayAttribute = (DisplayAttribute)descriptor.Attributes[typeof(DisplayAttribute)];

            Assert.IsNotNull(displayAttribute,
                             "The ETag should have an DisplayAttribute.");
            Assert.IsFalse(displayAttribute.AutoGenerateField,
                           "The ETag should not be included in autogeneration.");

            ConcurrencyCheckAttribute concurrencyCheckAttribute = (ConcurrencyCheckAttribute)descriptor.Attributes[typeof(ConcurrencyCheckAttribute)];

            Assert.IsNotNull(concurrencyCheckAttribute,
                             "The ETag should have an ConcurrencyCheckAttribute.");
        }
 private static IDateOnlyFacet Create(DataTypeAttribute attribute, ConcurrencyCheckAttribute concurrencyCheckAttribute, ISpecification holder) =>
 attribute?.DataType == DataType.Date
         ? new DateOnlyFacet(holder)
         : concurrencyCheckAttribute != null
             ? null
             : attribute?.DataType == DataType.DateTime
                 ? null
                 : new DateOnlyFacet(holder);
        private static IDateOnlyFacet Create(DataTypeAttribute attribute, ConcurrencyCheckAttribute concurrencyCheckAttribute, ISpecification holder)
        {
            if (attribute?.DataType == DataType.Date)
            {
                return(new DateOnlyFacet(holder));
            }

            if (concurrencyCheckAttribute != null)
            {
                return(null);
            }

            return(attribute?.DataType == DataType.DateTime ? null : new DateOnlyFacet(holder));
        }
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine("Your model assembly name:");
            var assemblyName = Console.ReadLine();

            var asm     = Assembly.Load(assemblyName);
            var classes = asm.GetTypes().Where(p => p.IsClass).ToList();

            foreach (var item in classes)
            {
                                // Just grabbing this to get hold of the type name:
                                var type = item.GetType();

                                // Get the PropertyInfo object:
                                var properties = item.GetProperties();

                if (HasEFDataAnnotaion(properties))
                {
                    Console.WriteLine("");
                    Console.WriteLine("Found Data Annotations attributes at {0} ...", item.FullName);
                    foreach (var property in properties)
                    {
                        var attributes = property.GetCustomAttributes(false);

                        // Using reflection.
                        Attribute[] attrs = System.Attribute.GetCustomAttributes(property);

                        // Displaying output.
                        foreach (Attribute attr in attrs)
                        {
                            if (attr is KeyAttribute)
                            {
                                KeyAttribute a = (KeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ForeignKeyAttribute)
                            {
                                ForeignKeyAttribute a = (ForeignKeyAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is IndexAttribute)
                            {
                                IndexAttribute a = (IndexAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.GetType().FullName + a.ToString(), property.Name);
                            }

                            if (attr is RequiredAttribute)
                            {
                                RequiredAttribute a = (RequiredAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TimestampAttribute)
                            {
                                TimestampAttribute a = (TimestampAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ConcurrencyCheckAttribute)
                            {
                                ConcurrencyCheckAttribute a = (ConcurrencyCheckAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MinLengthAttribute)
                            {
                                MinLengthAttribute a = (MinLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is MaxLengthAttribute)
                            {
                                MaxLengthAttribute a = (MaxLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is StringLengthAttribute)
                            {
                                StringLengthAttribute a = (StringLengthAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is TableAttribute)
                            {
                                TableAttribute a = (TableAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ColumnAttribute)
                            {
                                ColumnAttribute a = (ColumnAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is DatabaseGeneratedAttribute)
                            {
                                DatabaseGeneratedAttribute a = (DatabaseGeneratedAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }

                            if (attr is ComplexTypeAttribute)
                            {
                                ComplexTypeAttribute a = (ComplexTypeAttribute)attr;
                                Console.WriteLine("attribute {0} on {1} ", a.ToString(), property.Name);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
 private static object[] GetArgs(ConcurrencyCheckAttribute attribute)
 {
     return(new object[] { });
 }