Esempio n. 1
0
        /// <summary>
        /// Feeds the target its required Apis.
        /// </summary>
        /// <returns>false if update failed</returns>
        public static bool UpdateApis(IExternalApiProvider source, object target)
        {
            Type targetType = target.GetType();

            object[] tmp = new object[1];

            foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute)))
            {
                tmp[0] = source.GetApi(propinfo.PropertyType);
                if (tmp[0] == null)
                {
                    return(false);
                }

                propinfo.GetSetMethod(true).Invoke(target, tmp);
            }

            foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalApiAttribute)))
            {
                tmp[0] = source.GetApi(propinfo.PropertyType);
                propinfo.GetSetMethod(true).Invoke(target, tmp);
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Feeds the target its required Apis.
        /// </summary>
        /// <returns>false if update failed</returns>
        public static bool UpdateApis(IExternalApiProvider source, object target)
        {
            Type targetType = target.GetType();

            object[] tmp = new object[1];

            targetType.GetProperties(ReflectionExtensions.DI_TARGET_PROPS).FirstOrDefault(pi => pi.PropertyType == typeof(ApiContainer))
            ?.SetValue(target, source.Container);

            foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(RequiredApiAttribute)))
            {
                tmp[0] = source.GetApi(propinfo.PropertyType);
                if (tmp[0] == null)
                {
                    return(false);
                }

                propinfo.GetSetMethod(true).Invoke(target, tmp);
            }

            foreach (var propinfo in targetType.GetPropertiesWithAttrib(typeof(OptionalApiAttribute)))
            {
                tmp[0] = source.GetApi(propinfo.PropertyType);
                propinfo.GetSetMethod(true).Invoke(target, tmp);
            }

            return(true);
        }
Esempio n. 3
0
 public static T?GetApi <T>(this IExternalApiProvider apiProvider)
     where T : class, IExternalApi
 => apiProvider.GetApi(typeof(T)) as T;