Exemple #1
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (IsColumns)
     {
         object[] dynamicColumns = DynamicColumns as object[];
         if (dynamicColumns != null)
         {
             int index = Array.IndexOf(Columns, binder.Name);
             if (index >= 0)
             {
                 result = dynamicColumns[index];
             }
             else
             {
                 result = null;
             }
         }
         else
         {
             throw ExceptionManager.MessageException("DynamicColumns为空或类型不正确!");
         }
         return(true);
     }
     return(dic.TryGetValue(binder.Name, out result) || base.TryGetMember(binder, out result));
 }
Exemple #2
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (data != null)
     {
         if (data.ContainsKey(binder.Name))
         {
             result = data[binder.Name];
             if (result is Dictionary <string, object> )
             {
                 result = new JsonData(result as Dictionary <string, object>);
             }
             else if (result is System.Collections.ArrayList)
             {
                 result = new JsonData(result as System.Collections.ArrayList);
             }
             return(true);
         }
         else
         {
             result = data.GetType().InvokeMember(binder.Name, System.Reflection.BindingFlags.GetProperty, null, data, null);
             return(true);
         }
     }
     else
     {
         result = list.GetType().InvokeMember(binder.Name, System.Reflection.BindingFlags.GetProperty, null, list, null);
         return(true);
     }
 }
        // DynamicObject
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            result = null;

            foreach (var t in _columns)
            {
                if (t.Name != binder.Name)
                {
                    continue;
                }

                if (!t.Type.IsInstanceOfType(binder.ReturnType))
                {
                    throw new ArgumentException(
                              $"Property '{binder.Name}' is not an instance of '{binder.ReturnType.FullName}'!");
                }

                if (t.Value == null && Nullable.GetUnderlyingType(binder.ReturnType) == null)
                {
                    throw new ArgumentNullException($"Property '{binder.Name}' cannot be null!");
                }

                result = _columns.Single(c => c.Name == binder.Name).Value;
                return(true);
            }

            throw new ArgumentNullException($"Property '{binder.Name}' does not exist!");
        }
Exemple #4
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     try
     {
         var p = t.GetProperty(binder.Name);
         if (p != null)
         {
             result = p.GetValue(null, null);
         }
         else
         {
             var f = t.GetField(binder.Name);
             if (f != null)
             {
                 result = f.GetValue(null);
             }
             else
             {
                 result = null; return(false);
             }
         }
         return(true);
     }
     catch (SystemException)
     {
         result = null;
         return(false);
     }
 }
Exemple #5
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            if (_dictionary.TryGetValue(binder.Name, out result) == false)
            {
                if (_dictionary.TryGetValue(binder.Name.ToLower(), out result) == false)
                {
                    return(false);// throw new Exception("property not found " + binder.Name);
                }
            }
            if (result is IDictionary <string, object> )
            {
                result = new DynamicJson(result as IDictionary <string, object>);
            }
            else if (result is List <object> )
            {
                List <object> list = new List <object>();
                foreach (object item in (List <object>)result)
                {
                    if (item is IDictionary <string, object> )
                    {
                        list.Add(new DynamicJson(item as IDictionary <string, object>));
                    }
                    else
                    {
                        list.Add(item);
                    }
                }
                result = list;
            }

            return(_dictionary.ContainsKey(binder.Name));
        }
Exemple #6
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            switch (binder.Name)
            {
            case "Attributes":
                result = new SimpleXmlAttributes(_element);
                break;

            case "Value":
                result = _element.Value;
                break;

            default:
                var element = _element.Element(binder.Name);
                if (element == null)
                {
                    result = null;
                }
                else
                {
                    result = new SimpleXmlElement(element);
                }
                break;
            }

            return(result != null);
        }
        /// <summary>
        /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
        /// </summary>
        /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result" />.</param>
        /// <returns>
        /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)
        /// </returns>
        /// <exception cref="NotImplementedException">
        /// </exception>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            MemberInfo member = FindMember(binder.Name);

            //If we have a member then return that
            if (member != null)
            {
                switch (member.MemberType)
                {
                case MemberTypes.Event:
                    //Return an event binder
                    result = new DynamicReflector((EventInfo)member, base.Target)
                    {
                        WrapReturn = this.WrapReturn
                    };
                    break;

                case MemberTypes.Property:
                    //Check if we should wrap the result in another dynamic reflector
                    result = ((PropertyInfo)member).GetValue(base.Target);
                    if (WrapReturn)
                    {
                        result = new DynamicReflector(result)
                        {
                            WrapReturn = this.WrapReturn
                        };
                    }
                    break;

                case MemberTypes.Field:
                    //Check if we should wrap the result in another dynamic reflector
                    result = ((FieldInfo)member).GetValue(base.Target);
                    if (WrapReturn)
                    {
                        result = new DynamicReflector(result)
                        {
                            WrapReturn = this.WrapReturn
                        };
                    }
                    break;

                case MemberTypes.Method:
                    //Return the method info bound to the target object
                    result = new BoundMethodInfo((MethodInfo)member, base.Target);
                    break;

                case MemberTypes.NestedType:
                    //TODO: Implement
                    throw new NotImplementedException();

                default:
                    throw new NotImplementedException();
                }

                return(true);
            }

            return(base.TryGetMember(binder, out result));
        }
Exemple #8
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (!_ChangedTracking.TryGetValue(binder.Name, out result))
     {
         base.TryGetMember(binder, out result);
     }
     return(true);
 }
Exemple #9
0
 /// <summary>
 /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject"/> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
 /// </summary>
 /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject"/> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
 /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result"/>.</param>
 /// <returns>
 /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)
 /// </returns>
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (base.TryGetMember(binder, out result))
     {
         return(this.MassageResultBasedOnInterface(binder.Name, true, ref result));
     }
     return(false);
 }
        /// <summary>
        /// 实现动态对象属性成员访问的方法,得到返回指定属性的值
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var propertyName = binder.Name;
            var property     = DomainProperty.GetProperty(this.ObjectType, propertyName);

            result = GetValue(property);
            return(true);
        }
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     result = _row [binder.Name];
     if (result is DBNull)
     {
         result = null;
     }
     return(true);
 }
Exemple #12
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (this.Dictionary.ContainsKey(binder.Name))
     {
         result = this.Dictionary[binder.Name];
         return(true);
     }
     return(base.TryGetMember(binder, out result));
 }
 /// <summary>
 /// Provides the implementation for operations that get member values.
 /// </summary>
 /// <param name="binder"> Provides information about the object that called the dynamic
 /// operation. </param>
 /// <param name="result"> The result of the get operation. </param>
 /// <returns> <c>true</c> if the operation is successful; otherwise, <c>false</c>. </returns>
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     result = this.obj[binder.Name];
     if (TypeUtilities.IsUndefined(result))
     {
         result = Undefined.Value;
     }
     return(true);
 }
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var a = ViewData.TryGetValue(binder.Name.ToLower(), out result);

            if (!a)
            {
                throw new Exception(string.Format("动态字典Bag不存在索引值:{0}", binder.Name));
            }
            return(a);
        }
Exemple #15
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     result = null;
     if (_dict.ContainsKey(binder.Name))
     {
         result = _dict[binder.Name];
         return(true);
     }
     return(false);
 }
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            string name = binder.Name;

            objMapping.TryGetValue(name, out result);
            if (result == null)
            {
                result = string.Empty;
            }
            return(true);
        }
        /// <summary>
        /// Attempts to access the Fields first, then Metadata.
        /// </summary>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            bool found = Fields.TryGetMember(binder, out result);

            if (!found)
            {
                found = Metadata.TryGetMember(binder, out result);
            }

            return(found);
        }
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var tReturn = base.TryGetMember(binder, out result);

            if (!tReturn)
            {
                return(false);
            }
            result = GetProxy((dynamic)result);
            return(true);
        }
Exemple #19
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            string name = binder.Name.ToLower();

            //return dictionary.TryGetValue(name, out result);
            if (!dictionary.TryGetValue(name, out result))
            {
                result = null;
            }
            return(true);
        }
Exemple #20
0
        public override System.Dynamic.DynamicMetaObject BindGetMember(System.Dynamic.GetMemberBinder binder)
        {
            var parameters = new System.Linq.Expressions.Expression[]
            {
                System.Linq.Expressions.Expression.Constant(binder.Name)
            };

            var callMethod = CallMethod(getValueMethod, parameters);

            return(callMethod);
        }
        /// <summary>
        /// Attempts to get a member of the instance.
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            string name = binder.Name.ToLower();

            if (!_dictionary.ContainsKey(name))
            {
                Logger.Warning(String.Format("Key '{0}' Not Found In ItemFields", name));
                result = null;
                return(true);
            }

            return(_dictionary.TryGetValue(name, out result));
        }
Exemple #22
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (_memberdic.ContainsKey(binder.Name))
     {
         result = _memberdic[binder.Name];
         return(true);
     }
     else
     {
         bool v = base.TryGetMember(binder, out result);
         return(v);
     }
 }
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var name = binder.Name;

            if (!base.TryGetMember(binder, out result) || (null == result))
            {
                // substitute nil results with a robot that turns adds a zone on
                // the parent when .Add is invoked
                result = new ZoneOnDemand(_zoneFactory, this, name);
                TrySetMemberImpl(name, result);
            }

            return(true);
        }
Exemple #24
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var element = _document.Root.Element(binder.Name);

            if (element == null)
            {
                result = null;
            }
            else
            {
                result = new SimpleXmlElement(element);
            }
            return(result != null);
        }
Exemple #25
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var attribute = _element.Attribute(binder.Name);

            if (attribute == null)
            {
                result = null;
            }
            else
            {
                result = attribute.Value;
            }
            return(result != null);
        }
Exemple #26
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            // get index of column value trying to be retrieved
            var idx = getindex(binder.Name);

            // default to empty
            result = string.Empty;
            // return error if we can't find
            if (idx < 0)
            {
                return(base.TryGetMember(binder, out result));
            }
            // get result
            result = Value[idx];
            return(true);
        }
 public static dynamic TryGetProperty(dynamic dynamicObject, String PropertyName, dynamic Default)
 {
     try
     {
         if (!HasProperty(dynamicObject, PropertyName))
         {
             return(Default);
         }
         if (dynamicObject.GetType() == typeof(System.Web.Helpers.DynamicJsonObject))
         {
             // good thing this type of documentation was easy to find
             System.Web.Helpers.DynamicJsonObject obj = (System.Web.Helpers.DynamicJsonObject)dynamicObject;
             Type scope = obj.GetType();
             System.Dynamic.IDynamicMetaObjectProvider provider = obj as System.Dynamic.IDynamicMetaObjectProvider;
             if (provider != null)
             {
                 System.Linq.Expressions.ParameterExpression param = System.Linq.Expressions.Expression.Parameter(typeof(object));
                 System.Dynamic.DynamicMetaObject            mobj  = provider.GetMetaObject(param);
                 System.Dynamic.GetMemberBinder          binder    = (System.Dynamic.GetMemberBinder)Microsoft.CSharp.RuntimeBinder.Binder.GetMember(0, PropertyName, scope, new Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo[] { Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(0, null) });
                 System.Dynamic.DynamicMetaObject        ret       = mobj.BindGetMember(binder);
                 System.Linq.Expressions.BlockExpression final     = System.Linq.Expressions.Expression.Block(
                     System.Linq.Expressions.Expression.Label(System.Runtime.CompilerServices.CallSiteBinder.UpdateLabel),
                     ret.Expression
                     );
                 System.Linq.Expressions.LambdaExpression lambda = System.Linq.Expressions.Expression.Lambda(final, param);
                 Delegate del = lambda.Compile();
                 return(del.DynamicInvoke(obj));
             }
             else
             {
                 return(obj.GetType().GetProperty(PropertyName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(obj, null));
             }
         }
         else if (dynamicObject.GetType() == typeof(System.Collections.IDictionary))
         {
             return((Dictionary <String, object>)dynamicObject[PropertyName]);
         }
         return(Default);
     }
     catch (Exception ex)
     {
         throw new Exception("Could not determine if dynamic object has property.", ex);
     }
 }
Exemple #28
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            result = this.Dictionary[binder.Name];

            if (result is IDictionary <string, object> )
            {
                result = new DynamicJsonObject(result as IDictionary <string, object>);
            }
            else if (result is ArrayList && (result as ArrayList) is IDictionary <string, object> )
            {
                result = new List <DynamicJsonObject>((result as ArrayList).ToArray().Select(x => new DynamicJsonObject(x as IDictionary <string, object>)));
            }
            else if (result is ArrayList)
            {
                result = new List <object>((result as ArrayList).ToArray());
            }

            return(this.Dictionary.ContainsKey(binder.Name));
        }
Exemple #29
0
    public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
    {
        System.Diagnostics.Debug.WriteLine("Enter: ", binder.Name);

        try
        {
            result = _innerType.InvokeMember(
                binder.Name,
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty,
                null, _innerObject, null);
        }
        catch (MissingMemberException)
        {
            return(base.TryGetMember(binder, out result));
        }
        finally
        {
            System.Diagnostics.Debug.WriteLine("Exit: ", binder.Name);
        }
        return(true);
    }
            public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
            {
                if (binder == null)
                {
                    throw new ArgumentNullException("binder");
                }

                var dynamicObject = _model as RazorDynamicObject;

                if (dynamicObject != null)
                {
                    return(dynamicObject.TryGetMember(binder, out result));
                }

                Type modelType = _model.GetType();
                var  prop      = modelType.GetProperty(binder.Name);

                if (prop == null)
                {
                    result = null;
                    return(false);
                }

                object value = prop.GetValue(_model, null);

                if (value == null)
                {
                    result = value;
                    return(true);
                }

                Type valueType = value.GetType();

                result = (TypeHelper.IsAnonymousType(valueType))
                             ? new RazorDynamicObject(value)
                             : value;
                return(true);
            }