예제 #1
0
        /// <summary>
        /// Creates a binding for the given settings.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="control"></param>
        /// <param name="propertyName"></param>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Binding CreateBinding(Control control, string propertyName, string expression)
        {
            if (propertyName == null)
            {
                throw new ArgumentNullException("propertyName");
            }
            if (propertyName.Length == 0)
            {
                throw new ArgumentException("'propertyName' is zero-length.");
            }
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (expression.Length == 0)
            {
                throw new ArgumentException("'expression' is zero-length.");
            }

            if (DataSource == null)
            {
                throw new ArgumentNullException("DataSource");
            }

            // get...
            EntityType entityType = this.EntityType;

            if (entityType != null)
            {
                // work out what the expression is...
                EntityViewProperty property = EntityViewProperty.GetViewProperty(entityType, expression);
                if (property is EntityFieldViewProperty)
                {
                    return(new EntityFieldBinding(((EntityFieldViewProperty)property).Field, this.DataSource, propertyName));
                }
                if (property is EntityLinkViewProperty)
                {
                    return(new EntityLinkBinding(((EntityLinkViewProperty)property).Link, this.DataSource, propertyName));
                }
                if (property is EntityBindViewProperty)
                {
                    return(new EntityPropertyBinding(((EntityBindViewProperty)property).Property, this.DataSource, propertyName));
                }
                else
                {
                    throw new NotSupportedException(string.Format(Cultures.Exceptions, "Cannot handle '{0}'.", property));
                }
            }

            // return a default binding...
            return(this.CreateDefaultBinding(propertyName, expression));
        }
예제 #2
0
 public static string GetPropertyString(bool?isMany, EntityViewProperty p, bool?prevIsMany, bool isFirstOrDefault)
 {
     if (isFirstOrDefault)
     {
         return(p.EntityProperty != null
                 ? p.EntityProperty.PropertyName
                 : p.EntityViewViewProperty.EntityProperty.PropertyName);
     }
     if (prevIsMany == null)
     {
         return(p.EntityProperty != null
                 ? p.EntityProperty.PropertyName
                 : p.EntityViewViewProperty.EntityProperty.PropertyName);
     }
     if (isMany == null)
     {
         return(p.EntityProperty != null
                 ? p.EntityProperty.PropertyName
                 : p.EntityViewViewProperty.EntityProperty.PropertyName);
     }
     if (prevIsMany == true)
     {
         return(string.Format("Select(z => z.{0})",
                              p.EntityProperty != null
                     ? p.EntityProperty.PropertyName
                     : p.EntityViewViewProperty.EntityProperty.PropertyName));
     }
     else
     {
         if (isMany == true)
         {
             return(string.Format("Select(z => z.{0})",
                                  p.EntityProperty != null
                         ? p.EntityProperty.PropertyName
                         : p.EntityViewViewProperty.EntityProperty.PropertyName));
         }
         else
         {
             return(p.EntityProperty.PropertyName);
         }
     }
 }