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


C# Dynamic.ExpandoObject类代码示例

本文整理汇总了C#中System.Dynamic.ExpandoObject的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject类的具体用法?C# ExpandoObject怎么用?C# ExpandoObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpandoObject类属于System.Dynamic命名空间,在下文中一共展示了ExpandoObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Publish_Photo_To_Existing_Album

        public void Publish_Photo_To_Existing_Album()
        {
            #if DEBUG
            string photoPath = @"..\..\..\Facebook.Tests\bin\Debug\monkey.jpg";
            #else
            string photoPath = @"..\..\..\Facebook.Tests\bin\Release\monkey.jpg";
            #endif
            string albumId = ConfigurationManager.AppSettings["AlbumId"];
            byte[] photo = File.ReadAllBytes(photoPath);

            FacebookClient app = new FacebookClient();
            dynamic parameters = new ExpandoObject();
            parameters.access_token = ConfigurationManager.AppSettings["AccessToken"];
            parameters.message = "This is a test photo of a monkey that has been uploaded " +
                                 "by the Facebook C# SDK (http://facebooksdk.codeplex.com)" +
                                 "using the Graph API";
            var mediaObject = new FacebookMediaObject
            {
                FileName = "monkey.jpg",
                ContentType = "image/jpeg",
            };
            mediaObject.SetValue(photo);
            parameters.source = mediaObject;

            dynamic result = app.Post(String.Format("/{0}/photos", albumId), parameters);

            Assert.NotNull(result);
            Assert.NotEqual(null, result.id);
        }
开发者ID:halfpeople,项目名称:Facebook-C--SDK,代码行数:29,代码来源:GraphPublishTests.cs

示例2: SuccessTest1

		public void SuccessTest1()
		{
			using (IDocumentStore documentStore = new EmbeddableDocumentStore
			{
				RunInMemory = true
			}.Initialize())
			{
				dynamic expando = new ExpandoObject();

				using (IDocumentSession session = documentStore.OpenSession())
				{
					session.Store(expando);

					RavenJObject metadata =
						session.Advanced.GetMetadataFor((ExpandoObject)expando);

					metadata[PropertyName] = RavenJToken.FromObject(true);

					session.SaveChanges();
				}

				using (IDocumentSession session = documentStore.OpenSession())
				{
					var loaded =
						session.Load<dynamic>((string)expando.Id);

					RavenJObject metadata =
						session.Advanced.GetMetadataFor((DynamicJsonObject)loaded);
					RavenJToken token = metadata[PropertyName];

					Assert.NotNull(token);
					Assert.True(token.Value<bool>());
				}
			}
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:35,代码来源:LuceneQueryCustomMetadata.cs

示例3: AreExpandoStructureEquals

        public static bool AreExpandoStructureEquals(ExpandoObject obj1, ExpandoObject obj2)
        {
            var obj1AsColl = (ICollection<KeyValuePair<string, object>>)obj1;
            var obj2AsDict = (IDictionary<string, object>)obj2;

            // Make sure they have the same number of properties
            if (obj1AsColl.Count != obj2AsDict.Count)
                return false;

            foreach (var pair in obj1AsColl)
            {
                if (!obj2AsDict.ContainsKey(pair.Key))
                {
                    return false;
                }
                else
                {
                    //if (obj2AsDict[pair.Key].GetType() != pair.Value.GetType())
                    //    return false;
                }

            }

            // Everything matches
            return true;
        }
开发者ID:anwarminarso,项目名称:IDLake,代码行数:26,代码来源:SchemaConverter.cs

示例4: _createKey

		private dynamic _createKey() {
			dynamic key = new ExpandoObject();
			key.b = (Func<string, int>)( p1 => p1.Length );
			key.r = (Func<double, int>)( p1 => (int)Math.Floor( p1 ) );
			key.i = (Func<int, int>)( p1 => key.r( rand.NextDouble() * p1 ) );
			key.j = (Func<int>)( () => 8 );
			key.k = (Func<double, double, double>)( ( p1, p2 ) => (int)p1 ^ (int)p2 );
			key.l = (Func<string, int, int, double>)( ( p1, p2, p3 ) => {
				double d;
				if ( double.TryParse( p1.substr( p2, p3 ), out d ) ) {
					return d;
				}
				return double.NaN;
			} );
			key.m = (Func<double, double, double>)( ( p1, p2 ) => p1 - p2 );
			key.n = (Func<double>)( () => key.r( DateTime.Now.getTime() / 1000 ) );
			key.o = (Func<double, double, double>)( ( p1, p2 ) => p2 / p1 );
			key.p = (Func<double, double, double>)( ( p1, p2 ) => p2 % p1 );
			key.q = (Func<double>)( () => 1.44269504088896 );
			key.s = (Func<object, string>)( p1 => p1.ToString() );
			key.t = (Func<object[], string>)( ps => string.Join( "", ps ) );
			key.u = (Func<double, double, double>)( ( p1, p2 ) => p1 + p2 );
			key.v = (Func<int>)( () => 16 );
			key.w = (Func<int>)( () => 2 );
			key.x = (Func<int>)( () => 4 );
			key.y = (Func<int, double>)( p1 => Math.Sqrt( p1 ) );
			key.z = (Func<double, double, double>)( ( p1, p2 ) => p1 * p2 );
			return ( key );
		}
开发者ID:wangxd1213,项目名称:kcapi_in_csharp_impl,代码行数:29,代码来源:PortAPI.cs

示例5: Initialize

		public override void Initialize()
		{
			_viewBag = new ExpandoObject();
			var verb = _context.Request.HttpMethod;
			object methResult = null;
			var allParams = ReadRequestParameters();
			var action = allParams.ContainsKey("action") ? allParams["action"].ToString() : null;
			var requestContentType = _context.Request.ContentType;
			bool hasConverter = _conversionService.HasConverter(requestContentType);

			var routeService = ServiceLocator.Locator.Resolve<IRoutingHandler>();
			var cdd = _controller.WrapperDescriptor;
			for (int index = 0; index < _controller.Instance.Properties.Count; index++)
			{
				var property = _controller.Instance.Properties[index];
				switch (property)
				{
					case ("HttpContext"):
						_controller.Instance.Set(property, _context);
						break;
					case ("Url"):
						_controller.Instance.Set(property, new UrlHelper(_context, routeService));
						break;
					case ("ViewBag"):
						_controller.Instance.Set(property, _viewBag as dynamic);
						break;
					default:
						var prop = cdd.GetProperty(property);
						if (prop.SetterVisibility == ItemVisibility.Public)
						{
							var value = ServiceLocator.Locator.Resolve(prop.PropertyType);
							if (value != null)
							{
								_controller.Instance.Set(property, value);
							}
						}
						break;
				}
			}

			var methods = _controller.GetMethodGroup(action, verb).ToList();


			bool methodInvoked = false;
			foreach (var method in methods)
			{
				if (TryInvoke(method, allParams, _controller.Instance, hasConverter, _context, false,
						out methResult))
				{
					methodInvoked = true;
					break;
				}
			}
			if (!methodInvoked)
			{
				throw new HttpException(404, string.Format("Url '{0}' not found.", _context.Request.Url));
			}

			_enumerableResult = (methResult as IEnumerable<IResponse>).GetEnumerator();
		}
开发者ID:kendarorg,项目名称:Node.Cs.Old,代码行数:60,代码来源:RoutedItemCoroutine.cs

示例6: Execute

        public IEnumerable<dynamic> Execute(int? id)
        {
            var command = new SqlCommand();
            command.Connection = _connection;
            command.CommandText = "SelectEmployees";

            if (id.HasValue)
            {
                var parameter = new SqlParameter
                {
                    Value = id,
                    ParameterName = "@id",
                };

                command.Parameters.Add(parameter);
            }


            var reader = command.ExecuteReader();

            while (reader.Read())
            {
                dynamic record = new ExpandoObject();

                for (var ii = 0; ii < reader.FieldCount; ii++)
                {
                    record[reader.GetName(ii)] = reader[ii];
                }

                yield return record;
            }
        }
开发者ID:kemiller2002,项目名称:StructuredSight,代码行数:32,代码来源:FinishedExample.cs

示例7: Request

 public dynamic Request(string subject, object body)
 {
     object response = null;
     try {
         var token = Guid.NewGuid().ToString();
         dynamic payload = new ExpandoObject();
         payload.subject = subject;
         payload.body = body;
         payload.token = token;
         var json = LowerCaseSerializer.SerializeObject(payload);
         _responseHandlers.TryAdd(token, (msg) => {
             response = msg;
         });
         _serverChatService.SendMessage(json);
         while (response == null) {
             Thread.Sleep(200);
         }
         Action<object> removedItem;
         _responseHandlers.TryRemove(token, out removedItem);
         return (dynamic)response;
     } catch (Exception ex) {
         _onSendException(ex);
     }
     return null;
 }
开发者ID:FishyJ,项目名称:BellyRub,代码行数:25,代码来源:Channel.cs

示例8: ExpandoAsJoin

        public void ExpandoAsJoin()
        {
            var customers = new List<dynamic>();
            for (int i = 0; i < 10; ++i)
            {
                string iter = i.ToString();
                for (int j = 0; j < 3; ++j)
                {
                    dynamic customer = new ExpandoObject();
                    customer.City = "Chicago" + iter;
                    customer.Id = i;
                    customer.Name = "Name" + iter;
                    customer.CompanyName = "Company" + iter + j.ToString();

                    customers.Add(customer);
                }
            }

            var customers2 = new List<dynamic>(customers);

            var result = customers2.Cast<IDictionary<string, object>>().Query<IDictionary<string, object>, IDictionary<string, object>, dynamic>("SELECT this.City FROM this INNER JOIN that ON this.Id = that.Id", customers.Cast<IDictionary<string, object>>());

            var answer = from c2 in customers2
                         join c in customers on c2.Id equals c.Id
                         select c2.City;

            Assert.IsTrue(result.Any());
            Assert.IsTrue(answer.SequenceEqual(result));
        }
开发者ID:purnachandrapilla,项目名称:SqlLinq,代码行数:29,代码来源:DynamicTests.cs

示例9: Index

        public ActionResult Index(string authToken, string noteId)
        {
            if (String.IsNullOrWhiteSpace(authToken)) {
                throw new EverpageException("Argument \"authToken\" is required.");
            }

            if (String.IsNullOrWhiteSpace(noteId)) {
                throw new EverpageException("Argument \"noteId\" is required.");
            }

            authToken = authToken.Trim();
            noteId = noteId.Trim();

            var beginTime = DateTime.Now;

            var noteGuid = ParseNoteGuid(noteId);

            var userStore = GetUserStore();
            var user = GetUser(userStore, authToken);
            var userInfo = GetPublicUserInfo(userStore, user.Username);

            var noteStore = GetNoteStore(userStore, authToken);
            var note = GetNote(noteStore, authToken, noteGuid);

            var loadTime = DateTime.Now - beginTime;

            dynamic model = new ExpandoObject();
            model.Title = note.Title;
            model.Content = ProcessContent(userInfo, note);
            model.LoadTime = loadTime;

            return View(model);
        }
开发者ID:huoxudong125,项目名称:everpage,代码行数:33,代码来源:NoteController.cs

示例10: AddRow_Error_AdditionalElement_DefineOnce

        public void AddRow_Error_AdditionalElement_DefineOnce()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.DefineOnce);
            dynamic row;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            try
            {
                row = new ExpandoObject();
                row.FirstName = "Hans";
                row.LastName = "Meier";
                row.Age = 30;
                row.Street = "Main street";
                table.AddRow(row);

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }
        }
开发者ID:JhonatanSteven,项目名称:DynamicObjects,代码行数:27,代码来源:FunctionsUnitTest.cs

示例11: 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

示例12: AddRows_Error_Rollback

        public void AddRows_Error_Rollback()
        {
            IDynamicTable table = new DynamicTable(DynamicTableType.Expandable);
            dynamic row;
            dynamic rowB;

            //add values
            row = new ExpandoObject();
            row.FirstName = "Hans";
            row.LastName = "Mueller";
            row.Age = 30;
            table.AddRow(row);

            try
            {
                row = new ExpandoObject();
                row.FirstName = "Hans";
                row.LastName = "Meier";
                row.Age = 30;

                rowB = new ExpandoObject();
                rowB.LastName = 50;
                rowB.Street = "Main street";

                table.AddRows(new List<dynamic>(){ row, rowB});

                Assert.Fail();
            }
            catch (ArgumentException)
            {
            }

            //compare
            Assert.AreEqual(1, table.Rows.Count);
        }
开发者ID:JhonatanSteven,项目名称:DynamicObjects,代码行数:35,代码来源:FunctionsUnitTest.cs

示例13: ProcessContent

        public void ProcessContent(IContentPersister persister)
        {
            using (var db = new GameDatabaseContext())
            {
                var repo = new QuestRepository(db);
                var items = repo.GetAll();

                foreach (var item in items)
                {

                    // Save out properties we want to a new object and then persist
                    dynamic persistable = new ExpandoObject();

                    Console.WriteLine("Processing quest with ID {0}", item.Id);

                    persistable.id = item.Id;
                    persistable.name = item.Name;
                    persistable.description = item.Description;

                    persister.Persist(persistable, "\\quests\\{0}.json".FormatWith(item.Id));

                }

            }
        }
开发者ID:gitter-badger,项目名称:OpenORPG,代码行数:25,代码来源:QuestExtractor.cs

示例14: SuccessTest2

		public void SuccessTest2()
		{
			using (IDocumentStore documentStore = new EmbeddableDocumentStore
			{
				RunInMemory = true
			}.Initialize())
			{
				dynamic expando = new ExpandoObject();

				using (IDocumentSession session = documentStore.OpenSession())
				{
					session.Store(expando);

					RavenJObject metadata =
						session.Advanced.GetMetadataFor((ExpandoObject)expando);

					metadata[PropertyName] = RavenJToken.FromObject(true);

					session.SaveChanges();
				}

				using (IDocumentSession session = documentStore.OpenSession())
				{
					dynamic loaded = session.Advanced.LuceneQuery<dynamic>()
						.WhereEquals("@metadata.Raven-Entity-Name",
									 documentStore.Conventions.GetTypeTagName(typeof(ExpandoObject)))
						.FirstOrDefault();

					Assert.NotNull(loaded);
				}
			}
		}
开发者ID:nzdunic,项目名称:ravendb,代码行数:32,代码来源:LuceneQueryCustomMetadata.cs

示例15: ExtractValue

        /// <summary>
        /// Extract value, include extract "Property=Value" formay
        /// </summary>
        private static dynamic ExtractValue(string line, BCONConfig config)
        {
            if (config.ValueSeperator.Any(line.Contains) || config.PropertySeperator.Any(line.Contains))
            {
                dynamic obj = new ExpandoObject();
                string[] parameters = line.Split(config.PropertySeperator, StringSplitOptions.RemoveEmptyEntries);
                foreach (string p in parameters)
                {
                    string[] values = p.Split(config.ValueSeperator, StringSplitOptions.RemoveEmptyEntries);
                    if (values.Length > 1)
                    {
                        (obj as IDictionary<string, dynamic>)[values[0].Trim()] = ExtractValue(values[1].Trim(), config);
                    }
                }

                return obj;
            }

            double doubleValue;
            int intValue;
            if (double.TryParse(line, NumberStyles.Number, null, out doubleValue))
            {
                return doubleValue;
            }

            if (int.TryParse(line, NumberStyles.Number, null, out intValue))
            {
                return intValue;
            }

            return line;
        }
开发者ID:Jarrey,项目名称:BCONParser,代码行数:35,代码来源:BCONParser.cs


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