-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseComponent.cs
86 lines (76 loc) · 2.71 KB
/
BaseComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq.Expressions;
using System.Text;
using Xamarin.Forms;
namespace LivingThing.Core.Frameworks.XamarinRazor
{
class DelegateConverter<T> : IValueConverter
{
Func<T, object> Delegate;
public DelegateConverter(Func<T, object> @delegate)
{
Delegate = @delegate;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Delegate((T)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BaseComponent:ComponentBase, IDisposable
{
//public static Binding Binding<TViewModel, TTarget>(TViewModel viewModel, Expression<Func<TViewModel, TTarget>> exp)
//{
// var path = exp.ToString();
// var lambdaIndex = path.IndexOf("=>");
// var lamdaPath = path.Substring(lambdaIndex+2).Trim();
// var firstDot = lamdaPath.IndexOf(".");
// if (firstDot >= 0)
// {
// lamdaPath = lamdaPath.Substring(firstDot + 1);
// }
// else
// {
// lamdaPath = ".";
// }
// return new Binding(lamdaPath);
//}
public static Binding Binding<TViewModel, TTarget>(TViewModel source, Expression<Func<TViewModel, TTarget>> exp, Func<TTarget, object> converter = null, string format = null, BindingMode mode = BindingMode.Default)
{
var path = exp.ToString();
var lambdaIndex = path.IndexOf("=>");
var lamdaPath = path.Substring(lambdaIndex + 2).Trim();
var firstDot = lamdaPath.IndexOf(".");
if (firstDot >= 0)
{
lamdaPath = lamdaPath.Substring(firstDot + 1);
}
else
{
lamdaPath = ".";
}
return new Binding(lamdaPath, mode, converter != null ? new DelegateConverter<TTarget>(converter) : null, null, format, source);
}
public static Thickness Thickness(double value)
{
return new Thickness(value);
}
public static Thickness Thickness(double horizontal, double vertical)
{
return new Thickness(horizontal, vertical);
}
public static Thickness Thickness(double left, double top, double right, double bottom)
{
return new Thickness(left, top, right, bottom);
}
public void Dispose()
{
}
}
}