logo
down
shadow

How to set property values for indexers using Expressions?


How to set property values for indexers using Expressions?

Content Index :

How to set property values for indexers using Expressions?
Tag : chash , By : MikeG
Date : November 29 2020, 04:01 AM

will be helpful for those in need I think I see what you are attempting - a single SetPropertyValue extension that works for regular and indexed properties. In that case you need to determine the type of reference in the passed in Expression to determine how to call SetValue:
public static void SetPropertyValue<T, TValue>(this T target, Expression<Func<T,TValue>> memberFn, TValue value) {
    var b = memberFn.Body;
    if (b is MethodCallExpression bc && bc.Method.IsSpecialName && bc.Method.Name.StartsWith("get_")) {
        var PI = typeof(T).GetProperty(bc.Method.Name.Substring(4));
        PI.SetValue(target, value, bc.Arguments.Select(a => a.Evaluate<object>()).ToArray());
    }
    else if (b is MemberExpression bm) {
        var pi = bm.Member;
        pi.SetValue(target, value);
    }
}
public static void SetPropertyValue<T, TValue>(this T target, Expression<Func<T,TValue>> memberFn, TValue value) {
    var b = memberFn.Body;
    if (b is MethodCallExpression bc && bc.Method.IsSpecialName) {
        var PI = typeof(T).GetProperties().First(pi => bc.Method.Name.Contains(pi.Name));
        PI.SetValue(target, value, bc.Arguments.Select(a => a.Evaluate<object>()).ToArray());
    }
    else if (b is MemberExpression bm) {
        var pi = bm.Member;
        pi.SetValue(target, value);
    }
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

protobuf-net property indexers


Tag : development , By : arbeitandy
Date : March 29 2020, 07:55 AM
this will help 2 options present themselves:
if the generated code is a partial class, you can create a second partial class file for the same type, and add the attributes there - this is then part of the same type; in particular, note that [ProtoPartialMember(...)] can be added to a type (multiple times), but describes a member; or if you want less maintenance, [ProtoContract(ImplicitFields=ImplicitFields.AllPublic)] can be used to let the model take control of the rules (but please read the intellisense remarks on ImplicitFields before doing this)
var metaType = RuntimeTypeModel.Default.Add(yourType, false);
// TODO: some reflection that decides what members you want to serialize
// and as what keys
foreach(...)
    metaType.Add(member, key);

Can Indexers of a property work in xaml binding in windows phone 8?


Tag : chash , By : lwl_seu
Date : March 29 2020, 07:55 AM
Does that help The XAML code you show is fine.
There may be a problem with the DataContext. Maybe the page DataContext has not been set? Or maybe the the DataContext has changed e.g. inside an ItemTemplate
private ObservableCollection<string> _imagePathList = new ObservableCollection<string>();
public ObservableCollection<string> ImagePathList {
    get { return this._imagePathList; }
    set {
        if (this._imagePathList != value)
        {
            this._imagePathList = value;
            // I'm going to assume you have the NotifyPropertyChanged
            // method defined on the view-model
            this.NotifyPropertyChanged();
        }
    }
}
public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}
public class MyViewModelClass : INoftifyPropertyChanged 
{
    ...
}

LINQ+Lambda vs. standard-indexers+foreach - Even MS and Lippert say, indexers are better. And in this case?


Tag : chash , By : dyarborough
Date : March 29 2020, 07:55 AM
seems to work fine First, let me get a bit nitpicky about what LINQ is.
This is LINQ. Language integrated query. You are querying. Reading.
(from t in tabControlOutput.TabPages.Cast<TabPage>()
 from c in t.Controls.OfType<WebBrowser>()
 select c).ToList()
.ForEach(c => c.Navigate(Constants.BlankUrl));

Multiple indexers not allowed error, but they are not indexers


Tag : development , By : gopal
Date : March 29 2020, 07:55 AM
wish helps you That syntax will not work for what you are trying to do. [key: TYPE]: TYPE in Flowtype is syntax for using objects as dictionaries, not syntax for computed property names.
It is also not possible to use typeof in the way you want, because the type is just string, not articles exactly. You'll have to manually put in the names of the keys.

Can we restrict number of indexers for set operator in indexers?


Tag : chash , By : ranja
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com