Skip to content

Instantly share code, notes, and snippets.

View felipeslongo's full-sized avatar
🌴
Having Fun With Threads

Felipe de Souza Longo felipeslongo

🌴
Having Fun With Threads
View GitHub Profile
@felipeslongo
felipeslongo / DisposeEx.cs
Last active March 18, 2019 20:55
I used the below extension methods to solve these memory leak issues. Think of Ender's Game final battle scene, the DisposeEx method is like that laser and it disassociates all views and their connected objects and disposes them recursively and in a way that shouldn't crash your app.
//https://stackoverflow.com/questions/25532870/xamarin-ios-memory-leaks-everywhere?rq=1
public static void DisposeEx(this UIView view) {
const bool enableLogging = false;
try {
if (view.IsDisposedOrNull())
return;
var viewDescription = string.Empty;
@felipeslongo
felipeslongo / .View
Created March 18, 2019 21:31 — forked from aspnetde/.View
Xamarin.iOS MemoryUtility
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.MessageUI;
using MonoTouch.UIKit;
namespace MyApp
{
public interface ICanCleanUpMyself
{
@felipeslongo
felipeslongo / UITableView_ScrollToAndSelectRow.cs
Created March 21, 2019 22:58
Xamarin.IOS extension that scroll to a UITableViewCell and select it (it trigger the selected events)
using System;
using System.Threading.Tasks;
using Foundation;
namespace UIKit
{
public static class UITableView_ScrollToAndSelectRow
{
private static TimeSpan CabalisticDelay => TimeSpan.FromSeconds(1);
@felipeslongo
felipeslongo / UITableView+SelectCell.cs
Created March 22, 2019 17:01
Xamarin.IOS extension method that performs a click/tap event into a UITableViewCell
namespace UIKit
{
public static class UITableView_SelectCell
{
public static void SelectCell(this UITableView @this, UITableViewCell cell)
{
var index = @this.IndexPathForCell(cell);
@this.SelectRow(index, true, UITableViewScrollPosition.None);
@this.Delegate.RowSelected(@this, index);
}
@felipeslongo
felipeslongo / UITableViewCell+GetTableView.cs
Created March 22, 2019 21:24
Xamarin.IOS extension that gets the parent UITableView from the UITableViewCell
namespace UIKit
{
/// <summary>
/// Xamarin.IOS extension that gets the parent <see cref="UITableView"/> from the <see cref="UITableViewCell"/>
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/15711645/how-to-get-uitableview-from-uitableviewcell"/>
public static class UITableViewCell_GetTableView
{
/// <summary>
/// Gets the parent <see cref="UITableView"/>
@felipeslongo
felipeslongo / IDictionary+WhereToDictionary.cs
Created March 25, 2019 20:55
Filtering out values from a C# Generic Dictionary
using System.Collections.Generic;
namespace System.Linq
{
/// <summary>
/// Filtering out values from a C# Generic Dictionary
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/2131648/filtering-out-values-from-a-c-sharp-generic-dictionary"/>
public static class IDictionary_WhereToDictionary
{
@felipeslongo
felipeslongo / EmbeddedResource.cs
Created March 28, 2019 20:25
Loads files with Build Action set to EmbeddedResource.
using System.IO;
using System.Reflection;
namespace Core.Utils
{
public static class EmbeddedResource
{
public static string ReadString(Assembly assembly, string @namespace ,string filename)
{
var stream = assembly.GetManifestResourceStream($"{@namespace}.{filename}");
@felipeslongo
felipeslongo / UITableViewCell+GetUITableView.cs
Created April 2, 2019 16:05
Get the UITableView from a UITableViewCell
using UIKit;
namespace UIKit
{
public static class UITableViewCell_GetUITableView
{
/// <summary>
/// Get the <see cref="UITableView"/> associated with this cell.
/// </summary>
/// <param name="this"></param>
@felipeslongo
felipeslongo / AutoCompleteTextView+ShowSuggestions.cs
Last active April 11, 2019 16:37
Extension method ShowSuggestions to AutoCompleteTextView
using Android.Widget;
namespace App.Droid.Extensions
{
/// <summary>
/// Extension method ShowSuggestions to AutoCompleteTextView
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/2126717/android-autocompletetextview-show-suggestions-when-no-text-entered"/>
public static class AutoCompleteTextView_ShowSuggestions
{
@felipeslongo
felipeslongo / JavaLangObject+Cast.cs
Last active April 10, 2019 17:38
Extension method Cast for <see cref="Java.Lang.Object"/>.
using Java.Lang;
namespace App.Droid.Extensions
{
/// <summary>
/// Extension method Cast for <see cref="Java.Lang.Object"/>.
/// </summary>
/// <seealso cref="https://stackoverflow.com/questions/6594250/type-cast-from-java-lang-object-to-native-clr-type-in-monodroid"/>
public static class JavaLangObject_Cast
{