Skip to content

Instantly share code, notes, and snippets.

@Majirefy
Majirefy / webpack.config.js
Created August 5, 2018 02:51
Phaser-CE Webpack config.
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const phaserModule = path.join(__dirname, '/node_modules/phaser-ce/');
const phaser = path.join(phaserModule, 'build/custom/phaser-split.js');
const pixi = path.join(phaserModule, 'build/custom/pixi.js');
const p2 = path.join(phaserModule, 'build/custom/p2.js');
module.exports = {
@Majirefy
Majirefy / LambdaInvoke.cs
Created May 18, 2018 01:54
Use lambda expression to invoke property change notification.
public bool IsLogin
{
get
{
return _isLogin;
}
set
{
_isLogin = value;
RaisePropertyChanged(() => IsLogin);
@Majirefy
Majirefy / ExtendedBindableObject.cs
Created May 18, 2018 01:45
The eShopOnContainers mobile app uses the ExtendedBindableObject class to provide change notifications.
public abstract class ExtendedBindableObject : BindableObject
{
    public void RaisePropertyChanged<T>(Expression<Func<T>> property)
    {
        var name = GetMemberInfo(property).Name;
        OnPropertyChanged(name);
    }
    private MemberInfo GetMemberInfo(Expression expression)
    {
@Majirefy
Majirefy / OnAutoWireViewModelChanged.cs
Created May 18, 2018 01:07
OnAutoWireViewModelChanged event
private static void OnAutoWireViewModelChanged(BindableObject bindable, object oldValue, object newValue)
{
    var view = bindable as Element;
    if (view == null)
    {
        return;
    }
    var viewType = view.GetType();
    var viewName = viewType.FullName.Replace(".Views.", ".ViewModels.");
@Majirefy
Majirefy / AutoWireViewModel.XAML
Created May 18, 2018 01:02
Automatically Creating a View Model with a View Model Locator
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
@Majirefy
Majirefy / CreateAViewModelProgrammatically.cs
Created May 17, 2018 13:33
Creating a view model Programmatically.
public LoginView()
{
InitializeComponent();
BindingContext = new LoginViewModel(navigationService);
}
@Majirefy
Majirefy / CreateAViewModelInXAML.xaml
Created May 17, 2018 13:27
Create a view model in XAML.
<ContentPage ... xmlns:local="clr-namespace:eShop">
<ContentPage.BindingContext>
<local:LoginViewModel />
</ContentPage.BindingContext>
...
</ContentPage>
@Majirefy
Majirefy / BestPractice.cs
Created January 19, 2018 16:26
Don't block on async code.
public async void Button1_Click(...)
{
var json = await GetJsonAsync(...);
textBox1.Text = json;
}
public class MyController : ApiController
{
public async Task<string> Get()
{
@Majirefy
Majirefy / ConfigureAwait.cs
Created January 19, 2018 16:14
Use ConfigureAwait(false) for preventing the deadlock.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
using (var client = new HttpClient())
{
var jsonString = await client.GetStringAsync(uri).ConfigureAwait(false);
return JObject.Parse(jsonString);
}
}
@Majirefy
Majirefy / ASP.NETExample.cs
Created January 19, 2018 15:44
ASP.NET example for deadlock async code.
// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
using (var client = new HttpClient())
{
var jsonString = await client.GetStringAsync(uri);
return JObject.Parse(jsonString);
}
}