本文整理汇总了C#中System.Dynamic.ExpandoObject.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject.Add方法的具体用法?C# ExpandoObject.Add怎么用?C# ExpandoObject.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Dynamic.ExpandoObject
的用法示例。
在下文中一共展示了ExpandoObject.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertTo
public void ConvertTo()
{
IDictionary<string,object> TestObject = new ExpandoObject();
TestObject.Add("A", "This is a test");
TestObject.Add("B", 10);
TestClass Result = TestObject.To<IDictionary<string, object>, TestClass>();
Assert.Equal(10, Result.B);
Assert.Equal("This is a test", Result.A);
}
示例2: CreateDto
public dynamic CreateDto(Entity entity)
{
var result = new ExpandoObject() as IDictionary<string, object>;
result.Add("Id", entity.Id);
foreach (var component in entity.Components)
{
result.Add(component.GetType().Name, component);
}
return result;
}
示例3: TraverseSelectorNodes
private dynamic TraverseSelectorNodes(
object responseNode, List<FieldSelectorTreeNode> selectorNodes, string parentSelectorPath)
{
if (responseNode == null)
{
return null;
}
var asEnumerable = responseNode as IEnumerable;
if (asEnumerable.IsGenericEnumerable())
{
return TraverseEnumerableObject(asEnumerable, selectorNodes, parentSelectorPath);
}
var expandoObject = new ExpandoObject() as IDictionary<string, object>;
foreach (FieldSelectorTreeNode fieldSelectorTreeNode in selectorNodes)
{
KeyValuePair<string, object> value = TraverseSingleObject(
responseNode,
fieldSelectorTreeNode,
parentSelectorPath
);
if (value.Value != null)
{
expandoObject.Add(value);
}
}
return expandoObject.Count == 0 ? null : expandoObject;
}
示例4: ToExpando
public static ExpandoObject ToExpando(this object anonymousObject) {
IDictionary<string, object> anonymousDictionary = new RouteValueDictionary(anonymousObject);
IDictionary<string, object> expando = new ExpandoObject();
foreach (var item in anonymousDictionary)
expando.Add(item);
return (ExpandoObject)expando;
}
示例5: ToExpando
public static ExpandoObject ToExpando(this object anonymousObject)
{
IDictionary<string, object> anonymousDictionary = new RouteValueDictionary(anonymousObject);
IDictionary<string, object> expando = new ExpandoObject();
foreach (var item in anonymousDictionary)
{
object value = null;
var ie = item.Value as IEnumerable;
if (ie != null && ie.GetType().Name.Contains("AnonymousType"))
{
var list = new List<ExpandoObject>();
foreach (var i in ie)
list.Add(i.ToExpando());
value = list;
}
else
{
value = item.Value;
}
expando.Add(new KeyValuePair<string, object>(item.Key, value));
}
return (ExpandoObject)expando;
}
示例6: ParseFromRow
private ExpandoObject ParseFromRow(Row row, ISheetDefinition sheetDefinition)
{
IDictionary<string, object> expando = new ExpandoObject();
var cells = row.Elements<Cell>().ToList();
var colDefs = sheetDefinition.ColumnDefinitions.ToList();
var count = Math.Max(cells.Count, colDefs.Count);
for (var index = 0; index < count; index++)
{
var colDef = index < colDefs.Count ? colDefs[index] : null;
var cell = index < cells.Count ? cells[index] : null;
string propName;
object propValue;
if (cell != null)
{
propName = cell.GetMdsolAttribute("propertyName");
propValue = _converterManager.GetCSharpValue(cell);
}
else if (colDef != null)
{
propName = colDef.PropertyName;
propValue = null;
}
else
{
throw new NotSupportedException("Cell and CellDefinition are both null");
}
expando.Add(propName, propValue);
}
return (ExpandoObject) expando;
}
示例7: Match
public bool Match(BreadcrumbsContext context)
{
var patterns = BreadcrumbsService.GetPatterns();
// Look up a provider matching the current URL
PatternMatch matchResult = null;
var match = patterns
.ToList()
.FirstOrDefault(p => context.Paths.Any(path => _patterns.TryMatch(path, p.Pattern, out matchResult)));
// Set the provider to the matching one and return false, which means
// continuing with provider matching.
if (match != null)
{
IDictionary<string, object> groups = new ExpandoObject();
context.Provider = match.Provider;
foreach (var group in matchResult.Groups)
groups.Add(group.Key, group.Value);
context.Properties["Groups"] = groups;
context.Properties["Pattern"] = match.Pattern;
}
return false;
}
示例8: Configuration
public Configuration()
{
var awsConfig = string.Format("{0}/.aws/config", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
var confinternal = new ExpandoObject() as IDictionary<string, object>;
if (File.Exists(awsConfig))
{
using (var str = new StreamReader(awsConfig))
{
string line = null;
do
{
line = str.ReadLine();
if (line == null)
continue;
var parts = line.Split(new[] { '=' });
if (parts.Count() == 2)
{
confinternal.Add(parts[0].Trim(), parts[1].Trim());
}
} while (line != null);
}
}
dynamic conf = confinternal;
Region = conf.region;
AWSAccessKey = conf.aws_access_key_id;
AWSSecretKey = conf.aws_secret_access_key;
}
示例9: DropMessageInternal
protected override void DropMessageInternal(IIntegrationMessage integrationMessage)
{
DateTime nowUtc = DateTime.UtcNow;
StreamReader streamReader;
dynamic expando;
IDictionary<string, object> associative;
MongoCollection<BsonDocument> collection;
expando = new ExpandoObject();
associative = new ExpandoObject();
streamReader = new StreamReader(integrationMessage.DataStream);
foreach (KeyValuePair<string, object> metadata in integrationMessage.Metadata)
associative.Add(metadata.Key, metadata.Value.SafeToString(null, null));
expando.Id = integrationMessage.RunTimeId;
expando.CreationTimestamp = nowUtc;
expando.ModificationTimestamp = nowUtc;
expando.Charset = integrationMessage.ContentEncoding = streamReader.CurrentEncoding.WebName;
expando.ContentType = integrationMessage.ContentType;
expando.MessageClass = "unknown";
expando.MessageStateId = new Guid(MessageStateConstants.MESSAGE_STATE_CREATED);
expando.MessageText = streamReader.ReadToEnd(); // TODO: inefficient buffered approach
expando.Metadata = (IDictionary<string, object>)associative;
expando = new BsonDocument((IDictionary<string, object>)expando);
collection = this.AquireMessageCollection();
collection.Insert(expando);
}
示例10: AsExpando
/// <summary>
/// Convert object to expando object.
/// Copy properties from object using reflection.
/// </summary>
/// <param name="item">source instance</param>
/// <returns>expando clone</returns>
public static ExpandoObject AsExpando(this object item)
{
var dictionary = new ExpandoObject() as IDictionary<string, object>;
foreach (var propertyInfo in item.GetType().GetProperties())
dictionary.Add(propertyInfo.Name, propertyInfo.GetValue(item, null));
return (ExpandoObject)dictionary;
}
示例11: AddEnumSources
private object AddEnumSources(object result)
{
var enums = result.GetType().GetProperties().Where(e => e.PropertyType.IsEnum || (e.PropertyType.IsGenericType && e.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) && typeof(Enum).IsAssignableFrom(e.PropertyType.GetGenericArguments()[0])));
if (enums.Any())
{
var xpando = new ExpandoObject() as IDictionary<string, Object>;
foreach (var type in result.GetType().GetProperties())
xpando.Add(type.Name, type.GetValue(result));
foreach (var enumProp in enums)
{
var dict = new List<KeyValuePair<string, string>>();
foreach (Enum enumValue in Enum.GetValues(enumProp.PropertyType.IsGenericType ? enumProp.PropertyType.GetGenericArguments()[0] : enumProp.PropertyType))
{
dict.Add(new KeyValuePair<string, string>(enumValue.ToString(), enumValue.GetDescription()));
}
xpando.Add(new KeyValuePair<string, object>(enumProp.Name + "Source", dict));
}
return (dynamic)xpando;
}
else
return result;
}
示例12: ToExpando
public static ExpandoObject ToExpando(this Object anonymousObject)
{
var dict = new RouteValueDictionary(anonymousObject);
IDictionary<String, Object> eo = new ExpandoObject();
foreach (var item in dict) eo.Add(item);
return (ExpandoObject)eo;
}
示例13: Encrypt_PopulatedObject_Success
public void Encrypt_PopulatedObject_Success()
{
Assert.DoesNotThrow(() =>
{
var settings = new ProjectSettingsProviderEnv();
dynamic secOps = new ExpandoObject();
IDictionary<string, object> filter = new ExpandoObject();
filter.Add("property_name", "account_id" );
filter.Add("operator", "eq" );
filter.Add("property_value", 123 );
secOps.filters = new List<object>(){ filter };
secOps.allowed_operations = new List<string>(){ "read" };
});
}
示例14: GetExpandoObject
static IDictionary<string, object> GetExpandoObject(object value)
{
IDictionary<string, object> expando = new ExpandoObject();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
expando.Add(property.Name, property.GetValue(value));
return expando;
}
示例15: ExpandoPropertiesTest
public void ExpandoPropertiesTest()
{
var x = new ExpandoObject() as IDictionary<string, Object>;
x.Add("NewProp", "test");
dynamic model = x as dynamic;
Assert.AreEqual(model.NewProp, "test");
}