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
0
		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;
		}
        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
0
        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;
        }
        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;
        }
Пример #6
0
 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;
 }
        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
0
		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);
		}
Пример #9
0
		/// <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;
		}
        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;
        }
Пример #11
0
 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;
 }
Пример #12
0
        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" };
            });
        }
Пример #13
0
 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;
 }
Пример #14
0
 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");
 }
Пример #15
0
        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;
        }
Пример #16
0
 public static ExpandoObject ToExpando(this object anonymousObject)
 {
     IDictionary<string, object> anonymousDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(anonymousObject);
     IDictionary<string, object> expando = new ExpandoObject();
     foreach (var item in anonymousDictionary)
         expando.Add(item);
     return (ExpandoObject)expando;
 }
Пример #17
0
        public ExpandoObject ToExpandoObject()
        {
            IDictionary<string, object> expando = new ExpandoObject();

            foreach (dynamic field in _allFields)
            {
                if (String.Compare(field.Key, "ProjectShortName", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    expando.Add("project", field.Value);
                }
                else
                {
                    expando.Add(field.Key.ToLower(), field.Value);
                }
            }
            return (ExpandoObject) expando;
        }
Пример #18
0
        private dynamic BuildParameterObject(HttpContext context)
        {
            IDictionary<string, object> parameters = new ExpandoObject();

            foreach (string key in context.Request.Form)
            {
                if (key.Contains("[]"))
                {
                    var values = context.Request.Form.GetValues(key);

                    if (values != null)
                    {
                        parameters.Add(key.Replace("[]", string.Empty), values);
                    }
                }
                else
                {
                    parameters.Add(key, context.Request.Form[key]);
                }
            }

            foreach (string key in context.Request.QueryString)
            {
                if (key.Contains("[]"))
                {
                    var values = context.Request.QueryString.GetValues(key);

                    if (values != null)
                    {
                        parameters.Add(key.Replace("[]", string.Empty), values);
                    }
                }
                else
                {
                    parameters.Add(key, context.Request.QueryString[key]);
                }
            }

            foreach (var item in _requestContext.RouteData.Values)
            {
                parameters.Add(item.Key, item.Value);
            }

            parameters.Add("HttpContext", context);
            return parameters;
        }
Пример #19
0
		public dynamic ToDynamic(object value)
		{
			IDictionary<string, object> expando = new ExpandoObject();

			foreach (var property in _property.All(value))
				expando.Add(property.Name, property.GetValue(value));

			return (ExpandoObject)expando;
		}
        dynamic ToExpandoObject(object obj)
        {
            IDictionary<string, object> expando = new ExpandoObject();

            foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(obj.GetType()))
                expando.Add(property.Name, property.GetValue(obj));

            return expando as ExpandoObject;
        }
Пример #21
0
 /// <summary>
 /// Dictionary<string, object> i.e. fieldname and value
 /// </summary>
 /// <param name="properties"></param>
 /// <returns></returns>
 public static dynamic GetDynamicObject(Dictionary<string, object> properties)
 {
     var dynamicObject = new ExpandoObject() as IDictionary<string, Object>;
     foreach (var property in properties)
     {
         dynamicObject.Add(property.Key, property.Value);
     }
     return dynamicObject;
 }
Пример #22
0
        public static dynamic ToDynamic(this object obj)
        {
            IDictionary<string, object> expando = new ExpandoObject();

            Type type = obj.GetType();

            foreach (PropertyInfo property in type.GetProperties())
            {
                expando.Add(property.Name, property.GetValue(obj));
            }

            foreach (FieldInfo field in type.GetFields())
            {
                expando.Add(field.Name, field.GetValue(obj));
            }

            return expando as ExpandoObject;
        }
Пример #23
0
        public static dynamic ToDynamic(this 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 as ExpandoObject;
        }
        public FormInstance CreateNewFormInstance(Guid formTemplateId, List<KeyValuePair<string, object>> fieldValues)
        {
            var postData = new ExpandoObject() as IDictionary<string, object>;
            foreach (var keyValuePair in fieldValues)
            {
                postData.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return HttpHelper.Post<FormInstance>(GlobalConfiguration.Routes.FormTemplatesIdForms, "", GetUrlParts(), this.ClientSecrets, this.ApiTokens, postData, formTemplateId);
        }
Пример #25
0
        public static ExpandoObject ToExpando(this object @this)
        {
            IDictionary<string, object> expando = new ExpandoObject();

            foreach (var prop in @this.GetType().GetProperties())
            {
                expando.Add(prop.Name, prop.GetValue(@this, null));
            }

            return (ExpandoObject)expando;
        }
Пример #26
0
		/// <summary>
		/// To the expando.
		/// </summary>
		/// <param name="o">The o.</param>
		/// <returns>ExpandoObject.</returns>
        public static ExpandoObject ToExpando(this object o)
        {
            IDictionary<string, object> expando = new ExpandoObject();

            foreach (var propertyInfo in o.GetType().GetProperties())
            { 
                expando.Add(new KeyValuePair<string, object>(propertyInfo.Name, propertyInfo.GetValue(o, index: null))); 
            } 
            
            return (ExpandoObject)expando;
        }
Пример #27
0
        /// <summary>
        /// Converts an object to an ExpandoObject.
        /// </summary>
        /// <param name="anonymousObject">The anonymous object.</param>
        /// <returns>ExpandoObject.</returns>
        internal static ExpandoObject ToExpando(this object anonymousObject)
        {
            IDictionary<string, object> expando = new ExpandoObject();
            foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(anonymousObject))
            {
                var obj = propertyDescriptor.GetValue(anonymousObject);
                expando.Add(propertyDescriptor.Name, obj);
            }

            return (ExpandoObject)expando;
        }
Пример #28
0
        public void 以上()
        {
            var actual = PredicateSql.From<Person>(DbKind.SqlServer, x => x.Id >= 1);

            var expectStatement = "Id >= @p0";
            IDictionary<string, object> expectParameter = new ExpandoObject();
            expectParameter.Add("p0", 1);

            actual.Parameter.Is(expectParameter);
            actual.Statement.Is(expectStatement);
        }
Пример #29
0
        public void Encrypt_64CharKeyWithFilter_Success()
        {
            var settings = new ProjectSettingsProvider("projId", "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");

            IDictionary<string, object> filter = new ExpandoObject();
            filter.Add("property_name", "account_id");
            filter.Add("operator", "eq");
            filter.Add("property_value", 123);

            dynamic secOpsIn = new ExpandoObject();
            secOpsIn.filters = new List<object>() { filter };
            secOpsIn.allowed_operations = new List<string>() { "read" };
            Assert.DoesNotThrow(() =>
            {
                var scopedKey = ScopedKey.Encrypt(settings.MasterKey, (object)secOpsIn);
                var decrypted = ScopedKey.Decrypt(settings.MasterKey, scopedKey);
                var secOpsOut = JObject.Parse(decrypted);
                Assert.True(secOpsIn.allowed_operations[0] == (string)(secOpsOut["allowed_operations"].First()));
            });
        }
        internal virtual object FlattenToObject(DataTable table)
        {
            IDictionary<string, object> result = new ExpandoObject();
            var rows = table.Rows.OfType<DataRow>();
            foreach (var row in rows)
            {
                result.Add(row["Tag"] as string, row["ConfigValue"]);
            }

            return result;
        }
    public static List <dynamic> GetTable()
    {
        string _sql = "Select * from MyTable"
                      List <dynamic> table = null;

        try
        {
            using (SqlConnection _conn = new SqlConnection(HelperData._conn_string))
            {
                _conn.Open();

                using (SqlCommand _cmd = new SqlCommand(_sql, _conn))
                {
                    _cmd.CommandTimeout = 600;

                    using (SqlDataReader reader = _cmd.ExecuteReader())
                    {
                        table = new List <dynamic>();

                        while (reader.Read())
                        {
                            var row = new System.Dynamic.ExpandoObject() as IDictionary <string, Object>;

                            for (int field = 0; field <= reader.FieldCount - 1; field++)
                            {
                                row.Add(reader.GetName(field), reader[field]);
                            }
                            table.Add(row);
                        }
                    }
                }
            }
        }
        catch (Exception ex) { throw ex; }
        return(table);
    }