C# Passing a Class Property Name as String Parameter

C# Passing a Class Property Name as String Parameter

By : Don King
Date : November 22 2020, 02:42 PM
will be helpful for those in need For those who might stumble on this, I took cue from Valentin to utilize dictionary and still peruse the static class.
My code as below:
code :
public static class DictionaryOfShuttleState
  static Dictionary<string, string> _dict = new Dictionary<string, string>
    {"Item1", ShuttleState.Item1},
    {"Item2", ShuttleState.Item2},
    {"Item3", ShuttleState.Item3}

  public static string GetDictionaryValue(string keyValue)
    string result;
    if(_dict.TryGetValue(keyValue, out result)
      return result;
      return String.Empty

string testValue = DictionaryOfShuttleState.GetDictionaryValue(itemName);
isTest = (qry == null) ? false : (String.Compare(qry.TestItem, testValue, true) == 0);

Share : facebook icon twitter icon
Passing parameter to class property in Java

Passing parameter to class property in Java

By : Sruthi Johny
Date : March 29 2020, 07:55 AM
like below fixes the issue What you've got in the .NET code is an indexer in C# terms. There's no equivalent in Java - you'll just need to take two parameters:
code :
public void setUpdateField(String idField, String pParam) {
Passing a class property as a parameter

Passing a class property as a parameter

By : user3580104
Date : March 29 2020, 07:55 AM
This might help you I'd like to pass a class property (or a getter/setter if need be) reference to a function. , You could use a Func as parameter:
code :
public Flags[] getAllWhereAisTrue(Flags[] array, Func<Flags, bool> propertySelector)
    List<Flags> resultList = new List<Flags>();
    for (int i = 0; i < array.Length; i++)
        if (propertySelector(array[i])) // for each Flags for which a is true
        {                       // add it to the results list
    return resultList.ToArray(); //return the results list as an array
var allAFlagsSet = getAllWhereAisTrue(flagsArray, x=> x.a);
var allAFlagsSet = flagsArray.Where(x=> x.a).ToArray();
Passing class property as a parameter of a method

Passing class property as a parameter of a method

By : Tanya Hrushenko
Date : March 29 2020, 07:55 AM
it should still fix some issue If you don't have any particular reason why you want to actually pass the property, you can just pass the value of that property:
code :
private void setLabel (Label label, object propertyValue)
    label.Text = propertyValue.ToString();
setLabel(myLabel, user.ThePropertyIWant);
Passing class as parameter in C# and then wanting to access property of class

Passing class as parameter in C# and then wanting to access property of class

By : kahwooi
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I'm trying to refactor some code as I have about 7 occurrences of code like this: , you can try something like this
code :
private void ResetPreferredImage<T>(int ID) where T : BaseClass,new()
            List<T> results = DBConnection.Table<T>().Where(t => (int)t.PreferredImage == ID).ToList(); 
How to create a Lazy property passing a string property of <this> class as parameter to it in C#?

How to create a Lazy property passing a string property of <this> class as parameter to it in C#?

By : Piethon
Date : March 29 2020, 07:55 AM
Does that help You can use the factory overload of Lazy to achieve this. This also means that the instantiation must, as Zohar's comment suggests, be moved to the constructor, as non static fields cannot be referenced from field initializers.
code :
public class Item
    private Lazy<BOM> _BOM;

    public Item(string name)
        this.Name = name;
        _BOM = new Lazy<BOM>(() => new BOM(Name));
    public string Name { get; private set; }
    public BOM BOM { get { return _BOM.Value; } }

public class BOM
    public BOM(string name)
Related Posts Related Posts :
  • validation rule needed for only numbers to be entered
  • Parsing complex XML, no descendent elements exists when selecting a named element
  • Web Api - IEnumerable with complex type as param is null
  • Email address input validation
  • .Net AND operator Regular Expression using strings in a document
  • Windows phone 8.1 POST x-www-form-urlencoded not working
  • Is there any way to make my C# XMLManager work?
  • ASP.NET 5 Console Application (package) - How to create DBContext from connection string?
  • How to use form's function in other class C#
  • WPF Zebra EPL2 Printing issue
  • C# use reflection to capture exception throw
  • Convert strings in DataRow to double
  • Xml-Serialization is not working
  • HTML Agility Pack can't find classes with trailing spaces
  • ComputeHash Calls Inexplicably Differ
  • Creating an array that holds both integers and datetime C#
  • GroupBy multiple columns in Linq with Take()
  • Rename multiple symbols at once? (using Roslyn)
  • Cast lambda in delegate
  • DataContractSerializer using default properties
  • LINQ Query Sum in recordset
  • change left-hand boolean value to be opposite of the right hand value
  • Get node from XmlDocument using xpath
  • Why does a Control's BeginInvoke() target delegate never occur after Dispose() is called on the Control?
  • A pattern for returning an object created by multiple repositories
  • Change Tracking in Excel
  • MVC5 Compilation Bug
  • where I need to set my await compared to the code
  • How to make the transition from "traditional" to reactive MVVM
  • Exception when calling RDORecipients.AddMultiple(ref Array, object) in Redemption
  • Switch a Task<T> where T is an enum
  • c# neo4j cypher use regular exp
  • Calling a method from a LINQ select
  • LINQ Specified Cast is Not Valid with a ushort Table Column
  • Why does ReSharper recommend the removal of its own fix?
  • WPF UserControl with nullable dependency property dependent on checkbox value
  • Generating a random number and putting it in a TextBlock
  • Convert datetime string with this format: (yyyy-MM-dd'T'hh:mm:ss-zzz)
  • Check for True or Null value in Linq to Entity
  • Overload resolution, extension methods and genericity in C#
  • Mono can't load Facebook library (from NuGet)
  • Enumerating sql server instances
  • How to avoid duplicate primary key in Entity Framework manual Insert?
  • Shift + F10 in TextBox KeyDown event
  • Failed to assign to property 'Windows.UI.Xaml.Controls.ContentControl.Content'
  • Factory Pattern without a Switch or If/Then
  • c# How to make smooth arc region using graphics path
  • How to Optimize Reactive implementation of recursive function
  • Encrypted connection string can not be decrypted
  • How to know if a user can read and list files of a directory
  • Add a background colour to a MediaComposition
  • How to get a list of recently edited files?
  • System.ArgumentOutOfRangeException linq c#
  • Uri canonicalization compacting FTP scheme
  • Detecting foreign key conflicts
  • Autofac multiple database support
  • 'System.NullReferenceException'
  • Set a different language for ASP.NET MVC errors
  • checkbox checked or click event not firing in datatemplate
  • Get Current Executable Directory On Map Drive
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co