Пример #1
0
 protected PathNode(ITypeMapper typeMapper, PathNode parent, string name)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     if (name == null)
         throw new ArgumentNullException("name");
     this.typeMapper = typeMapper;
     this.parent = parent;
     this.name = name;
 }
Пример #2
0
 public PomonaRequest(PathNode node,
     NancyContext context,
     ITextSerializerFactory serializerFactory)
 {
     if (node == null)
         throw new ArgumentNullException("node");
     if (context == null)
         throw new ArgumentNullException("context");
     if (serializerFactory == null)
         throw new ArgumentNullException("serializerFactory");
     this.node = node;
     this.context = context;
     this.serializerFactory = serializerFactory;
     this.method = (HttpMethod)Enum.Parse(typeof(HttpMethod), context.Request.Method, true);
 }
Пример #3
0
 public ResourceNode(ITypeMapper typeMapper,
     PathNode parent,
     string name,
     Func<object> valueFetcher,
     ResourceType expectedType)
     : base(typeMapper, parent, name)
 {
     this.value = new System.Lazy<object>(valueFetcher);
     this.expectedType = expectedType;
     this.type = new System.Lazy<ResourceType>(() =>
     {
         var localValue = Value;
         if (Value == null)
             return expectedType;
         return (ResourceType)typeMapper.GetClassMapping(localValue.GetType());
     });
 }
Пример #4
0
        protected static PathNode CreateNode(ITypeMapper typeMapper,
            PathNode parent,
            string name,
            Func<object> valueFetcher,
            TypeSpec expectedType)
        {
            if (typeMapper == null)
                throw new ArgumentNullException("typeMapper");
            if (expectedType is ResourceType)
                return new ResourceNode(typeMapper, parent, name, valueFetcher, (ResourceType)expectedType);
            if (expectedType.IsCollection && expectedType.ElementType is ResourceType)
            {
                var elementType = (ResourceType)expectedType.ElementType;

                if (elementType.PrimaryId == null)
                {
                    throw new InvalidOperationException(
                        "Unable to create queryable of resource type without PrimaryId set.");
                }

                var idType = elementType.PrimaryId.PropertyType.Type;
                return (PathNode)Activator.CreateInstance(
                    typeof(QueryableNode<,>).MakeGenericType(new[] { elementType.Type, idType }),
                    typeMapper,
                    parent,
                    name,
                    valueFetcher,
                    expectedType);
            }

            throw new NotImplementedException();
        }