Skip to content

Instantly share code, notes, and snippets.

@Majirefy
Majirefy / webpack.config.js
Created Aug 5, 2018
Phaser-CE Webpack config.
View webpack.config.js
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
Use lambda expression to invoke property change notification.
View LambdaInvoke.cs
public bool IsLogin
{
get
{
return _isLogin;
}
set
{
_isLogin = value;
RaisePropertyChanged(() => IsLogin);
@Majirefy
Majirefy / ExtendedBindableObject.cs
Created May 18, 2018
The eShopOnContainers mobile app uses the ExtendedBindableObject class to provide change notifications.
View ExtendedBindableObject.cs
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
OnAutoWireViewModelChanged event
View OnAutoWireViewModelChanged.cs
private static void OnAutoWireViewModelChanged(BindableObject bindableobject oldValueobject 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
Automatically Creating a View Model with a View Model Locator
View AutoWireViewModel.XAML
viewModelBase:ViewModelLocator.AutoWireViewModel="true"
@Majirefy
Majirefy / CreateAViewModelProgrammatically.cs
Created May 17, 2018
Creating a view model Programmatically.
View CreateAViewModelProgrammatically.cs
public LoginView()
{
InitializeComponent();
BindingContext = new LoginViewModel(navigationService);
}
@Majirefy
Majirefy / CreateAViewModelInXAML.xaml
Created May 17, 2018
Create a view model in XAML.
View CreateAViewModelInXAML.xaml
<ContentPage ... xmlns:local="clr-namespace:eShop">
<ContentPage.BindingContext>
<local:LoginViewModel />
</ContentPage.BindingContext>
...
</ContentPage>
@Majirefy
Majirefy / BestPractice.cs
Created Jan 19, 2018
Don't block on async code.
View BestPractice.cs
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 Jan 19, 2018
Use ConfigureAwait(false) for preventing the deadlock.
View ConfigureAwait.cs
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 Jan 19, 2018
ASP.NET example for deadlock async code.
View ASP.NETExample.cs
// 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);
}
}
You can’t perform that action at this time.