Skip to content

Instantly share code, notes, and snippets.

Avatar

Tomas "Arci" Kouba tkouba

  • Prague, Czech Republic
View GitHub Profile
@tkouba
tkouba / Extensions.GetAttributeValue.cs
Created Jan 28, 2021
Simple get attribute value helper extension
View Extensions.GetAttributeValue.cs
public static TValue GetAttributeValue<TAttribute, TValue>(this Type type, Func<TAttribute, TValue> valueSelector) where TAttribute : Attribute
{
var att = type.GetCustomAttributes(typeof(TAttribute), true).FirstOrDefault() as TAttribute;
if (att != null)
{
return valueSelector(att);
}
return default(TValue);
}
@tkouba
tkouba / UserDialogsImplWPF.cs
Created Nov 26, 2020
Acr.UserDialog WPF implementation preview
View UserDialogsImplWPF.cs
namespace Acr.UserDialogs
{
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using Acr.UserDialogs.Infrastructure;
using SAPXamarinTransporter.WPF.UserDialogs;
using Xamarin.Forms.Platform.WPF.Controls;
@tkouba
tkouba / MainActivity.cs
Created Nov 26, 2020
Show indicator workaround for Xamarin.Forms.PageIs.IsBusy
View MainActivity.cs
// Android MainActivity
using Android.App;
using Android.Content.PM;
using Android.OS;
using AndroidHUD; // https://github.com/redth-org/AndHUD
namespace ThemingDemo.Droid
{
[Activity(Label = "ThemingDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
@tkouba
tkouba / Reinstaller.cs
Created Sep 14, 2020
ClickOnce application migration tool
View Reinstaller.cs
/* ClickOnceReinstaller v 1.1.0
* - Author: Tomas Kouba (tomas.kouba@gmail.com)*
* - Changes:
* - add reinstall file extension .txt
* - using log4net
* - migration should be cancelled by user
* - TODO
* - add cancellation message to reinstall.txt file
*
* v 1.0.0
@tkouba
tkouba / TrayIconApplicationContext.cs
Created Aug 27, 2020
System.Windows.Forms.ApplicationContext enhancement with tray icon and menu.
View TrayIconApplicationContext.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyVpnManager.Base
{
/// <summary>
/// Specifies the contextual information about an application thread with <see cref="Icon"/> and <see cref="ContextMenuStrip"/>
@tkouba
tkouba / FontImageButtonRenderrer.WPF.cs
Created Feb 25, 2020
Xamarin custom button renderrer for buttons with FontImagesource
View FontImageButtonRenderrer.WPF.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Platform.WPF;
using MyDemo.WPF.Renderers;
@tkouba
tkouba / InstallClickOnceApp.cs
Created Oct 18, 2019 — forked from josheinstein/InstallClickOnceApp.cs
Install ClickOnce application programmatically (C#)
View InstallClickOnceApp.cs
using System;
using System.Collections.Generic;
using System.Deployment.Application;
using System.Linq;
using System.Text;
using System.Threading;
namespace InstallClickOnceApp
{
@tkouba
tkouba / CreateName.cs
Created Jun 28, 2018
Create valid variable name in PascalCase from any text - remove invalid characters, add underscore prefix if needed
View CreateName.cs
public static string CreateName(this string s) {
s = s.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
bool upper = true;
for (int i = 0; i < s.Length; i++)
{
var cat = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(s[i]);
//Console.WriteLine(cat);
if (cat == System.Globalization.UnicodeCategory.DecimalDigitNumber && sb.Length == 0)
sb.Append('_');
@tkouba
tkouba / IEnumStringToArray.cs
Created Aug 29, 2017
COM interface IEnumString to string array
View IEnumStringToArray.cs
private string[] IEnumStringToArray(IEnumString enumerator)
{
const int S_OK = 0x00000000;
List<string> lst = new List<string>();
if (enumerator != null)
{
int cft;
string[] strF = new string[100];
int hresult;
IntPtr intPtr = Marshal.AllocCoTaskMem(sizeof(int));
@tkouba
tkouba / PetaPocoValueConverter.cs
Last active Jan 9, 2019
PetaPoco value converters using PetaPoco.ConventionMapper
View PetaPocoValueConverter.cs
using System;
using System.Drawing;
namespace PetaPoco
{
/// <summary>
/// Specifies a persistent property value converter.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]