Exemplo n.º 1
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;
        }
Exemplo n.º 2
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));
            }
        }
Exemplo n.º 3
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();
        }