/// <summary> /// Register a new property for the <see cref="IProvideEditableProperties" /> by convention. The description text key will be <param name="name">name</param>.Description. /// </summary> /// <typeparam name="T">The type of the property</typeparam> /// <param name="provideEditableProperties"> /// The <see cref="IProvideEditableProperties" /> the property should be registered /// to /// </param> /// <param name="property">The expression which points to the property</param> /// <param name="name">The tx key of the display name of the property</param> /// <param name="category">The category of the property</param> /// <returns>Returns the <see cref="provideEditableProperties" /> to allow the fluent usage of this method</returns> public static IProvideEditableProperties RegisterPropertyByConvention <T>(this IProvideEditableProperties provideEditableProperties, Expression <Func <T> > property, string name, string category = null) { provideEditableProperties.RegisterProperty(property, Tx.T(name), $"{name}.Description", category ?? Tx.T("TasksInfrastructure:CreateTask.Common")); return(provideEditableProperties); }
/// <summary> /// Initialize <see cref="Property{T}" /> /// </summary> /// <param name="provideEditableProperties">The object which has the property</param> /// <param name="property">The property</param> /// <param name="name">The dispaly name of the property</param> /// <param name="description">The description of the property</param> /// <param name="category">The category of the property</param> public Property(IProvideEditableProperties provideEditableProperties, Expression <Func <T> > property, string name, string description, string category) { _provideEditableProperties = provideEditableProperties; Name = name; Description = description; Category = category; _propertyInfo = (PropertyInfo)((MemberExpression)property.Body).Member; }
/// <summary> /// Register a new property for the <see cref="IProvideEditableProperties" /> /// </summary> /// <typeparam name="T">The type of the property</typeparam> /// <param name="provideEditableProperties"> /// The <see cref="IProvideEditableProperties" /> the property should be registered /// to /// </param> /// <param name="property">The expression which points to the property</param> /// <param name="name">The display name of the property</param> /// <param name="description">The description of the property</param> /// <param name="category">The category of the property</param> /// <returns>Returns the <see cref="provideEditableProperties" /> to allow the fluent usage of this method</returns> public static IProvideEditableProperties RegisterProperty <T>( this IProvideEditableProperties provideEditableProperties, Expression <Func <T> > property, [LocalizationRequired] string name, [LocalizationRequired] string description, [LocalizationRequired] string category) { provideEditableProperties.Properties.Add(new Property <T>(provideEditableProperties, property, name, description, category)); return(provideEditableProperties); }
private void PropertiesProviderChanged(IProvideEditableProperties propertiesProvider) { if (propertiesProvider != null) { InitializeProperties(propertiesProvider.Properties); } else { Properties = null; } SelectedPropertyItem = null; }
/// <summary> /// Initialize <see cref="Property{T}" /> /// </summary> /// <param name="provideEditableProperties">The object which has the property</param> /// <param name="property">The property</param> /// <param name="name">The dispaly name of the property</param> /// <param name="description">The description of the property</param> /// <param name="category">The category of the property</param> public Property(IProvideEditableProperties provideEditableProperties, Expression <Func <T> > property, string name, string description, string category) { _provideEditableProperties = provideEditableProperties; Name = name; Description = description; Category = category; var memberExpression = (MemberExpression)property.Body; _propertyInfo = (PropertyInfo)memberExpression.Member; var expr = memberExpression.Expression; var memberInfos = new Stack <MemberInfo>(); // https://stackoverflow.com/a/3954131/4166138 // "descend" toward's the root object reference: while (expr is MemberExpression) { var memberExpr = expr as MemberExpression; memberInfos.Push(memberExpr.Member); expr = memberExpr.Expression; } // fetch the root object reference: var constExpr = expr as ConstantExpression; var objReference = constExpr.Value; // "ascend" back whence we came from and resolve object references along the way: while (memberInfos.Count > 0) // or some other break condition { var mi = memberInfos.Pop(); if (mi.MemberType == MemberTypes.Property) { objReference = objReference.GetType() .GetProperty(mi.Name) .GetValue(objReference, null); } else if (mi.MemberType == MemberTypes.Field) { objReference = objReference.GetType() .GetField(mi.Name) .GetValue(objReference); } } _propertyProvidingObject = objReference; }
public PropertyGridSettingsViewModel(IProvideEditableProperties propertiesProvider) { PropertiesProvider = propertiesProvider; }
/// <summary> /// Register a new property for the <see cref="IProvideEditableProperties" /> /// </summary> /// <typeparam name="T">The type of the property</typeparam> /// <param name="provideEditableProperties"> /// The <see cref="IProvideEditableProperties" /> the property should be registered /// to /// </param> /// <param name="property">The expression which points to the property</param> /// <param name="name">The display name of the property</param> /// <param name="description">The description of the property</param> /// <param name="category">The category of the property</param> /// <returns>Returns the <see cref="provideEditableProperties" /> to allow the fluent usage of this method</returns> public static IProvideEditableProperties RegisterProperty <T>(this IProvideEditableProperties provideEditableProperties, Expression <Func <T> > property, string name, string description, string category) { provideEditableProperties.Properties.Add(new Property <T>(provideEditableProperties, property, name, description, category ?? Tx.T("TasksInfrastructure:CreateTask.Common"))); return(provideEditableProperties); }