diff --git a/UnityWeld/Binding/Internal/BindableMember.cs b/UnityWeld/Binding/Internal/BindableMember.cs index a3525d4..d160d90 100644 --- a/UnityWeld/Binding/Internal/BindableMember.cs +++ b/UnityWeld/Binding/Internal/BindableMember.cs @@ -21,6 +21,28 @@ public class BindableMember where MemberType : MemberInfo /// public readonly Type ViewModelType; + /// + /// Name of the view model type. + /// + public string ViewModelTypeName + { + get + { + return ViewModelType.Name; + } + } + + /// + /// Name of the member. + /// + public string MemberName + { + get + { + return Member.Name; + } + } + public BindableMember(MemberType member, Type viewModelType) { Member = member; @@ -29,7 +51,7 @@ public BindableMember(MemberType member, Type viewModelType) public override string ToString() { - return string.Concat(ViewModelType.ToString(), ".", Member.Name); + return string.Concat(ViewModelType.ToString(), ".", MemberName); } } } diff --git a/UnityWeld/Binding/Internal/PropertyFinder.cs b/UnityWeld/Binding/Internal/PropertyFinder.cs index 25245b3..a8464fc 100644 --- a/UnityWeld/Binding/Internal/PropertyFinder.cs +++ b/UnityWeld/Binding/Internal/PropertyFinder.cs @@ -23,13 +23,18 @@ public static class PropertyFinder /// /// Use reflection to find all components with properties we can bind to. /// - public static IEnumerable GetBindableProperties(GameObject gameObject) //todo: Maybe move this to the TypeResolver. + public static IEnumerable> GetBindableProperties(GameObject gameObject) //todo: Maybe move this to the TypeResolver. { return gameObject.GetComponents() - .SelectMany(component => component.GetType() - .GetProperties(BindingFlags.Instance | BindingFlags.Public)) - .Where(prop => !hiddenTypes.Contains(prop.ReflectedType)) - .Where(prop => !prop.GetCustomAttributes(typeof(ObsoleteAttribute), true).Any()); + .SelectMany(component => + { + var type = component.GetType(); + return type + .GetProperties(BindingFlags.Instance | BindingFlags.Public) + .Select(p => new BindableMember(p, type)); + }) + .Where(prop => !hiddenTypes.Contains(prop.ViewModelType)) + .Where(prop => !prop.Member.GetCustomAttributes(typeof(ObsoleteAttribute), true).Any()); } } } diff --git a/UnityWeld/Binding/Internal/TypeResolver.cs b/UnityWeld/Binding/Internal/TypeResolver.cs index 2312c23..65b5af1 100644 --- a/UnityWeld/Binding/Internal/TypeResolver.cs +++ b/UnityWeld/Binding/Internal/TypeResolver.cs @@ -262,7 +262,7 @@ public static BindableMember[] FindBindableMethods(EventBinding targ ) .Where(m => m.Member.GetParameters().Length == 0) .Where(m => m.Member.GetCustomAttributes(typeof(BindingAttribute), false).Any() - && !m.Member.Name.StartsWith("get_")) // Exclude property getters, since we aren't doing anything with the return value of the bound method anyway. + && !m.MemberName.StartsWith("get_")) // Exclude property getters, since we aren't doing anything with the return value of the bound method anyway. .ToArray(); } diff --git a/UnityWeld_Editor/BaseBindingEditor.cs b/UnityWeld_Editor/BaseBindingEditor.cs index c79e809..70b572e 100644 --- a/UnityWeld_Editor/BaseBindingEditor.cs +++ b/UnityWeld_Editor/BaseBindingEditor.cs @@ -82,7 +82,7 @@ Func menuEnabled InspectorUtils.DoPopup( new GUIContent(curPropertyValue), label, - prop => string.Concat(prop.ViewModelType, "/", prop.Member.Name, " : ", prop.Member.PropertyType.Name), + prop => string.Concat(prop.ViewModelType, "/", prop.MemberName, " : ", prop.Member.PropertyType.Name), prop => menuEnabled(prop.Member), prop => prop.ToString() == curPropertyValue, prop => @@ -95,8 +95,8 @@ Func menuEnabled ); }, bindableProperties - .OrderBy(property => property.ViewModelType.Name) - .ThenBy(property => property.Member.Name) + .OrderBy(property => property.ViewModelTypeName) + .ThenBy(property => property.MemberName) .ToArray() ); } @@ -135,11 +135,11 @@ Func menuEnabled { var options = bindableProperties .Select(prop => new OptionInfo( - string.Concat(prop.ViewModelType, "/", prop.Member.Name, " : ", prop.Member.PropertyType.Name), + string.Concat(prop.ViewModelType, "/", prop.MemberName, " : ", prop.Member.PropertyType.Name), prop )) - .OrderBy(option => option.Property.ViewModelType.Name) - .ThenBy(option => option.Property.Member.Name); + .OrderBy(option => option.Property.ViewModelTypeName) + .ThenBy(option => option.Property.MemberName); var noneOption = new OptionInfo(NoneOptionString, null); @@ -174,22 +174,22 @@ Func menuEnabled /// protected void ShowViewPropertyMenu( GUIContent label, - PropertyInfo[] properties, + BindableMember[] properties, Action propertyValueSetter, string curPropertyValue, out Type selectedPropertyType ) { var propertyNames = properties - .Select(MemberInfoToString) + .Select(m => m.ToString()) .ToArray(); var selectedIndex = Array.IndexOf(propertyNames, curPropertyValue); var content = properties.Select(prop => new GUIContent(string.Concat( - prop.ReflectedType.Name, + prop.ViewModelTypeName, "/", - prop.Name, + prop.MemberName, " : ", - prop.PropertyType.Name + prop.Member.PropertyType.Name ))) .ToArray(); @@ -201,11 +201,11 @@ out Type selectedPropertyType UpdateProperty( propertyValueSetter, curPropertyValue, - MemberInfoToString(newSelectedProperty), + newSelectedProperty.ToString(), "Set view property" ); - selectedPropertyType = newSelectedProperty.PropertyType; + selectedPropertyType = newSelectedProperty.Member.PropertyType; } else { @@ -215,7 +215,7 @@ out Type selectedPropertyType return; } - selectedPropertyType = properties[selectedIndex].PropertyType; + selectedPropertyType = properties[selectedIndex].Member.PropertyType; } } @@ -354,14 +354,6 @@ protected Type AdaptTypeForward(Type inputType, string adapterName) return adapterAttribute != null ? adapterAttribute.OutputType : inputType; } - /// - /// Convert a MemberInfo to a uniquely identifiable string. - /// - protected static string MemberInfoToString(MemberInfo member) - { - return string.Concat(member.ReflectedType.ToString(), ".", member.Name); - } - /// /// Convert a BindableEvent to a uniquely identifiable string. /// diff --git a/UnityWeld_Editor/EventBindingEditor.cs b/UnityWeld_Editor/EventBindingEditor.cs index 46708b4..4468033 100644 --- a/UnityWeld_Editor/EventBindingEditor.cs +++ b/UnityWeld_Editor/EventBindingEditor.cs @@ -53,7 +53,7 @@ private void ShowMethodMenu(EventBinding targetScript, BindableMember m.ViewModelType + "/" + m.Member.Name, + m => m.ViewModelType + "/" + m.MemberName, m => true, m => m.ToString() == targetScript.viewModelMethodName, m => UpdateProperty( @@ -63,8 +63,8 @@ private void ShowMethodMenu(EventBinding targetScript, BindableMember m.ViewModelType.Name) - .ThenBy(m => m.Member.Name) + .OrderBy(m => m.ViewModelTypeName) + .ThenBy(m => m.MemberName) .ToArray() ); } diff --git a/UnityWeld_Editor/OneWayPropertyBindingEditor.cs b/UnityWeld_Editor/OneWayPropertyBindingEditor.cs index 57af2f1..924fc9e 100644 --- a/UnityWeld_Editor/OneWayPropertyBindingEditor.cs +++ b/UnityWeld_Editor/OneWayPropertyBindingEditor.cs @@ -51,8 +51,8 @@ public override void OnInspectorGUI() ShowViewPropertyMenu( new GUIContent("View property", "Property on the view to bind to"), PropertyFinder.GetBindableProperties(targetScript.gameObject) - .OrderBy(property => property.ReflectedType.Name) - .ThenBy(property => property.Name) + .OrderBy(prop => prop.ViewModelTypeName) + .ThenBy(prop => prop.MemberName) .ToArray(), updatedValue => targetScript.uiPropertyName = updatedValue, targetScript.uiPropertyName, diff --git a/UnityWeld_Editor/TwoWayPropertyBindingEditor.cs b/UnityWeld_Editor/TwoWayPropertyBindingEditor.cs index b36b9b4..739aca2 100644 --- a/UnityWeld_Editor/TwoWayPropertyBindingEditor.cs +++ b/UnityWeld_Editor/TwoWayPropertyBindingEditor.cs @@ -81,8 +81,8 @@ public override void OnInspectorGUI() ShowViewPropertyMenu( new GUIContent("View property", "Property on the view to bind to"), PropertyFinder.GetBindableProperties(targetScript.gameObject) - .OrderBy(prop => prop.ReflectedType.Name) - .ThenBy(prop => prop.Name) + .OrderBy(prop => prop.ViewModelTypeName) + .ThenBy(prop => prop.MemberName) .ToArray(), updatedValue => targetScript.uiPropertyName = updatedValue, targetScript.uiPropertyName,