SlideShare une entreprise Scribd logo
1  sur  36
概要
目次
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

Contenu connexe

Similaire à Reflection with xamarin.forms

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
 
Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)Data Binding Intro (Windows 8)
Data Binding Intro (Windows 8)
Gilbok Lee
 

Similaire à 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
 

Plus de 道化師 堂華

Plus de 道化師 堂華 (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の設計コンセプトと 導入予定の機能紹介
 

Dernier

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 

Reflection with xamarin.forms