15. COMU+
こみゅぷらす
ViewModel
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace AddinByRoslyn
{
public static class PropertyChangedEventHandlerExtensions
{
public static void Raise(this PropertyChangedEventHandler onPropertyChanged, object
sender, [CallerMemberName] string propertyName = "")
{
if (onPropertyChanged != null)
onPropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
public static void Raise<PropertyType>(this PropertyChangedEventHandler
onPropertyChanged, object sender, Expression<Func<PropertyType>> propertyExpression)
{ onPropertyChanged.Raise(sender, propertyExpression.GetMemberName()); }
static string GetMemberName<MemberType>(this Expression<Func<MemberType>> expression)
{ return ((MemberExpression)expression.Body).Member.Name; }
}
16. COMU+
こみゅぷらす
ViewModelpublic class ViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
int identifierCount = 0;
public int IdentifierCount
{
get { return identifierCount; }
set {
if (value != identifierCount) {
identifierCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int usingCount = 0;
public int UsingCount
{
get { return usingCount; }
set {
if (value != usingCount) {
usingCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int classCount = 0;
public int ClassCount
{
get { return classCount; }
set {
if (value != classCount) {
classCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int fieldCount = 0;
public int FieldCount
{
get { return fieldCount; }
set {
if (value != fieldCount) {
fieldCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
17. COMU+
こみゅぷらす
ViewModel
int propertyCount = 0;
public int PropertyCount
{
get { return propertyCount; }
set {
if (value != propertyCount) {
propertyCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int methodCount = 0;
public int MethodCount
{
get { return methodCount; }
set {
if (value != methodCount) {
methodCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int variableCount = 0;
public int VariableCount
{
get { return variableCount; }
set {
if (value != variableCount) {
variableCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
int ifCount = 0;
public int IfCount
{
get { return ifCount; }
set {
if (value != ifCount) {
ifCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
18. COMU+
こみゅぷらす
ViewModel
int lambdaCount = 0;
public int LambdaCount
{
get { return lambdaCount; }
set {
if (value != lambdaCount) {
lambdaCount = value;
PropertyChanged.Raise(this);
RaiseUpdateData();
}
}
}
public object Data
{
get {
return new [] {
new { 名称 = "識別子の数" , 結果 =
IdentifierCount },
new { 名称 = "using の数" , 結果 = UsingCount },
new { 名称 = "クラスの数" , 結果 = ClassCount },
new { 名称 = "フィールドの数", 結果 =
FieldCount },
new { 名称 = "プロパティの数", 結果 =
PropertyCount },
new { 名称 = "メソッドの数" , 結果 =
MethodCount },
new { 名称 = "変数の数" , 結果 =
VariableCount },
new { 名称 = "if の数" , 結果 = IfCount },
new { 名称 = "ラムダ式の数" , 結果 =
string result = string.Empty;
public string Result
{
get { return result; }
set {
if (value != result) {
result = value;
PropertyChanged.Raise(this);
}
}
}
public void Clear()
{
IdentifierCount = UsingCount =
ClassCount = FieldCount =
PropertyCount = MethodCount =
VariableCount = IfCount =
LambdaCount = 0;
Result = string.Empty;
}
void RaiseUpdateData()
{ PropertyChanged.Raise(this, () => Data); }
}
}