Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

ExpandoObject Add PropertyName and PropertyValue Dynamically

//Here's a method that accepts both a property name and a property value then adds them both to an ExpandoObject:
public ExpandoObject CreateDynamicCustomer(string propertyName, string PropertyValue)
{
  dynamic cust = new ExpandoObject();
  ((IDictionary<string, object>)cust)[propertyName] = PropertyValue;
  return cust;
}

// How it is use
dynamic cust = CreateDynamicCustomer("FullName", "Peter Vogel");
string fname = cust.FullName;

// retrieve the properties added dynamically 
foreach (KeyValuePair<string, object> kvp in ((IDictionary<string, object>) cust))
{
  if (!kvp.Value.GetType().Name.Contains("Action"))
  {
    foreach (KeyValuePair<string, object> kvp in ((IDictionary<string, object>) cust))
    {
      string PropertyWithValue = kvp.Key + ": " + kvp.Value.ToString();
    }
  }
}
Comment

ExpandoObject Add PropertyName and PropertyValue Dynamically

//Here's a method that accepts both a property name and a property value then adds them both to an ExpandoObject:
public ExpandoObject CreateDynamicCustomer(string propertyName, string PropertyValue)
{
  dynamic cust = new ExpandoObject();
  ((IDictionary<string, object>)cust)[propertyName] = PropertyValue;
  return cust;
}

// How it is use
dynamic cust = CreateDynamicCustomer("FullName", "Peter Vogel");
string fname = cust.FullName;

// retrieve the properties added dynamically 
foreach (KeyValuePair<string, object> kvp in ((IDictionary<string, object>) cust))
{
  if (!kvp.Value.GetType().Name.Contains("Action"))
  {
    foreach (KeyValuePair<string, object> kvp in ((IDictionary<string, object>) cust))
    {
      string PropertyWithValue = kvp.Key + ": " + kvp.Value.ToString();
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity color mix 
Csharp :: why does everything reset when switching scene unity 
Csharp :: mongodb custom IIdGenerator 
Csharp :: c# driver.findelement to look for declared variable 
Csharp :: f sharp global variable 
Csharp :: c# webbrowser upload file 
Csharp :: c# predicate 
Csharp :: discord bot c# how to refresh message 
Csharp :: Go Statement in CSharp 
Csharp :: remove loading bars devexpress on callback 
Csharp :: how to subtract two rows asp ne gridview in asp.net 
Csharp :: unity firebase update nodes rank value by sorting value 
Csharp :: how many zeros in quinnonagintillion 
Csharp :: HOW TO CALL AN EXTENSION METHOD FOR VIEW C# 
Csharp :: c# XmlElement from string 
Csharp :: c# check value at design time 
Csharp :: Toggle value change 
Csharp :: build url mvs view 
Csharp :: c# bitwise and 
Csharp :: C# return dictionary string/integer from comparison of List and Array 
Csharp :: list to array f# 
Csharp :: c# convert float to string 
Csharp :: creating an object 
Csharp :: where are the viwes in .net core publish 
Csharp :: copy array to array in c# 
Csharp :: unity create file name datetime 
Csharp :: c# increment by 2 
Csharp :: unity check if swipe not tap 
Csharp :: block wapalyzer from detecting codeigniter 
Csharp :: how to set the forgound color of listitems in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =