internal bool TryGetMember(string memberName, out object result)
        {
            result = null;

            // Try to get the row index
            if (TryGetRowIndex(memberName, out result))
            {
                return(true);
            }

            // Try to evaluate the dynamic member based on the name
            if (_dynamic != null && DynamicHelper.TryGetMemberValue(_dynamic, memberName, out result))
            {
                return(true);
            }

            // Support '.' for navigation properties
            return(TryGetComplexMember(_value, memberName, out result));
        }
Esempio n. 2
0
        private static IEnumerable <string> GetDefaultColumnNames(
            IEnumerable <dynamic> source,
            Type elementType
            )
        {
            var dynObj = source.FirstOrDefault() as IDynamicMetaObjectProvider;

            if (dynObj != null)
            {
                return(DynamicHelper.GetMemberNames(dynObj));
            }
            else
            {
                return((
                           from p in elementType.GetProperties()
                           where IsBindableType(p.PropertyType) && (p.GetIndexParameters().Length == 0)
                           select p.Name
                           )
                       .OrderBy(n => n, StringComparer.OrdinalIgnoreCase)
                       .ToArray());
            }
        }
Esempio n. 3
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            var values      = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            var memberNames = DynamicHelper.GetMemberNames(obj);

            // This should never happen
            Debug.Assert(memberNames != null);

            // Get the value for each member in the dynamic object
            foreach (string memberName in memberNames)
            {
                object value     = DynamicHelper.GetMemberValue(obj, memberName);
                var    jsonValue = value as DynamicJsonArray;
                if (jsonValue != null)
                {
                    value = (object[])jsonValue;
                }
                values[memberName] = value;
            }

            return(values);
        }