public override Expression <Func <TModel, bool> > GetExpression <TModel>(IColumn column, ISearch search, ParameterExpression parameterExpression) { var sourcePropertyName = column.Field ?? column.Name; var sourceProperty = GetProperty <TModel> .ByName(sourcePropertyName); var sourcePropertyType = sourceProperty.PropertyType; var sourceNullableType = Nullable.GetUnderlyingType(sourcePropertyType); Expression property = Expression.Property(parameterExpression, sourceProperty); bool canBeConvertedToColumnType = TryConvert(search.Value, out TColumn filterValue); if (canBeConvertedToColumnType) { if (TargetType.Equals(sourcePropertyType)) { Expression valueCheck = Expression.Equal(property, Expression.Constant(filterValue)); return(Expression.Lambda <Func <TModel, bool> >(valueCheck, new ParameterExpression[] { parameterExpression })); } else if (TargetType.Equals(sourceNullableType)) { Expression nullCheck = Expression.NotEqual(property, Expression.Constant(null, sourcePropertyType)); Expression valueCheck = Expression.Equal(property, Expression.Convert(Expression.Constant(filterValue), sourcePropertyType)); //Expression.Lambda return(Expression.Lambda <Func <TModel, bool> >(Expression.AndAlso(nullCheck, valueCheck), new ParameterExpression[] { parameterExpression })); } } return(null); }
/// <summary> /// Parse an assignment expression /// </summary> /// <returns>An assignment expression node or an expression node<</returns> private Expr Assignment() { Expr expr = Or(); if (Match(TokenType.IS)) { // If it's not an assignment, parse equality instead if (MatchNext(TokenType.EQUAL, TokenType.NOT)) { return(Equality()); } // get the variable identifier //Token Name = Previous(); // recursively get the expression to assign Expr value = Assignment(); if (expr is Variable) { Token name = ((Variable)expr).Name; return(new Assign(name, value)); } else if (expr is GetProperty) { GetProperty get = (GetProperty)expr; return(new SetProperty(get.Object, get.Name, value)); } throw new ParsingError(Previous(), "Assignment target is invalid"); } return(expr); }
public GetProperty GetProperty(string obj_code) { GetProperty getExportData = new GetProperty(); using (IDbConnection dbConnection = (new AppDataBase()).connection) { dbConnection.Open(); // IDbTransaction transaction = dbConnection.BeginTransaction(); try { string sql = @"select * from V_FLC_OBJECTPROPERTY where obj_code = :obj_code and lan = 'zn_CN' "; var para = new DynamicParameters(); para.Add(":obj_code", obj_code); getExportData.objects = AppDataBase.Query <V_FLC_OBJECTPROPERTY>(sql, para, null, dbConnection); string sql2 = @"select *from flc_objects objs left join flc_lang lan on lan.key=objs.obj_code||'.'||objs.obj_table where obj_code=:obj_code and lan='zn_CN' and is_main=0 "; getExportData.tables = AppDataBase.Query <ObjectsUnionLang>(sql2, para, null, dbConnection); } catch (Exception e) { throw e; } } return(getExportData); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if ((value is DateTime)) { if ((DateTime)value != DateTime.MinValue) { return(ValidationResult.Success); } } else if ((value != null) && (!string.IsNullOrWhiteSpace(value.ToString()))) { return(ValidationResult.Success); } var model = validationContext.ObjectInstance; var otherPropertyValue = GetProperty.Value(model, otherProperty); if (otherPropertyValue == null) { return(ValidationResult.Success); } if (otherPropertyValue.ToString() == otherPropertyCheckTriggerValue) { return(new ValidationResult($"The {GetDisplayNameAttribute.Value(model, validationContext.MemberName)} field is required.")); } return(ValidationResult.Success); }
private IEnumerable <Expression <Func <TModel, object> > > GetSortExpression(IColumn column, ISort sortValue) { var sourcePropertyName = column.Field ?? column.Name; var sourceProperty = GetProperty <TModel> .ByName(sourcePropertyName); var sourcePropertyType = sourceProperty.PropertyType; var sourceNullableType = Nullable.GetUnderlyingType(sourcePropertyType); if (sourceProperty == null) { throw new DataTablesException(string.Format(CultureInfo.CurrentUICulture, "Cannot find a Get-property with the name '{0}' on type '{1}'", sourcePropertyName, typeof(TModel).FullName)); } var expression = Expression.Property(parameterExpression, sourceProperty); if (sourceNullableType != null) { var hasValueExpression = Expression.Convert(Expression.Property(expression, "HasValue"), typeof(object)); var valueExpression = Expression.Convert(Expression.Property(expression, "Value"), typeof(object)); yield return(Expression.Lambda <Func <TModel, object> >(hasValueExpression, new ParameterExpression[] { parameterExpression })); yield return(Expression.Lambda <Func <TModel, object> >(valueExpression, new ParameterExpression[] { parameterExpression })); } else { yield return(Expression.Lambda <Func <TModel, object> >(expression, new ParameterExpression[] { parameterExpression })); } }
public async override Task <FundingOpportunity> GetAsync(Guid id) { var entity = await PortalContext.Set <FundingOpportunity>() .Include(o => o.FundingOpportunityObjectives) .ThenInclude(fo => fo.Objective) .Include(foer => foer.FundingOpportunityExpectedResults) .ThenInclude(er => er.ExpectedResult) .Include(foec => foec.FundingOpportunityEligibilityCriterias) .ThenInclude(ec => ec.EligibilityCriteria) .Include(fas => fas.EligibleClientTypes) .Include(c => c.FundingProgram) .Include(c => c.FundingOpportunityConsiderations) .ThenInclude(ec => ec.Consideration) .Include(c => c.FundingOpportunityResources) .Include(c => c.FundingOpportunityFrequentlyAskedQuestions) .ThenInclude(ec => ec.FrequentlyAskedQuestion) .Include(c => c.FundingOpportunityInternalUsers) .ThenInclude(ec => ec.InternalUser) .SingleOrDefaultAsync(i => i.FundingOpportunityId == id); if (entity != null) { GetProperty.TrySetProperty(entity, "Lang", _Language); } return(entity); }
public bool explicitType; // store object type with property in file public Property(string name, GetProperty getter, SetProperty setter, PropertyGUI gui) { this.name = name; this.getter = getter; this.setter = setter; this.gui = gui; explicitType = false; }
public void Should_return_null_when_the_subject_property_is_null() { GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.TheB.TheC.Value); var subject = new A(); Assert.AreEqual(null, getValue.Get(subject)); }
/// <summary> /// Returns the value for the property, or the default for the property type if /// the actual property value is unreachable (due to a null reference in the property chain) /// </summary> /// <typeparam name="T">The object type referenced</typeparam> /// <typeparam name="TValue">The property type</typeparam> /// <param name="getValue"></param> /// <param name="obj">The object from which the value should be retrieved</param> /// <returns>The value of the property, or default(TValue) if it cannot be accessed</returns> public static TValue Get <T, TValue>(this GetProperty <T, TValue> getValue, T obj) where T : class { TValue value = default(TValue); getValue(obj, x => value = x); return(value); }
public Property(string name, GetProperty getter, SetProperty setter, PropertyGUI gui, bool explicitType) { this.name = name; this.getter = getter; this.setter = setter; this.gui = gui; this.explicitType = explicitType; }
/// <summary> /// 在魔镜中显示属性,在调用前已确保魔镜处于打开状态。 /// </summary> private void ShowMagicProperty() { if (this.lvwFiles.SelectedItems.Count <= 0) { return; } if (this.lvStatus == ListViewStatus.MP3Artist) { //显示无扩展信息的控件。 this.magicMirror.SetProperties(MagicMode.None, null); return; } string fullName = ""; string extension = Deal.GetExtension(this.lvwFiles.SelectedItems[0].Text); if (this.lvwFiles.SelectedItems[0].ImageIndex != 0) { //非文件夹 if (this.lvStatus == ListViewStatus.File) { fullName = this.lvwFiles.SelectedItems[0].SubItems[1].Text + this.lvwFiles.SelectedItems[0].Text; switch (extension) { case "jpg": this.magicMirror.SetProperties(MagicMode.JPG, GetProperty.GetJPGExif(fullName)); break; case "mp3": this.magicMirror.SetProperties(MagicMode.MP3, GetProperty.GetMP3Tag(fullName)); break; default: this.magicMirror.SetProperties(MagicMode.File, GetProperty.GetFileProperty(fullName)); break; } } else if (this.lvStatus == ListViewStatus.MP3) { fullName = this.lvwFiles.SelectedItems[0].SubItems[8].Text + this.lvwFiles.SelectedItems[0].Text; this.magicMirror.SetProperties(MagicMode.MP3, GetProperty.GetMP3Tag(fullName)); } } else { //文件夹只在文件模式中出现,所以这里不用再判断。 fullName = this.lvwFiles.SelectedItems[0].SubItems[1].Text + this.lvwFiles.SelectedItems[0].Text; //文件夹 this.magicMirror.SetProperties(MagicMode.File, GetProperty.GetDirectoryProperty(fullName)); } }
public void Should_return_the_default_if_array_value_missing() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.Values[0]); var obj = new A(); int value = getter.Get(obj); Assert.AreEqual(0, value); }
/// <summary> /// /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="column"></param> /// <param name="search"></param> /// <param name="parameterExpression"></param> /// <returns></returns> /// <exception cref="NotSupportedException">Thrown when the searchquery is based on an regular expression</exception> public override Expression <Func <TModel, bool> > GetExpression <TModel>(IColumn column, ISearch search, ParameterExpression parameterExpression) { var sourcePropertyName = column.Field ?? column.Name; var sourceProperty = GetProperty <TModel> .ByName(sourcePropertyName); var logicalMethod = TargetType.GetMethod(nameof(string.Contains), new[] { typeof(string), typeof(StringComparison) }); var expression = Expression.Call(Expression.Property(parameterExpression, sourceProperty), logicalMethod, Expression.Constant(search.Value), Expression.Constant(StringComparison.CurrentCultureIgnoreCase)); return(Expression.Lambda <Func <TModel, bool> >(expression, new ParameterExpression[] { parameterExpression })); }
public void Should_return_default_if_the_array_is_null() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value); var obj = new A(); int value = getter.Get(obj); Assert.AreEqual(0, value); }
public void Should_return_default_if_item_missing() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value); A obj = null; int value = getter.Get(obj); Assert.AreEqual(0, value); }
public void Add(string propertyName, GetProperty get) { if (string.IsNullOrEmpty(propertyName) || _Map.ContainsKey(propertyName)) { return; } _Map.Add(propertyName, get); _Properties.Add(propertyName); }
public SimplePropertyHandler(GetProperty <T> Get, SetProperty <T> Set, Primitive delta) { this.Get = Get; this.Set = Set; SetDirection = (b, d, v) => Set(b, v); Increment = (b, v) => Set(b, Get(b).Plus(v)); IncrementDirection = (b, d, v) => Increment(b, Multiply(v, d)); Move = (b, d) => Set(b, Get(b).Plus(Multiply(delta, d))); Reverse = (b) => Set(b, Get(b).Not()); }
public void Should_return_nothing_if_object_is_null() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value); A obj = null; int value = getter.Get(obj); Assert.AreEqual(0, value); }
public float GetHeight(GetProperty getProperty, GUIContent label) { var option = getProperty(OptionPropertyName); var selection = getProperty(m_PropertyNames[option.enumValueIndex]); if (selection != null) { return(EditorGUI.GetPropertyHeight(selection, label, true)); } return(EditorGUIUtility.singleLineHeight); }
public object VisitGetPropertyExpr(GetProperty expr) { object obj = Evaluate(expr.Object); if (obj is HlangClass) { var foundClass = (HlangClass)obj; return(foundClass.Get(expr.Name)); } throw new RuntimeError(expr.Name, "Object is not a class and does not have a property"); }
public void Should_return_default_value_for_null_object_on_value_type_references() { GetProperty <A, int> getValue = SafeProperty <A> .GetGetProperty(x => x.Id); const int expected = 0; A obj = null; int value = getValue.Get(obj); Assert.AreEqual(expected, value); }
public void Should_return_nothing_if_list_is_empty() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value); var obj = new A { TheBs = new List <B>() }; int value = getter.Get(obj); Assert.AreEqual(0, value); }
public bool DoGUI(GetProperty getProperty, Rect position, GUIContent label) { EditorGUI.BeginChangeCheck(); var option = getProperty(OptionPropertyName); var selection = getProperty(m_PropertyNames[option.enumValueIndex]); using (new EditorGUI.IndentLevelScope(-EditorGUI.indentLevel)) { var optionPosition = new Rect( position.x - s_OptionsStyle.fixedWidth - s_OptionsStyle.margin.right + EditorGUIUtility.labelWidth, position.y + s_OptionsStyle.margin.top + s_OptionsStyle.padding.top, s_OptionsStyle.fixedWidth + s_OptionsStyle.margin.right, s_OptionsStyle.lineHeight); if (string.IsNullOrEmpty(label.text)) { optionPosition.x = position.x; position.xMin = optionPosition.xMax; if (selection.hasVisibleChildren) { // leave space for the foldout icon ~= ReorderableArray.PaddingLeft optionPosition.x -= 10; } } var oldOption = m_Values[option.enumValueIndex]; var newOption = EditorGUI.EnumPopup(optionPosition, GUIContent.none, oldOption, s_OptionsStyle); if (!newOption.Equals(oldOption)) { option.enumValueIndex = Convert.ToInt32(newOption); selection = getProperty(m_PropertyNames[option.enumValueIndex]); foreach (var prop in m_PropertyNames) { getProperty(prop).ResetValue(); } } } if (selection != null) { EditorGUI.PropertyField(position, selection, label, true); } return(EditorGUI.EndChangeCheck()); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var model = validationContext.ObjectInstance; var otherPropertyValue = GetProperty.Value(model, otherProperty); if (otherPropertyValue.Equals(value)) { return(ValidationResult.Success); } var memberDisplayName = GetDisplayNameAttribute.Value(model, validationContext.MemberName); var otherPropertyDisplayName = GetDisplayNameAttribute.Value(model, otherProperty); return(new ValidationResult($"{memberDisplayName} must match {otherPropertyDisplayName}.")); }
public virtual void ValidateCreateExpressionCall <TModel>(IColumn column, ISearch search, ParameterExpression parameterExpression) { if (search.IsRegex && SupportsReqularExpressions == false) { throw new NotSupportedException($"The expression creator {this.GetType().FullName} does not support regular expressions."); } var sourcePropertyName = column.Field ?? column.Name; var sourceProperty = GetProperty <TModel> .ByName(sourcePropertyName); if (sourceProperty == null) { throw new ArgumentOutOfRangeException(nameof(column), $"The column '{sourcePropertyName}' is not a property of the model '{typeof(TModel).FullName}'"); } }
public void Should_return_the_value_for_value_types() { GetProperty <A, int> getValue = SafeProperty <A> .GetGetProperty(x => x.Id); const int expected = 123; var obj = new A { Id = expected }; int value = getValue.Get(obj); Assert.AreEqual(expected, value); }
public void Should_work_for_reference_types() { GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.Value); const string expected = "123"; var obj = new A { Value = expected }; string value = getValue.Get(obj); Assert.AreEqual(expected, value); }
public void oiuwer() { GetProperty <A, string> getter = SafeProperty <A> .GetGetProperty(x => x.TheB.Value); var subject = new A { TheB = new B { Value = "123" } }; string id = null; getter(subject, value => { id = value; }); Assert.AreEqual("123", id); }
public void Should_retrieve_a_property_value_when_present() { GetProperty <A, string> getValue = SafeProperty <A> .GetGetProperty(x => x.TheB.TheC.Value); var subject = new A { TheB = new B { TheC = new C { Value = "123" } } }; Assert.AreEqual("123", getValue.Get(subject)); }
public void Should_return_nothing_if_list_entry_is_null() { GetProperty <A, int> getter = SafeProperty <A> .GetGetProperty(x => x.TheBs[0].Value); var obj = new A { TheBs = new List <B> { null } }; Assert.AreEqual(1, obj.TheBs.Count); int value = getter.Get(obj); Assert.AreEqual(0, value); }
public void Once() { _getter = SafeProperty<A>.GetGetProperty(x => x.Id); }
public SafeGetNestedPropertyRunner() { _accessor = SafeProperty<A>.GetGetProperty(x => x.TheB.TheC.Value); }
public ReadOnlyProperty(PropertyInfo property) { Property = property; Get = GetGetMethod(property); }