zoukankan      html  css  js  c++  java
  • ExtensionMethods Class

    /// <summary>
    		/// Generic Enum.Parse implementation.
    		/// </summary>
    		/// <typeparam name="TEnum">The enumeration type to parse to.</typeparam>
    		/// <param name="strEnumValue">String value to parse.</param>
    		/// <param name="defaultValue">Default value when conversion fails.</param>
    		/// <returns>The parsed result or the default provided when parsing failed.</returns>
    		public static TEnum ToEnum<TEnum>(this string strEnumValue, TEnum defaultValue)
    		{
    			if (!Enum.IsDefined(typeof(TEnum), strEnumValue))
    				return defaultValue;
     
    			return (TEnum)Enum.Parse(typeof(TEnum), strEnumValue);
    		}
     
     
    		/// <summary>
    		/// Invoke passed in action synchronously on the GUI thread of this item. 
    		/// </summary>
    		/// <param name="me">The control.</param>
    		/// <param name="action">Action that will be performed on the GUI thread.</param>
    		public static void InvokeOnGui(this Control me, Action action)
    		{
    			if (me.InvokeRequired)
    				me.Invoke(action);
    			else
    				action();
    		}
     
    		/// <summary>
    		/// Invoke passed in action asynchronously on the GUI thread of this item.  Note: If this method is called
    		/// on the GUI thread, the action will be performed synchronously. If it is called from another thread, it
    		/// is invoked asynchronoulsly.
    		/// </summary>
    		/// <param name="me">The control.</param>
    		/// <param name="action">Action that will be performed on the GUI thread.</param>
    		public static void BeginInvokeOnGui(this Control me, Action action)
    		{
    			if (me.InvokeRequired)
    				me.BeginInvoke(action);
    			else
    				action();
    		}
    
  • 相关阅读:
    Jetpack MVVM 高频提问和解答
    Android-Jetpack架构组件-—-Navigation#
    Jetpack明星组件 —ViewModel #
    Android开发把 LiveData 用于事件传递那些坑#
    Android官方架构组件Lifecycle#
    Android架构组件JetPack之Lifecycle#
    Android架构组件JetPack之LiveData的工作原理#
    DataBinding从入门到通透#
    SpringBoot 分包方式多数据源
    SpringBoot与数据访问
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/3098400.html
Copyright © 2011-2022 走看看