Esempio n. 1
0
        private IAttributeGroupDefinition TryResolveAttributeGroupDefinition(DynamicEntity.BinderInfo binderInfo)
        {
            //finds all the attribute groups that either have the Name or the ID
            //TODO: handle binderInfo.IgnoreCase
            var tabs = from tab in _entity.AttributionSchema.AttributeGroupDefinitions
                       where tab.Name == binderInfo.Name || tab.Id.ValueAsString == binderInfo.Name
                       select tab;

            return(tabs.SingleOrDefault());
        }
Esempio n. 2
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)
        {
            Contract.Requires(binder != null);
            var binderInfo = new DynamicEntity.BinderInfo(binder.IgnoreCase, binder.Name, binder.ReturnType);

            ITypedAttribute attr = TryResolveAttribute(binderInfo);

            if (attr != null)
            {
                result = attr;
                return(true);
            }

            //TODO: Support all the different things that the member may try to represent

            return(base.TryGetMember(binder, out result));
        }
Esempio n. 3
0
        private IEnumerable <dynamic> TryResolveChildrenByTypeName(DynamicEntity.BinderInfo binderInfo)
        {
            //ensures that we're working with a vertexed entity
            if (typeof(IEntityVertex).IsAssignableFrom(_entity.GetType()))
            {
                var vertex   = (IEntityVertex)_entity;
                var children = from c in (IDictionary <IMappedIdentifier, IEntityVertex>)vertex.DescendentEntities //we have to do the explicit cast as it implements IEnumerable twice, as we want the dictionary
                               where MakePluralName(c.Key.ValueAsString) == binderInfo.Name || MakePluralName(c.Value.Id.ValueAsString) == binderInfo.Name
                               select((ITypedEntity)c.Value).AsDynamic();                                          //either we're returning too low a type from c.Value or we need a Dynamic which isn't Typed

                //we wont return null here, as the child may be allowed, there just aren't any
                //TODO: Should we return null or not? (refer to previous comment)
                return(children);
            }
            else
            {
                //You're doing it wrong!
                throw new NotSupportedException(string.Format("Entity {0} is not an instance of {1} and hence it does not support the concept of children", _entity.GetType().FullName, typeof(IEntityVertex).FullName));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Attempts to resolve the attribute from the binder information
        /// </summary>
        /// <param name="binderInfo">The binder info.</param>
        /// <returns></returns>
        private ITypedAttribute TryResolveAttribute(DynamicEntity.BinderInfo binderInfo)
        {
            //TODO: Az - Should we be returning a dynamic version of Attribute? Could have some fun there if we do

            //find all the properties in the object schema
            //TODO: handle binderInfo.IgnoreCase
            var properties = from tab in _entity.AttributionSchema.AttributeGroupDefinitions
                             from p in tab.AttributeDefinitions
                             where p.Alias == binderInfo.Name || p.Id.ValueAsString == binderInfo.Name
                             select p;

            var property = properties.SingleOrDefault();

            //if there is a property then find the attribute that implements it
            if (property != default(IAttributeDefinition))
            {
                //Need to work out some better way to expose the values, x.Value.Value, err that's not good
                return(Attributes.Where <ITypedAttribute>(x => x.Value.AttributeType == property).Select(x => x.Value.Value).SingleOrDefault());
            }

            return(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>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            Contract.Requires(binder != null);
            var binderInfo = new DynamicEntity.BinderInfo(binder.IgnoreCase, binder.Name, binder.ReturnType);

            ITypedAttribute attr = TryResolveAttribute(binderInfo);
            if (attr != null)
            {
                result = attr;
                return true;
            }

            //TODO: Support all the different things that the member may try to represent

            return base.TryGetMember(binder, out result);
        }