Example #1
0
        public static TomlTableArray Clone(this TomlTableArray source)
        {
            source.CheckNotNull(nameof(source));

            var cloned = new TomlTableArray(source.Root, source.Items.Select(i => i.Clone()));
            return cloned;
        }
 /// <summary>
 /// 去除StringBuilder两端的空格
 /// </summary>
 /// <param name="sb">StringBuilder</param>
 /// <returns>返回修改后的StringBuilder,主要用于链式操作</returns>
 public static StringBuilder Trim(this StringBuilder sb)
 {
     sb.CheckNotNull("sb");
     if (sb.Length == 0)
         return sb;
     return sb.TrimEnd().TrimStart();
 }
Example #3
0
 /// <summary>
 /// 初始化WebApi框架
 /// </summary>
 public static IAppBuilder UseWebApiInitialize(this IAppBuilder app, WebApiInitializeOptions options)
 {
     app.CheckNotNull("app");
     options.CheckNotNull("options");
     IFrameworkInitializer initializer = new WebApiFrameworkInitializer(options);
     initializer.Initialize();
     return app;
 }
        public static void CheckStringNotNullOrEmpty(this string obj, string name)
        {
            obj.CheckNotNull(name);

            if (obj.Length == 0)
            {
                throw new ArgumentException("String parameter cannot be empty.", name);
            }
        }
 /// <summary>
 /// 添加AutoMapper服务映射信息
 /// </summary>
 public static void AddAutoMapperServices(this IServiceCollection services)
 {
     services.CheckNotNull("services" );
     services.AddSingleton<IMapper, AutoMapperMapper>();
     services.AddSingleton<InputDtoTypeFinder>();
     services.AddSingleton<EntityTypeFinder>();
     services.AddSingleton<OutputDtoTypeFinder>();
     services.AddSingleton<IMapTuple, InputDtoEntityMapTuple>();
     services.AddSingleton<IMapTuple, EntityOutputDtoMapTuple>();
 }
        public static TPath BuildTPath(this LambdaExpression expr)
        {
            expr.CheckNotNull(nameof(expr));

            var exprBody = expr.Body.ToString();
            var withoutRootKey = exprBody.Substring(exprBody.IndexOf(".") + 1);

            var toParse = "/" + withoutRootKey.Replace('.', '/');
            return TPath.Parse(toParse);
        }
        /// <summary>
        /// 添加OAuth服务映射令牌
        /// </summary>
        public static void AddOAuthServices(this IServiceCollection services)
        {
            services.CheckNotNull("services");
            services.AddSingleton<IOAuthAuthorizationServerProvider, OsharpAuthorizationServerProvider>();
            services.AddSingleton<IAuthorizationCodeProvider, OsharpAuthorizationCodeProvider>();
            services.AddSingleton<IRefreshTokenProvider, OsharpRefreshTokenProvider>();

            services.AddSingleton<IOAuthClientIdProvider, DatetimeOAuthClientIdProvider>();
            services.AddSingleton<IOAuthClientSecretProvider, GuidOAuthClientSecretProvider>();
        }
 /// <summary>
 /// 去除<see cref="StringBuilder"/>结尾指定字符
 /// </summary>
 /// <param name="sb"></param>
 /// <param name="c">要去掉的字符</param>
 /// <returns></returns>
 public static StringBuilder TrimEnd(this StringBuilder sb, char c)
 {
     sb.CheckNotNull("sb");
      if (sb.Length == 0)
         return sb;
     while (c.Equals(sb[sb.Length - 1]))
     {
         sb.Remove(sb.Length - 1, 1);
     }
     return sb;
 }
 /// <summary>
 /// 返回<see cref="StringBuilder"/>从起始位置指定长度的字符串
 /// </summary>
 /// <param name="sb"></param>
 /// <param name="start">起始位置</param>
 /// <param name="length">长度</param>
 /// <returns>字符串</returns>
 /// <exception cref="OverflowException">超出字符串索引长度异常</exception>
 public static string SubString(this StringBuilder sb, int start, int length)
 {
     sb.CheckNotNull("sb");
     if (start + length > sb.Length)
         throw new IndexOutOfRangeException("超出字符串索引长度");
     char[] cs = new char[length];
     for (int i = 0; i < length; i++)
     {
         cs[i] = sb[start + i];
     }
     return new string(cs);
 }
Example #10
0
        internal static MethodInfo GetMethodWithThrowOnError(this Type type, string name, params Type[] types)
        {
            type.CheckNotNull(nameof(type));
            name.CheckNotNullOrWhitespace(nameof(name));

            MethodInfo method = type.GetMethod(name, types);

            if (method == null)
                throw new MissingMethodException(type.FullName, name);

            return method;
        }
Example #11
0
        internal static PropertyInfo GetPropertyWithThrowOnError(this Type type, string name, BindingFlags bindingFlags = BindingFlags.Default)
        {
            type.CheckNotNull(nameof(type));
            name.CheckNotNullOrWhitespace(nameof(name));

            PropertyInfo property = bindingFlags == BindingFlags.Default
                ? type.GetProperty(name)
                : type.GetProperty(name, bindingFlags);

            if (property == null)
                throw new MissingMemberException(type.FullName, name);

            return property;
        }
        public static string ToDetailedString(this IWebElement element)
        {
            element.CheckNotNull(nameof(element));

            try
            {
                return $@"Tag: {element.TagName}
Location: {element.Location}
Size: {element.Size}
Text: {element.Text.Trim()}";
            }
            catch
            {
                return null;
            }
        }
 /// <summary>
 /// 去除<see cref="StringBuilder"/>开头的指定的<seealso cref="string"/>
 /// </summary>
 /// <param name="sb"></param>
 /// <param name="str">要去掉的<seealso cref="string"/></param>
 /// <returns></returns>
 public static StringBuilder TrimStart(this StringBuilder sb, string str)
 {
     sb.CheckNotNull("sb");
     if (string.IsNullOrEmpty(str)
         || sb.Length == 0
         || str.Length > sb.Length)
         return sb;
     while (sb.SubString(0, str.Length).Equals(str))
     {
         sb.Remove(0, str.Length);
         if (str.Length>sb.Length)
         {
             break;
         }
     }
     return sb;
 }
Example #14
0
        public static Enum[] GetIndividualEnumFlags(this Type type)
        {
            type.CheckNotNull(nameof(type));

            if (type.IsDefined(typeof(FlagsAttribute), false))
            {
                Enum[] allFlags = Enum.GetValues(type).Cast<Enum>().Where(x => Convert.ToDecimal(x) != 0m).ToArray();
                List<Enum> individualFlags = new List<Enum>(allFlags.Take(1));

                for (int i = 1; i < allFlags.Length; i++)
                {
                    Enum currentFlag = allFlags[i];
                    if (allFlags.Take(i).All(x => !currentFlag.HasFlag(x)))
                        individualFlags.Add(currentFlag);
                }

                return individualFlags.ToArray();
            }
            else
            {
                return Enum.GetValues(type).Cast<Enum>().ToArray();
            }
        }
 /// <summary>
 /// 添加漫道短信功能相关映射信息
 /// </summary>
 public static void AddMdSmsServices(this IServiceCollection services)
 {
     services.CheckNotNull("services");
     services.AddScoped<ISms, MdSms>();
 }
Example #16
0
        internal static bool IsClassOrNullable(this Type type)
        {
            type.CheckNotNull(nameof(type));

            return type.IsClass || Nullable.GetUnderlyingType(type) != null;
        }
Example #17
0
        public static string ToString(this object value, TermCase termCase)
        {
            value.CheckNotNull("value");

            return TermResolver.ToString(value, new TermOptions { Case = termCase });
        }
 public static void AddJPushServices(this IServiceCollection services)
 {
     services.CheckNotNull("services");
     services.AddScoped<IPush,JPush>();
 }
 /// <summary>
 /// 添加容联.云通讯短信功能相关映射信息
 /// </summary>
 public static void AddMdSmsServices(this IServiceCollection services)
 {
     services.CheckNotNull("services");
     services.AddSingleton<ISms, CcpSms>();
 }
 public static void CheckNotNull(this object obj)
 {
     obj.CheckNotNull(string.Empty);
 }
 /// <summary>
 /// 添加OAuth服务映射令牌
 /// </summary>
 public static void AddOAuthServices(this IServiceCollection services)
 {
     services.CheckNotNull("services" );
     services.AddSingleton<IOAuthAuthorizationServerProvider, OsharpAuthorizationServerProvider>();
 }
Example #22
0
 /// <summary>
 /// 获取程序集的产品版本
 /// </summary>
 public static Version GetProductVersion(this Assembly assembly)
 {
     assembly.CheckNotNull("assembly");
     FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
     return new Version(info.ProductVersion);
 }