“ExpandoObject Add PropertyName e PropertyValue Dynamicty” Respostas de código

ExpandoObject Add PropertyName e PropertyValue Dynamicty

//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();
    }
  }
}
Someone who wants to know

ExpandoObject Add PropertyName e PropertyValue Dynamicty

//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();
    }
  }
}
Someone who wants to know

Respostas semelhantes a “ExpandoObject Add PropertyName e PropertyValue Dynamicty”

Perguntas semelhantes a “ExpandoObject Add PropertyName e PropertyValue Dynamicty”

Procure respostas de código populares por idioma

Procurar outros idiomas de código