当前位置: 首页>>代码示例>>C#>>正文


C# ExpandoObject.Add方法代码示例

本文整理汇总了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);
 }
开发者ID:modulexcite,项目名称:Craig-s-Utility-Library,代码行数:9,代码来源:ExpandoTypeConverter.cs

示例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;
		}
开发者ID:tolemac,项目名称:RosWorld,代码行数:12,代码来源:SrvEntityDtoCreator.cs

示例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;
        }
开发者ID:piotr-g,项目名称:ServiceStack.PartialResponse,代码行数:33,代码来源:PartialResponsinator.cs

示例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;
 }
开发者ID:afgbeveridge,项目名称:Quorum,代码行数:7,代码来源:Extensions.cs

示例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;
        }
开发者ID:mikalai-silivonik,项目名称:bnh,代码行数:25,代码来源:SinglePageAttribute.cs

示例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;
        }
开发者ID:echen-mdsol,项目名称:Medidata.Cloud.Tsdv.Loader,代码行数:31,代码来源:SheetParser.cs

示例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;
        }
开发者ID:Timbioz,项目名称:SciGitAzure,代码行数:26,代码来源:PatternBasedBreadcrumbsProvider.cs

示例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;
        }
开发者ID:MikeBeastall,项目名称:JustSaying,代码行数:28,代码来源:Configuration.cs

示例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);
		}
开发者ID:textmetal,项目名称:main,代码行数:32,代码来源:MongoDbMessageStore.cs

示例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;
		}
开发者ID:dstimac,项目名称:revenj,代码行数:13,代码来源:ExpandoHelper.cs

示例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;
        }
开发者ID:rafabertholdo,项目名称:escolashaolin,代码行数:25,代码来源:DynamicDataController.cs

示例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;
 }
开发者ID:bipson,项目名称:aic1-2,代码行数:7,代码来源:ExpandoHelper.cs

示例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" };
            });
        }
开发者ID:kidchenko,项目名称:keen-sdk-net,代码行数:16,代码来源:ScopedKeyTest.cs

示例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;
 }
开发者ID:rodrickyu,项目名称:Octopus-Tools,代码行数:7,代码来源:DynamicExtensions.cs

示例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");
 }
开发者ID:paralect,项目名称:setty,代码行数:7,代码来源:ApplicationTest.cs


注:本文中的System.Dynamic.ExpandoObject.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。