SlideShare a Scribd company logo
概要
目次
reflectionとは?
reflectionとは?
自
己言及
BindableProperty
素のBindableProperty
public class AlphaCircleImageCell : ViewCell
{
public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create
(
nameof(ImageSource),
typeof(ImageSource),
typeof(AlphaCircleImageCell),
propertyChanged: (bindable, oldValue, newValue) => ((AlphaCircleImageCell)bindable).ImageSource = (ImageSource)newValue
);
public static readonly BindableProperty TextProperty = BindableProperty.Create
(
nameof(Text),
typeof(string),
typeof(AlphaCircleImageCell),
propertyChanged: (bindable, oldValue, newValue) => ((AlphaCircleImageCell)bindable).Text = (string)newValue
);
...
}
素のBindableProperty
var Template = new DataTemplate(typeof(AlphaCircleImageCell));
Template.SetBinding(AlphaCircleImageCell.ImageSourceProperty, "AvatarUrl");
Template.SetBinding(AlphaCircleImageCell.TextProperty, "Login");
var List = new ListView
{
ItemTemplate = Template,
};
BindableProperty
BindableProperty
簡潔なBindableProperty
必要ありません!
public class AlphaCircleImageCell : ViewCell
{
public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create
(
nameof(ImageSource),
typeof(ImageSource),
typeof(AlphaCircleImageCell),
propertyChanged: (bindable, oldValue, newValue) => ((AlphaCircleImageCell)bindable).ImageSource = (ImageSource)newValue
);
public static readonly BindableProperty TextProperty = BindableProperty.Create
(
nameof(Text),
typeof(string),
typeof(AlphaCircleImageCell),
propertyChanged: (bindable, oldValue, newValue) => ((AlphaCircleImageCell)bindable).Text = (string)newValue
);
...
}
簡潔なBindableProperty
public class AlphaCircleImageCell : ViewCell
{
public static readonly BindableProperty ImageSourceProperty =
typeof(AlphaCircleImageCell).GetRuntimeProperty("ImageSource").CreateBindableProperty();
public static readonly BindableProperty TextProperty =
typeof(AlphaCircleImageCell).GetRuntimeProperty("Text").CreateBindableProperty();
...
}
簡潔なBindableProperty
var List = new ListView
{
ItemTemplate = new DataTemplateEx(typeof(AlphaCircleImageCell))
.SetBinding("ImageSource", "AvatarUrl")
.SetBinding("Text", "Login"),
};
簡潔なBindableProperty
var List = new ListView
{
ItemTemplate = new DataTemplateEx(typeof(AlphaCircleImageCell))
.SetBindingList("ImageSource", "Text"),
};
BindableProperty
typeof 演算子
var AlphaCircleImageCellType = typeof(AlphaCircleImageCell);
Type.GetRuntimeProperty()
var ImageSourcePropertyInfo = typeof(AlphaCircleImageCell)
.GetRuntimeProperty("ImageSource");
PropertyInfo.SetValue()
typeof(AlphaCircleImageCell)
.GetRuntimeProperty("ImageSource")
.SetValue(ImageCell, IconImage); // ImageCell.ImageSource = IconImage; と等価
BindableProperty
BindableProperty のヘルパー
public static class BindablePropertyEx
{
public static BindableProperty CreateBindableProperty(this PropertyInfo PropertyInfo, object DefaultValue)
{
return BindableProperty.Create
(
PropertyInfo.Name,
PropertyInfo.PropertyType,
PropertyInfo.DeclaringType,
DefaultValue,
propertyChanged: (bindable, oldValue, newValue) => PropertyInfo.SetValue(bindable, newValue)
);
}
public static BindableProperty CreateBindableProperty(this PropertyInfo PropertyInfo)
{
return PropertyInfo.CreateBindableProperty
(
PropertyInfo.PropertyType.GetTypeInfo().IsValueType ?
Activator.CreateInstance(PropertyInfo.PropertyType) :
null
);
}
}
public class DataTemplateEx : DataTemplate
{
Type DeclaringType;
public DataTemplateEx(Type aDeclaringType)
:base(aDeclaringType)
{
DeclaringType = aDeclaringType;
}
public DataTemplateEx SetBinding(string ViewPropertyName, string DataPropertyName, object DefaultValue)
{
this.SetBinding
(
DeclaringType.GetRuntimeProperty(ViewPropertyName).CreateBindableProperty(DefaultValue),
DataPropertyName
);
return this;
}
public DataTemplateEx SetBinding(string ViewPropertyName, string DataPropertyName)
{
this.SetBinding
(
DeclaringType.GetRuntimeProperty(ViewPropertyName).CreateBindableProperty(),
DataPropertyName
);
return this;
}
public DataTemplateEx SetBindingList(params string[] PropertyNameList)
{
foreach(var PropertyName in PropertyNameList)
{
SetBinding
(
PropertyName,
PropertyName
);
}
return this;
}
}
匿名クラス
匿名クラス
匿名クラス
匿名クラス
匿名クラス
匿名クラス
var User = List.SelectedItem.GetValue<string>("Text");
PropertyInfo.GetValue()
var IconImage = typeof(AlphaCircleImageCell)
.GetRuntimeProperty("ImageSource")
.GetValue(ImageCell); // IconImage = ImageCell.ImageSource; と等価
匿名クラス
static public class ValueEx
{
public static T GetValue<T>(this object o, string name)
{
return (T)o.GetType().GetRuntimeProperty(name).GetValue(o);
}
}
匿名クラス
既知の問題
Reflection with xamarin.forms

More Related Content

Similar to Reflection with xamarin.forms

Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
Ivan Dolgushin
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
andyrobinson8
 
Bean Intro
Bean IntroBean Intro
Bean Intro
vikram singh
 
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
ISS Art, LLC
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
AntoJoseph36
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
Slavisa Pokimica
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
Stephen Chin
 
Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)
Gilbok Lee
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
Knoldus Inc.
 

Similar to Reflection with xamarin.forms (9)

Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...Aggregation and Awareness or How to Reduce the Amount of  your FrontEnd Code ...
Aggregation and Awareness or How to Reduce the Amount of your FrontEnd Code ...
 
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.pptDESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
DESIGNING A PERSISTENCE FRAMEWORK WITH PATTERNS.ppt
 
ActionScript3 collection query API proposal
ActionScript3 collection query API proposalActionScript3 collection query API proposal
ActionScript3 collection query API proposal
 
JavaFX and Scala in the Cloud
JavaFX and Scala in the CloudJavaFX and Scala in the Cloud
JavaFX and Scala in the Cloud
 
Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 

More from 道化師 堂華

独りガラパゴス開発
独りガラパゴス開発独りガラパゴス開発
独りガラパゴス開発
道化師 堂華
 
C++ tips4 cv修飾編
C++ tips4 cv修飾編C++ tips4 cv修飾編
C++ tips4 cv修飾編
道化師 堂華
 
C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編
道化師 堂華
 
C++ tips2 インクリメント編
C++ tips2 インクリメント編C++ tips2 インクリメント編
C++ tips2 インクリメント編
道化師 堂華
 
C++ tips1 #include編
C++ tips1 #include編C++ tips1 #include編
C++ tips1 #include編
道化師 堂華
 
エラーハンドリングモデル考察
エラーハンドリングモデル考察エラーハンドリングモデル考察
エラーハンドリングモデル考察
道化師 堂華
 
C++0x総復習
C++0x総復習C++0x総復習
C++0x総復習
道化師 堂華
 
C++プログラマの為のセキュリティ入門
C++プログラマの為のセキュリティ入門C++プログラマの為のセキュリティ入門
C++プログラマの為のセキュリティ入門
道化師 堂華
 
エラーハンドリング
エラーハンドリングエラーハンドリング
エラーハンドリング
道化師 堂華
 
マスタリング バベル
マスタリング バベルマスタリング バベル
マスタリング バベル
道化師 堂華
 
並列プログラミング 入門!&おさらい!
並列プログラミング入門!&おさらい!並列プログラミング入門!&おさらい!
並列プログラミング 入門!&おさらい!
道化師 堂華
 
バグベアード入門
バグベアード入門バグベアード入門
バグベアード入門
道化師 堂華
 
LUCIFERの設計コンセプトと 導入予定の機能紹介
LUCIFERの設計コンセプトと 導入予定の機能紹介LUCIFERの設計コンセプトと 導入予定の機能紹介
LUCIFERの設計コンセプトと 導入予定の機能紹介
道化師 堂華
 

More from 道化師 堂華 (13)

独りガラパゴス開発
独りガラパゴス開発独りガラパゴス開発
独りガラパゴス開発
 
C++ tips4 cv修飾編
C++ tips4 cv修飾編C++ tips4 cv修飾編
C++ tips4 cv修飾編
 
C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編C++ tips 3 カンマ演算子編
C++ tips 3 カンマ演算子編
 
C++ tips2 インクリメント編
C++ tips2 インクリメント編C++ tips2 インクリメント編
C++ tips2 インクリメント編
 
C++ tips1 #include編
C++ tips1 #include編C++ tips1 #include編
C++ tips1 #include編
 
エラーハンドリングモデル考察
エラーハンドリングモデル考察エラーハンドリングモデル考察
エラーハンドリングモデル考察
 
C++0x総復習
C++0x総復習C++0x総復習
C++0x総復習
 
C++プログラマの為のセキュリティ入門
C++プログラマの為のセキュリティ入門C++プログラマの為のセキュリティ入門
C++プログラマの為のセキュリティ入門
 
エラーハンドリング
エラーハンドリングエラーハンドリング
エラーハンドリング
 
マスタリング バベル
マスタリング バベルマスタリング バベル
マスタリング バベル
 
並列プログラミング 入門!&おさらい!
並列プログラミング入門!&おさらい!並列プログラミング入門!&おさらい!
並列プログラミング 入門!&おさらい!
 
バグベアード入門
バグベアード入門バグベアード入門
バグベアード入門
 
LUCIFERの設計コンセプトと 導入予定の機能紹介
LUCIFERの設計コンセプトと 導入予定の機能紹介LUCIFERの設計コンセプトと 導入予定の機能紹介
LUCIFERの設計コンセプトと 導入予定の機能紹介
 

Recently uploaded

Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
anfaltahir1010
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
aisafed42
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 

Recently uploaded (20)

Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 

Reflection with xamarin.forms