Represents the dynamic get member operation at the call site, providing the binding semantic and the details about the operation.
Inheritance: DynamicMetaObjectBinder
        public override DynamicMetaObject BindGetMember(GetMemberBinder binder) {
            ContractUtils.RequiresNotNull(binder, "binder");
            string name = binder.Name;

            if (name == _info.Name) {
                name = "TypeLibDesc";
            } else if (name != "Guid" &&
                name != "Name" &&
                name != "VersionMajor" &&
                name != "VersionMinor") {

                return binder.FallbackGetMember(this);
            }

            return new DynamicMetaObject(
                Expression.Convert(
                    Expression.Property(
                        AstUtils.Convert(Expression, typeof(ComTypeLibInfo)),
                        typeof(ComTypeLibInfo).GetProperty(name)
                    ),
                    typeof(object)
                ),
                ComTypeLibInfoRestrictions(this)
            );
        }
Example #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (_data.ContainsKey(binder.Name))
            {
                result = _data[binder.Name];
                var converted = ConvertResult(result);
                if (!ReferenceEquals(result, converted))
                    _data[binder.Name] = result = converted;

                return true;
            }

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

            if (_database != null)
            {
                var relatedAdapter = _database.GetAdapter() as IAdapterWithRelation;
                if (relatedAdapter != null && relatedAdapter.IsValidRelation(_tableName, binder.Name))
                {
                    result = GetRelatedData(binder, relatedAdapter);
                    return true;
                }
            }
            return base.TryGetMember(binder, out result);
        }
Example #3
0
        public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject instance, out DynamicMetaObject result, bool delayInvocation) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");

            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                var comGetMember = new ComGetMemberBinder(binder, delayInvocation);
                result = instance.BindGetMember(comGetMember);
                if (result.Expression.Type.IsValueType) {
                    result = new DynamicMetaObject(
                        Expression.Convert(result.Expression, typeof(object)),
                        result.Restrictions
                    );
                }
                return true;
            } else {
                result = null;
                return false;
            }
        }
Example #4
0
 public override bool TryGetMember(
     GetMemberBinder binder, out object result)
 {
     result = null;
     if (binder.Name == "Value")
         result = _elements[0].Value;
     else if (binder.Name == "Count")
         result = _elements.Count;
     else
     {
         var attr = _elements[0].Attribute(
             XName.Get(binder.Name ) );
         if (attr != null)
             result = attr.Value;
         else
         {
             var items = _elements.Descendants(
                 XName.Get(binder.Name ) );
             if (items == null || items.Count() == 0)
                 return false;
             result = new DynamicXml( items );
         }
     }
     return true;
 }
Example #5
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (!_dictionary.TryGetValue(binder.Name, out result))
            {
                // return null to avoid exception.  caller can check for null this way...
                result = null;
                return true;
            }

            var dictionary = result as IDictionary<string, object>;
            if (dictionary != null)
            {
                result = new DictionaryObject(dictionary);
                return true;
            }

            var arrayList = result as ArrayList;
            if (arrayList != null && arrayList.Count > 0)
            {
                if (arrayList[0] is IDictionary<string, object>)
                    result = new List<object>(arrayList.Cast<IDictionary<string, object>>().Select(x => new DictionaryObject(x)));
                else
                    result = new List<object>(arrayList.Cast<object>());
            }

            return true;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            var att = _root.Attribute(binder.Name);
            if (att != null)
            {
                result = att.Value;
                return true;
            }

            var nodes = _root.Elements(binder.Name);
            if (nodes.Count() > 1)
            {
                result = nodes.Select(n => new DynamicXml(n)).ToList();
                return true;
            }

            var node = _root.Element(binder.Name);
            if (node != null)
            {
                if (node.HasElements)
                {
                    result = new DynamicXml(node);
                }
                else
                {
                    result = node.Value;
                }
                return true;
            }

            return true;
        }
Example #7
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = Repository.FindModel(binder.Name);

            //result = string.Format("{{ Site.{0} }}", binder.Name); //default result;
            return true;
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            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 = (CompilerServices.IsAnonymousType(valueType))
                         ? new RazorDynamicObject { Model = value }
                         : value;
            return true;
        }
Example #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(GetMemberBinder binder, out object result)
 {
     if (!this.values.ContainsKey(binder.Name))
         this.values.Add(binder.Name, null);
     result = binder.Name.Equals("response_type") ? (ResponseTypeIdentifier)this.values[binder.Name] : this.values[binder.Name];
     return true;
 }
        /// <summary>
        /// Returns a value from the current DataReader record
        /// If the field doesn't exist null is returned.
        /// DbNull values are turned into .NET nulls.
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            // 'Implement' common reader properties directly
            if (binder.Name == "IsClosed")
                result = DataReader.IsClosed;
            else if (binder.Name == "RecordsAffected")
                result = DataReader.RecordsAffected;
            // lookup column names as fields
            else
            {
                try
                {
                    result = DataReader[binder.Name];
                    if (result == DBNull.Value)
                        result = null;
                }
                catch
                {
                    result = null;
                    return false;
                }
            }

            return true;
        }
Example #11
0
File: Cmd.cs Project: srasch/cmd
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     var commando = Runner.GetCommand();
     commando.AddCommand(binder.Name);
     result =  commando;
     return true;
 }
Example #12
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var key = binder.Name;
            result = GetSetting(key);

            return true;
        }
Example #13
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var child = definition.Children
                        .Where(def => def.name == binder.Name.Replace("_", "-"))
                        //.DefaultIfEmpty(null)
                        //.SingleOrDefault();
                        .ToArray();

            /*
             * if (child != null)
             * {
             *  result = new Data(child, this);
             *  return true;
             * }*/
            if (child.Count() == 1)
            {
                result = new Data(child[0], this);
                return(true);
            }
            if (child.Count() > 1)
            {
                result = child.Select(fmt => new Data(fmt, this)).ToArray();
                return(true);
            }
            result = null;
            return(false);
        }
Example #14
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (_data.ContainsKey(binder.Name))
            {
                result = _data[binder.Name];
                var converted = ConvertResult(result);
                if (!ReferenceEquals(result, converted))
                    _data[binder.Name] = result = converted;
                
                return true;
            }

            if (_tableName == null)
            {
                result = null;
                return false;
            }
            var relatedAdapter = _database.Adapter as IAdapterWithRelation;
            if (relatedAdapter != null && relatedAdapter.IsValidRelation(_tableName, binder.Name))
            {
                var relatedRows = relatedAdapter.FindRelated(_tableName, _data, binder.Name);
                if (relatedRows.Count() == 1 && !binder.Name.IsPlural())
                {
                    result = new SimpleRecord(relatedRows.Single(), binder.Name, _database);
                }
                else
                {
                    result = new SimpleResultSet(relatedRows.Select(dict => new SimpleRecord(dict, binder.Name, _database)));
                }
                return true;
            }
            return base.TryGetMember(binder, out result);
        }
Example #15
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     if (cache == null) CacheLoad();
     if (!cache.TryGetValue(binder.Name, out result))
         result = GetDefault(binder.ReturnType);
     return true;
 }
Example #16
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var propertyInfo = m_type.GetProperty(
                binder.Name,
                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);

            if (propertyInfo != null)
            {
                result = propertyInfo.GetValue(null, null);
                return true;
            }

            var fieldInfo = m_type.GetField(
                binder.Name,
                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);

            if (fieldInfo != null)
            {
                result = fieldInfo.GetValue(null);
                return true;
            }

            result = null;
            return false;
        }
            public override bool TryGetMember(GetMemberBinder binder, out object result)
            {
                if (!this.dictionary.TryGetValue(binder.Name, out result))
                {
                    result = null;
                    return true;
                }

                var dictionary = result as IDictionary<string, object>;
                if (dictionary != null)
                {
                    result = new DynamicJsonObject(dictionary);
                    return true;
                }

                var arrayList = result as ArrayList;
                if (arrayList != null)
                {
                    if (arrayList.Count > 0 && arrayList[0] is IDictionary<string, object>)
                        result = new List<object>(arrayList.Cast<IDictionary<string, object>>().Select(x => new DynamicJsonObject(x)));
                    else
                        result = new List<object>(arrayList.Cast<object>());
                }

                return true;
            }
Example #18
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;
            if (xElement.Elements().All(x => x.DynamicCompatableName() != binder.Name) && binder.Name != xElement.DynamicCompatableName())
                return false;

            var xElements = xElement.Elements().Where(x => x.DynamicCompatableName() == binder.Name);
            if (xElements.Count() == 1)
            {
                var element = xElements.First();
                foreach (var xAttribute in element.Attributes())
                {
                    element.Add(new XElement(xAttribute.Name, xAttribute.Value));
                    xAttribute.Remove();
                }
                var childElements = element.Elements().Select(x => x.DynamicCompatableName());
                if (childElements.Count() > 1 && childElements.Distinct().Count() == 1)
                {
                    result = element.Elements().Select(x => new DynamicXml(x)).ToArray();
                }
                else
                    result = new DynamicXml(element);
            }
            else if (!xElements.Any() && binder.Name == xElement.DynamicCompatableName())
                result = this;
            else
                result = xElements.Select(x => new DynamicXml(x)).ToArray();
            return true;
        }
Example #19
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     if (stringValues.ContainsKey(binder.Name))
         result = stringValues[binder.Name];
     else result = numberValues[binder.Name];
     return true;
 }
Example #20
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     var child = elementFactory.CreateElementWithNameForParent(binder.Name, element);
     element.AddChild(child);
     result = DynamicElementFor(child);
     return true;
 }
Example #21
0
        public override bool TryGetMember(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);
        }
Example #22
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     try
     {
         Variable variable;
         if(!variables.TryGetValue(binder.Name, out variable))
         {
             int idx = GetGlobalVarIndexByName(binder.Name);
             var ptr = GetAddressOfGlobalVar(idx);
             if(ptr == IntPtr.Zero)
             {
                 result = null;
                 return true;
             }
             int tid;
             GetGlobalVar(idx, out tid);
             var instance = ScriptEngine.GetVariable(ptr, tid);
             variables[binder.Name] = variable = new Variable(instance, ptr, tid);
         }
         result = ScriptEngine.GetVariable(variable.Address, variable.TypeId, variable.Instance);
         return true;
     }
     catch(Exception ex)
     {
         ScriptEngine.Log ("Exception caught while fetching '{0}' variable of module '{1}': {2}.", binder.Name, Name, ex.Message);
         result = null;
         return false;
     }
 }
Example #23
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     result = null;
     switch (binder.Name)
     {
         case "Value":
             result = _elements[0].Value;
             break;
         case "Count":
             result = _elements.Count;
             break;
         default:
             {
                 var attr = _elements[0].Attribute(XName.Get(binder.Name));
                 if (attr != null)
                     result = attr;
                 else
                 {
                     var items = _elements.Descendants(XName.Get(binder.Name));
                     if (items == null)
                         return true;
                     var itemsArray = items.ToArray();
                     if (itemsArray.Length == 0)
                         return false;
                     result = new DynamicXml(itemsArray);
                 }
             }
             break;
     }
     return true;
 }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (GetStaticField(m_heap, m_type, binder, out result))
                return true;

            throw new InvalidOperationException(string.Format("Type '{0}' does not contain a static '{1}' field.", m_type.Name, binder.Name));
        }
Example #25
0
    /// <summary>
    /// Called when the user accesses a property dynamically (e.g. "xn.Countries")
    /// </summary>
    /// <returns>Depending on the data, this may return a collection of nodes
    /// or a single node or a string value.</returns>
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
      result = null;
      
      // First search for nested elements
      var elems = container.Elements(nameResolver(binder.Name));
      if (elems.Count() == 1)
        // Single element - wrap it inside DynamicXml
        result = new DynamicXml(elems.First(), ns, camelCase);
      else if (elems.Count() != 0)
      {
        // Multiple elements - wrapp all inside DynamicXml & return sequecne
        result = elems.Select(e => new DynamicXml(e, ns,  camelCase));
      }
      else
      {
        // No sub-element found. If the current node is Element, try attributes
        var element = container as XElement;
        if (element != null)
          result = element.Attributes(nameResolver(binder.Name)).FirstOrDefault();

        // Special name 'Value' can be used to get the inner text.
        if (binder.Name == "Value") result = element.Value;
      }
      return result != null;
    }
Example #26
0
        /// <summary>
        /// Finds text resource
        /// </summary>
        /// <param name="binder">GetMemberBinder with dynamic text key</param>
        /// <param name="result">Text item</param>
        /// <returns>Returns a value or a non existing value from the <see cref="ITextResource"/> implementation</returns>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result =
                new DynamicMemberChainer(binder.Name, this.context, this.textResource);

            return true;
        }
Example #27
0
 public override bool TryGetMember(GetMemberBinder binder, out object result)
 {
     //return base.TryGetMember(binder, out result);
       CurrentList = CurrentList ??  new BiggyList<dynamic>(dbName: binder.Name);
       result = CurrentList;
       return true;
 }
Example #28
0
        /// <summary>
        /// Tries to get a property or field with the given name
        /// </summary>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            //Try getting a property of that name
            var prop = _wrapped.GetType().GetProperty(binder.Name, flags);

            if (prop == null)
            {
                //Try getting a field of that name
                var fld = _wrapped.GetType().GetField(binder.Name, flags);
                if (fld != null)
                {
                    result = fld.GetValue(_wrapped);
                    return(true);
                }
                else
                {
                    return(base.TryGetMember(binder, out result));
                }
            }
            else
            {
                result = prop.GetValue(_wrapped, null);
                return(true);
            }
        }
Example #29
0
        public override Boolean TryGetMember(GetMemberBinder binder, out Object result)
        {
            var type = _targetType;
            do {
                var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
                if (binder.IgnoreCase)
                    flags |= BindingFlags.IgnoreCase;

                var propertyInfo = type.GetProperty(binder.Name, flags);
                if (propertyInfo != null) {
                    var value = propertyInfo.GetValue(_target, null);
                    result = value != null ? new ReflectedObject(value) : null;
                    return true;
                }

                var fieldInfo = type.GetField(binder.Name, flags);
                if (fieldInfo != null) {
                    var value = fieldInfo.GetValue(_target);
                    result = value != null ? new ReflectedObject(value) : null;
                    return true;
                }
            } while ((type = type.BaseType) != null);

            result = null;
            return false;
        }
Example #30
0
    public override bool TryGetMember(GetMemberBinder binder, out object result)
    {
      //if this is not a DomainProperty...
      if (!objectInstance.ObjectDefinition.Properties.ContainsKey(binder.Name))
      {
        //...try to get it as a normal property
        PropertyInfo propInfo = this.proxiedObject.GetType().GetProperty(binder.Name);
        if (propInfo != null)
        {
          result = propInfo.GetValue(this.proxiedObject, null);
          return true;
        }
        else
        {
          result = null;
          return false;
        }
      }
      else  //is a DomainProperty, get it from the Properties collection
      {
        PropertyDefinition prop = objectInstance.ObjectDefinition.Properties[binder.Name];
        var propValue = this.objectInstance.GetUntypedValue(prop);

        result = propValue.StringValue;
        return true;
      }
    }
Example #31
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            PropertyInfo propInfo = _realObject.GetType().GetProperty(binder.Name);

            if (propInfo == null) {
                PropertyInfo[] properties = _realObject.GetType().GetProperties();
                if (properties.Length == 0) {
                    throw new InvalidOperationException(
                        String.Format(CultureInfo.CurrentCulture,
                                      MvcResources.DynamicViewPage_NoProperties,
                                      binder.Name)
                    );
                }

                string propNames = properties.Select(p => p.Name)
                                             .OrderBy(name => name)
                                             .Aggregate((left, right) => left + ", " + right);

                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture,
                                  MvcResources.DynamicViewPage_PropertyDoesNotExist,
                                  binder.Name,
                                  propNames)
                );

            }

            result = Wrap(propInfo.GetValue(_realObject, null));
            return true;
        }
Example #32
0
        /// <summary>
        /// 获取动态类型的属性
        /// </summary>
        /// <param name="binder"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            if (PrivateDic.ContainsKey(binder.Name))
            {
                var member = PrivateDic[binder.Name];

                var enumerableMember = (member as IEnumerable <object>);
                if (enumerableMember != null)
                {
                    result = GetListObject(enumerableMember);
                }
                else if ((member as Dictionary <string, object>) != null)
                {
                    result = GetObject((member as Dictionary <string, object>));
                }
                else
                {
                    result = member;
                }
            }
            else
            {
                result = null;
            }

            return(true);
        }
Example #33
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (binder.Name == "__Fields")
            {
                result = (from field in m_type.Fields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
                return true;
            }
            if (binder.Name == "__StaticFields")
            {
                result = (from field in m_type.StaticFields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
                return true;
            }
            if (binder.Name == "__ThreadStaticFields")
            {
                result = (from field in m_type.ThreadStaticFields where field.Type != null select new { Name = field.Name, Type = field.Type.Name }).ToArray();
                return true;
            }
            if (binder.Name == "__Name")
            {
                result = m_type.Name;
                return true;
            }

            if (GetStaticField(m_heap, m_type, binder, out result))
                return true;

            throw new InvalidOperationException(string.Format("Type '{0}' does not contain a static '{1}' field.", m_type.Name, binder.Name));
        }
        /// <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     = this.Define.GetProperty(propertyName);

            result = GetValue(property);
            return(true);
        }
        /// <summary>
        /// Attempts to get a member value.
        /// </summary>
        /// <param name="binder">The binder to use.</param>
        /// <param name="result">The output result.</param>
        /// <returns>True if a member was returned.</returns>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            if (binder == null)
            {
                throw new ArgumentNullException("binder");
            }

            return(data.TryGetValue(binder.Name.ToUpperInvariant(), out result));
        }
Example #36
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))
     {
         this.Recording.Add(new Invocation(InvocationKind.Get, binder.Name));
         return(true);
     }
     return(false);
 }
Example #37
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     if (itemPropery.ContainsKey(binder.Name))
     {
         result = itemPropery[binder.Name];
         return(true);
     }
     result = null;
     return(false);
 }
Example #38
0
        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);
        }
Example #39
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     //HACK:目前默认zh-cn语言
     result = CodeSharp.Framework.SystemConfig.Settings["zhcn_" + binder.Name];
     result = string.IsNullOrEmpty((string)result) ? binder.Name : result;
     if (!Langs.ContainsKey(binder.Name))
     {
         Langs.Add(binder.Name, result.ToString());
     }
     return(true);
 }
        /// <summary>
        /// Performs the binding of the dynamic get member operation.
        /// </summary>
        /// <param name="binder">An instance of the <see cref="T:System.Dynamic.GetMemberBinder" /> that represents the details of the dynamic operation.</param>
        /// <returns>The new <see cref="T:System.Dynamic.DynamicMetaObject" /> representing the result of the binding.</returns>
        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);
        }
Example #41
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var name = binder.Name;

            if (!base.TryGetMember(binder, out result) || (null == result))
            {
                //Try to get Named shape
                result = Named(name.Replace("__", "-"));
            }
            return(true);
        }
Example #42
0
        /// <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     = this.Define.GetProperty(propertyName);

            if (property == null)
            {
                throw new DomainDrivenException(string.Format(Strings.NoDefinitionProperty, this.Define.TypeName, propertyName));
            }
            result = GetValue(property);
            return(true);
        }
Example #43
0
        // If you try to get a value of a property
        // not defined in the class, this method is called.
        public override bool TryGetMember(
            System.Dynamic.GetMemberBinder binder, out object result)
        {
            // Converting the property name to lowercase
            // so that property names become case-insensitive.
            string name = binder.Name;

            // If the property name is found in a dictionary,
            // set the result parameter to the property value and return true.
            // Otherwise, return false.
            return(dictionary.TryGetValue(name, out result));
        }
Example #44
0
        /// <summary>
        /// Dynamic get member
        /// </summary>
        /// <param name="binder">The binder</param>
        /// <param name="result">The output result</param>
        /// <returns>True if member was found</returns>
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            DataNode n = GetNodeNoThrow(binder.Name);

            if (n != null)
            {
                result = n;
                return(true);
            }
            else
            {
                return(base.TryGetMember(binder, out result));
            }
        }
Example #45
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var property = this.Model.Properties.FirstOrDefault(p => p.Name == binder.Name || p.PropertyName == binder.Name);

            if (property != null)
            {
                result = this[property];
                return(true);
            }
            else
            {
                return(base.TryGetMember(binder, out result));
            }
        }
Example #46
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            result = null;
            var name = binder.Name.ToLower();

            if (!dictionary.TryGetValue(name, out result))
            {
                if (page != null)
                {
                    if (page.ChildPage != null)
                    {
                        page.ChildPage.TypedViewBag.TryGetItem(name, out result);
                    }
                    else if (page.ParentPage != null)
                    {
                        page.ParentPage.TypedViewBag.TryGetItem(name, out result);
                    }
                }
            }

            return(true);
        }
Example #47
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var memberName = binder.Name;

            if (VstPluginContext != null && dynamicProperties.ContainsKey(memberName))
            {
                result = 0.0f;
                lock (InstrumentBase.VstPluginContextLockObject)
                {
                    if (VstPluginContext != null)
                    {
                        if (VstPluginContext.VstParameterIndexes.ContainsKey(memberName))
                        {
                            int idx = VstPluginContext.VstParameterIndexes[memberName];
                            result = VstPluginContext.Context.PluginCommandStub.GetParameter(idx);
                        }
                    }
                }
                return(true);
            }
            return(dynamicProperties.TryGetValue(memberName, out result));
        }
Example #48
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var name = binder.Name;

            // 属性値は _属性名 で取得。文字列として返す。
            if (name.StartsWith("_"))
            {
                var attName = name.Substring(1);

                result = element.Attribute(attName).Value;
                return(true);
            }

            var subElements = element.Elements(name).ToList();

            // 要素がないときは null 返す。
            if (subElements.Count == 0)
            {
                result = (string)null;
                return(true);
            }

            // 要素が1個だけの時は素直にその要素を返す。
            if (subElements.Count == 1)
            {
                var e = subElements[0];

                result = new DynamicXml(e);
                return(true);
            }

            // 要素が複数ある時はリストで要素一覧を返す。
            var es = subElements.Select(x => new DynamicXml(x));

            result = es.ToList();
            return(true);
        }
Example #49
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     result = DefaultResult_;
     return(true);
 }
 /// <summary>
 /// Attempts to get a member of the instance.
 /// </summary>
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     return(Fields.TryGetMember(binder, out result));
 }
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     return(storedValues.TryGetValue(binder.Name, out result));
 }
Example #52
0
 /// <summary>
 /// Tries to get the member.
 /// </summary>
 /// <param name="binder">The binder.</param>
 /// <param name="result">The result.</param>
 /// <returns></returns>
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     return(RemoteInvoke(new Invocation(InvocationKind.Get, binder.Name), out result));
 }
Example #53
0
        //public virtual bool TryBinaryOperation(BinaryOperationBinder binder, object arg, out object result) { throw new NotImplementedException(); }

        //public virtual bool TryConvert(ConvertBinder binder, out object result) { throw new NotImplementedException(); }

        //public virtual bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result) { throw new NotImplementedException(); }

        //public virtual bool TryDeleteIndex(DeleteIndexBinder binder, object[] indexes) { throw new NotImplementedException(); }

        //public virtual bool TryDeleteMember(DeleteMemberBinder binder) { throw new NotImplementedException(); }

        //public virtual bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) { throw new NotImplementedException(); }

        public virtual bool TryGetMember(GetMemberBinder binder, out object result)
        {
            throw new NotImplementedException();
        }
Example #54
0
 /// <summary>
 /// Performs the binding of the dynamic get member operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="GetMemberBinder"/> that represents the details of the dynamic operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindGetMember(GetMemberBinder binder)
 {
     ContractUtils.RequiresNotNull(binder, nameof(binder));
     return(binder.FallbackGetMember(this));
 }
Example #55
0
 public virtual bool TryGetMember(GetMemberBinder binder, out object result)
 {
     result = null;
     return(false);
 }
Example #56
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     return(TryGetProperty(binder.Name, out result));
 }
Example #57
0
        public virtual new System.Dynamic.DynamicMetaObject BindGetMember(GetMemberBinder binder)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }
        public virtual new bool TryGetMember(GetMemberBinder binder, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }