예제 #1
0
        public Column(System.Reflection.PropertyInfo propertyInfo)
        {
            bool isPrimaryKey = propertyInfo.Name.ToLower() == "id";

            bool isRequired = isPrimaryKey ||
                              propertyInfo.IsDefined(typeof(RobotBlocks.Annotations.Constraint.Field.Required), false) ||
                              !Column.CanBeNull(propertyInfo.PropertyType);
            int?maximumLength = null;

            object[] lengthAttributes = propertyInfo.GetCustomAttributes(typeof(RobotBlocks.Annotations.Constraint.Field.Length), false);
            foreach (RobotBlocks.Annotations.Constraint.Field.Length lengthConstraint in lengthAttributes)
            {
                if (lengthConstraint != null)
                {
                    maximumLength = lengthConstraint.Maximum;
                    break;
                }
            }

            bool isUnique = propertyInfo.IsDefined(typeof(RobotBlocks.Annotations.Constraint.Field.Unique), false);

            string defaultValue = null;

            object[] defaultAttributes = propertyInfo.GetCustomAttributes(typeof(RobotBlocks.Annotations.Constraint.Field.Default), false);
            foreach (RobotBlocks.Annotations.Constraint.Field.Default defaultConstraint in defaultAttributes)
            {
                if (defaultConstraint != null)
                {
                    defaultValue = defaultConstraint.Value;
                    break;
                }
            }
            Name = propertyInfo.Name;
            UnderlyingSystemType = propertyInfo.PropertyType.UnderlyingSystemType;
            Length       = maximumLength;
            IsRequired   = isRequired;
            IsPrimaryKey = isPrimaryKey;
            IsUnique     = isUnique;
            DefaultValue = defaultValue;
        }
예제 #2
0
        protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, System.Collections.Generic.IDictionary <object, object> items)
        {
            Check.NotNull <DbEntityEntry>(entityEntry, "entityEntry");
            DbEntityValidationResult dbEntityValidationResult = base.ValidateEntity(entityEntry, items);
            DbEntityValidationResult result;

            if (dbEntityValidationResult.IsValid)
            {
                result = dbEntityValidationResult;
            }
            else
            {
                System.Collections.Generic.List <string> unverifiedPropertyList = new System.Collections.Generic.List <string>();
                System.Reflection.PropertyInfo[]         properties             = entityEntry.Entity.GetType().GetProperties();
                System.Reflection.PropertyInfo[]         array = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = array[i];
                    if (propertyInfo.IsDefined(typeof(NotMappedAttribute), false))
                    {
                        unverifiedPropertyList.Add(propertyInfo.Name);
                    }
                    if (entityEntry.State == EntityState.Unchanged && propertyInfo.IsDefined(typeof(UnmodifiableAttribute), false))
                    {
                        if (!unverifiedPropertyList.Contains(propertyInfo.Name))
                        {
                            unverifiedPropertyList.Add(propertyInfo.Name);
                        }
                    }
                }
                result = new DbEntityValidationResult(entityEntry,
                                                      from r in dbEntityValidationResult.ValidationErrors
                                                      where !unverifiedPropertyList.Contains(r.PropertyName)
                                                      select r);
            }
            return(result);
        }
예제 #3
0
        public void InitializeDatabase(T context)
        {
            foreach (System.Reflection.PropertyInfo current in
                     from p in typeof(T).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)
                     where p.PropertyType.Name == typeof(DbSet).Name
                     select p)
            {
                System.Type type          = current.PropertyType.GetGenericArguments().Single <System.Type>();
                string      realTableName = DescriptionInitializer <T> .GetRealTableName(context, type);

                DescriptionInitializer <T> .AddTableDescription(context, type, realTableName);

                System.Reflection.PropertyInfo[] properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                for (int i = 0; i < properties.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = properties[i];
                    if (!propertyInfo.IsDefined(typeof(NotMappedAttribute), false))
                    {
                        DescriptionInitializer <T> .AddColumnDescription(context, propertyInfo, realTableName);
                    }
                }
            }
        }
예제 #4
0
        private void SerializeCustomObject(object o, System.Text.StringBuilder sb, int depth, System.Collections.Hashtable objectsInUse, JavaScriptSerializer.SerializationFormat serializationFormat)
        {
            bool flag = true;

            System.Type type = o.GetType();
            sb.Append('{');
            if (this.TypeResolver != null)
            {
                string text = this.TypeResolver.ResolveTypeId(type);
                if (text != null)
                {
                    JavaScriptSerializer.SerializeString("__type", sb);
                    sb.Append(':');
                    this.SerializeValue(text, sb, depth, objectsInUse, serializationFormat);
                    flag = false;
                }
            }
            EntityClassAttribute entityClassAttribute = JavaScriptSerializer.GetEntityClassAttribute(type);

            System.Reflection.FieldInfo[] fields = type.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            System.Reflection.FieldInfo[] array  = fields;
            for (int i = 0; i < array.Length; i++)
            {
                System.Reflection.FieldInfo fieldInfo = array[i];
                if (!fieldInfo.IsDefined(typeof(ScriptIgnoreAttribute), true))
                {
                    if (!flag)
                    {
                        sb.Append(',');
                    }
                    JavaScriptSerializer.SerializeString(JavaScriptSerializer.GetPropertyKey(fieldInfo, entityClassAttribute), sb);
                    sb.Append(':');
                    this.SerializeValue(fieldInfo.GetValue(o), sb, depth, objectsInUse, serializationFormat);
                    flag = false;
                }
            }
            System.Reflection.PropertyInfo[] properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty);
            System.Reflection.PropertyInfo[] array2     = properties;
            for (int i = 0; i < array2.Length; i++)
            {
                System.Reflection.PropertyInfo propertyInfo = array2[i];
                if (!propertyInfo.IsDefined(typeof(ScriptIgnoreAttribute), true))
                {
                    System.Reflection.MethodInfo getMethod = propertyInfo.GetGetMethod();
                    if (!(getMethod == null))
                    {
                        if (getMethod.GetParameters().Length <= 0)
                        {
                            if (!flag)
                            {
                                sb.Append(',');
                            }
                            JavaScriptSerializer.SerializeString(JavaScriptSerializer.GetPropertyKey(propertyInfo, entityClassAttribute), sb);
                            sb.Append(':');
                            this.SerializeValue(getMethod.Invoke(o, null), sb, depth, objectsInUse, serializationFormat);
                            flag = false;
                        }
                    }
                }
            }
            sb.Append('}');
        }
 public bool IsDefined(CType type, bool inherit)
 {
     return(internalInfo.IsDefined(type, inherit));
 }