Ejemplo n.º 1
0
        public VariableDeclaration GetVariableDeclaration(string name)
        {
            if (!variables.TryGetValue(name, out VariableDeclaration v))
            {
                var targetType = ResponseType ?? ModelType;

                PropertyInfo modelProperty;
                System.Linq.Expressions.Expression linqExpression;

                var responseProperty = targetType.GetProperty(name);
                if (responseProperty == null)
                {
                    responseProperty = targetType.GetProperty(name.Pascal());
                }

                if (responseProperty == null)
                {
                    throw new RecognitionException("Property not found " + name + " in " + targetType.Name);
                }

                if (ResponseType == null || ResponseType == ModelType)
                {
                    modelProperty  = responseProperty;
                    linqExpression = Parameter;
                }
                else
                {
                    NavigationPropertyAttribute navAttr = responseProperty.GetCustomAttribute <NavigationPropertyAttribute>();
                    if (navAttr != null)
                    {
                        modelProperty  = ModelType.GetProperty(navAttr.NavigationProperty);
                        linqExpression = System.Linq.Expressions.Expression.Property(Parameter, modelProperty);

                        modelProperty = modelProperty.PropertyType.GetProperty(navAttr.Property);
                    }
                    else
                    {
                        modelProperty  = ModelType.GetProperty(name);
                        linqExpression = Parameter;
                    }
                }

                v = new PropertyVariableDeclaration(linqExpression, modelProperty);
                variables.Add(name, v);
            }

            return(v);
        }
Ejemplo n.º 2
0
        public List <string> GetSelectedOptions()
        {
            List <string> names      = new List <string>();
            var           type       = GetType();
            var           properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo info in properties)
            {
                bool value = (bool)info.GetValue(this);
                if (info.PropertyType == typeof(bool) && value)
                {
                    NavigationPropertyAttribute attribute = (NavigationPropertyAttribute)info.GetCustomAttribute(typeof(NavigationPropertyAttribute));
                    names.Add(attribute.NavigationPropertyName);
                }
            }
            return(names);
        }
Ejemplo n.º 3
0
        public override System.Linq.Expressions.Expression GenerateLinqExpression(IASTContext context)
        {
            var leftExp       = Left.GenerateLinqExpression(context);
            var leftModelType = ((PropertyInfo)((System.Linq.Expressions.MemberExpression)leftExp).Member).PropertyType;

            NavigationPropertyAttribute navAttr = pi.GetCustomAttribute <NavigationPropertyAttribute>();

            if (navAttr != null)
            {
                var modelProperty = leftModelType.GetProperty(navAttr.NavigationProperty);
                var linqExp       = System.Linq.Expressions.Expression.Property(leftExp, modelProperty);
                modelProperty = modelProperty.PropertyType.GetProperty(navAttr.Property);
                linqExp       = System.Linq.Expressions.Expression.Property(linqExp, modelProperty);
                return(linqExp);
            }

            var expression = System.Linq.Expressions.Expression.Property(leftExp, pi.Name);

            return(expression);
        }