Ejemplo n.º 1
0
        /// <summary>
        /// Registers a type and all its public properties.
        /// </summary>
        /// <param name="type">The type to register.</param>
        public static void Register(this IMemberAccessStrategy strategy, Type type)
        {
            foreach (var propertyInfo in type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                strategy.Register(type, propertyInfo.Name, new MethodInfoAccessor(propertyInfo.GetGetMethod()));
            }

            foreach (var fieldInfo in type.GetTypeInfo().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                strategy.Register(type, fieldInfo.Name, new DelegateAccessor((o, n) => fieldInfo.GetValue(o)));
            }
        }
Ejemplo n.º 2
0
        public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
        {
            FluidValue.SetTypeMapping <JsonObject>(x => new ObjectValue(x));
            FluidValue.SetTypeMapping <JsonArray>(x => new JsonArrayFluidValue(x));

            memberAccessStrategy.Register <NamedContentData, object?>(
                (value, name) => value.GetOrDefault(name));

            memberAccessStrategy.Register <JsonObject, object?>(
                (value, name) => value.GetOrDefault(name));

            memberAccessStrategy.Register <ContentFieldData, object?>(
                (value, name) => value.GetOrDefault(name));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Registers a type and all its public properties.
 /// </summary>
 /// <param name="type">The type to register.</param>
 public static void Register(this IMemberAccessStrategy strategy, Type type)
 {
     foreach (var entry in GetTypeMembers(type))
     {
         strategy.Register(type, entry.Key, entry.Value);
     }
 }
 /// <summary>
 /// Registers a limited set of properties in a type.
 /// </summary>
 /// <param name="type">The type to register.</param>
 /// <param name="names">The names of the properties in the type to register.</param>
 public static void Register(this IMemberAccessStrategy strategy, Type type, params string[] names)
 {
     foreach (var name in names)
     {
         strategy.Register(type, GetNamedAccessor(type, name));
     }
 }
Ejemplo n.º 5
0
        public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
        {
            memberAccessStrategy.Register <IUser, FluidValue>((user, name) =>
            {
                switch (name)
                {
                case "id":
                    return(new StringValue(user.Id));

                case "email":
                    return(new StringValue(user.Email));

                case "name":
                    return(new StringValue(user.Claims.DisplayName()));

                default:
                    {
                        var claim = user.Claims.FirstOrDefault(x => string.Equals(name, x.Type, StringComparison.OrdinalIgnoreCase));

                        if (claim != null)
                        {
                            return(new StringValue(claim.Value));
                        }

                        return(NilValue.Instance);
                    }
                }
            });
        }
 /// <summary>
 /// Registers a type and all its public properties.
 /// </summary>
 /// <param name="type">The type to register.</param>
 public static void Register(this IMemberAccessStrategy strategy, Type type)
 {
     foreach (var name in GetAllMembers(type))
     {
         strategy.Register(type, name, GetNamedAccessor(type, name));
     }
 }
Ejemplo n.º 7
0
        public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
        {
            FluidValue.SetTypeMapping <JsonObject>(x => new ObjectValue(x));
            FluidValue.SetTypeMapping <JsonArray>(x => new JsonArrayFluidValue(x));
            FluidValue.SetTypeMapping <JsonString>(x => FluidValue.Create(x.Value));
            FluidValue.SetTypeMapping <JsonBoolean>(x => FluidValue.Create(x.Value));
            FluidValue.SetTypeMapping <JsonNumber>(x => FluidValue.Create(x.Value));
            FluidValue.SetTypeMapping <JsonNull>(_ => FluidValue.Create(null));

            memberAccessStrategy.Register <ContentData, object?>(
                (value, name) => value.GetOrDefault(name));

            memberAccessStrategy.Register <JsonObject, object?>(
                (value, name) => value.GetOrDefault(name));

            memberAccessStrategy.Register <ContentFieldData, object?>(
                (value, name) => value.GetOrDefault(name));
        }
Ejemplo n.º 8
0
 public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
 {
     memberAccessStrategy.Register <IAssetEntity>();
     memberAccessStrategy.Register <IAssetInfo>();
     memberAccessStrategy.Register <IEntity>();
     memberAccessStrategy.Register <IEntityWithCreatedBy>();
     memberAccessStrategy.Register <IEntityWithLastModifiedBy>();
     memberAccessStrategy.Register <IEntityWithVersion>();
     memberAccessStrategy.Register <IEnrichedAssetEntity>();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Registers a limited set of properties in a type.
        /// </summary>
        /// <param name="type">The type to register.</param>
        /// <param name="names">The names of the properties in the type to register.</param>
        public static void Register(this IMemberAccessStrategy strategy, Type type, params string[] names)
        {
            foreach (var name in names)
            {
                var propertyInfo = type.GetTypeInfo().GetProperty(name, BindingFlags.Public | BindingFlags.Instance);

                if (propertyInfo != null)
                {
                    strategy.Register(type, name, new MethodInfoAccessor(propertyInfo.GetGetMethod()));
                }
                else
                {
                    var fieldInfo = type.GetTypeInfo().GetField(name, BindingFlags.Public | BindingFlags.Instance);

                    if (fieldInfo != null)
                    {
                        strategy.Register(type, name, new DelegateAccessor((o, n) => fieldInfo.GetValue(o)));
                    }
                }
            }
        }
Ejemplo n.º 10
0
        public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
        {
            memberAccessStrategy.Register <IContentEntity>();
            memberAccessStrategy.Register <IWithId <DomainId> >();
            memberAccessStrategy.Register <IEntity>();
            memberAccessStrategy.Register <IEntityWithCreatedBy>();
            memberAccessStrategy.Register <IEntityWithLastModifiedBy>();
            memberAccessStrategy.Register <IEntityWithVersion>();
            memberAccessStrategy.Register <IEnrichedContentEntity>();

            AddReferenceFilter();
        }
 /// <summary>
 /// Registers a limited set of properties in a type.
 /// </summary>
 /// <typeparam name="T">The type to register.</typeparam>
 /// <param name="names">The names of the properties in the type to register.</param>
 public static void Register <T>(this IMemberAccessStrategy strategy, params string[] names)
 {
     strategy.Register(typeof(T), names);
 }
 /// <summary>
 /// Registers a type and all its public properties.
 /// </summary>
 /// <typeparam name="T">The type to register.</typeparam>
 public static void Register <T>(this IMemberAccessStrategy strategy)
 {
     strategy.Register(typeof(T));
 }
 /// <summary>
 /// Registers a type with a <see cref="Func{T, TemplateContext, TResult}"/> to retrieve the property specified.
 /// </summary>
 /// <param name="type">The type to register.</param>
 /// <param name="name">The name of the property.</param>
 /// <param name="accessor">The <see cref="Func{T, TemplateContext, TResult}"/> instance used to retrieve the value.</param>
 public static void Register <T, TResult>(this IMemberAccessStrategy strategy, string name, Func <T, TemplateContext, TResult> accessor)
 {
     strategy.Register(typeof(T), name, new DelegateAccessor <T, TResult>((obj, propertyName, ctx) => accessor(obj, ctx)));
 }
 /// <summary>
 /// Registers a type with a <see cref="Func{T, string, TemplateContext, Task{TResult}}"/> to retrieve any of
 /// its property values.
 /// </summary>
 /// <param name="type">The type to register.</param>
 /// <param name="accessor">The <see cref="Func{T, string, TemplateContext, Task{TResult}}"/> instance used to retrieve the value.</param>
 public static void Register <T, TResult>(this IMemberAccessStrategy strategy, Func <T, string, TemplateContext, Task <TResult> > accessor)
 {
     strategy.Register(typeof(T), "*", new AsyncDelegateAccessor <T, TResult>(accessor));
 }
 /// <summary>
 /// Registers a type using a <see cref="IMemberAccessor"/> to retrieve any of
 /// its property values.
 /// </summary>
 /// <param name="type">The type to register.</param>
 /// <param name="getter">The <see cref="IMemberAccessor"/> instance used to retrieve the value.</param>
 public static void Register(this IMemberAccessStrategy strategy, Type type, IMemberAccessor getter)
 {
     strategy.Register(type, "*", getter);
 }
 /// <summary>
 /// Registers a type using a <see cref="IMemberAccessor"/> to retrieve any of
 /// its property values.
 /// </summary>
 /// <typeparam name="T">The type to register.</typeparam>
 /// <param name="getter">The <see cref="IMemberAccessor"/> instance used to retrieve the value.</param>
 public static void Register <T>(this IMemberAccessStrategy strategy, IMemberAccessor getter)
 {
     strategy.Register(typeof(T), "*", getter);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Registers a limited set of properties in a type.
 /// </summary>
 /// <typeparam name="T">The type to register.</typeparam>
 /// <param name="names">The property's expressions in the type to register.</param>
 public static void Register <T>(this IMemberAccessStrategy strategy, params Expression <Func <T, object> >[] names)
 {
     strategy.Register <T>(names.Select(ExpressionHelper.GetPropertyName).ToArray());
 }
Ejemplo n.º 18
0
 public void RegisterGlobalTypes(IMemberAccessStrategy memberAccessStrategy)
 {
     memberAccessStrategy.Register <IContentEntity>();
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Registers a type with a <see cref="Func{T, string, Object}"/> to retrieve any of
 /// its property values.
 /// </summary>
 /// <param name="type">The type to register.</param>
 /// <param name="accessor">The <see cref="Func{T, string, Object}"/> instance used to retrieve the value.</param>
 public static void Register <T>(this IMemberAccessStrategy strategy, Func <T, string, object> accessor)
 {
     strategy.Register(typeof(T), "*", new DelegateAccessor <T>(accessor));
 }