public override object GetValue() { var target = this.Target; if (target == null) { return(null); } return(propertyInfo.GetValue(target)); }
public T GetProperty <T>(string name) { IProxyPropertyInfo proxyPropertyInfo = this.ProxyType.GetProperty(name); if (proxyPropertyInfo == null) { throw new InvalidOperationException("Property not found"); } object value = proxyPropertyInfo.GetValue(this.Value); return((T)typeof(T).ToSafe(value)); }
public virtual object GetValue() { var target = this.Target; if (target == null) { if (log.IsWarnEnabled) { log.WarnFormat("Get value ignored in target's property \"{0}\",the weak reference to the target is null.", this.propertyInfo.Name); } return(ReturnObject.UNSET); } return(proxyProperty.GetValue(target)); }
public ITargetProxy CreateProxy(object target, BindingDescription description) { IProxyType type = target.GetType().AsProxy(); IProxyMemberInfo memberInfo = type.GetMember(description.TargetName); if (memberInfo == null) { memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic); } if (memberInfo == null) { throw new MissingMemberException(type.Type.FullName, description.TargetName); } EventListener updateTrigger = null; if (!string.IsNullOrEmpty(description.UpdateTrigger)) { IProxyPropertyInfo updateTriggerPropertyInfo = type.GetProperty(description.UpdateTrigger); IProxyFieldInfo updateTriggerFieldInfo = updateTriggerPropertyInfo == null?type.GetField(description.UpdateTrigger) : null; if (updateTriggerPropertyInfo != null) { updateTrigger = updateTriggerPropertyInfo.GetValue(target) as EventListener; } if (updateTriggerFieldInfo != null) { updateTrigger = updateTriggerFieldInfo.GetValue(target) as EventListener; } if (updateTriggerPropertyInfo == null && updateTriggerFieldInfo == null) { throw new MissingMemberException(type.Type.FullName, description.UpdateTrigger); } //Other Property Type if (updateTrigger == null) /* by UniversalTargetProxyFactory */ { return(null); } } var propertyInfo = memberInfo as IProxyPropertyInfo; if (propertyInfo != null) { if (typeof(IObservableProperty).IsAssignableFrom(propertyInfo.ValueType)) { return(null); } if (typeof(EventListener).IsAssignableFrom(propertyInfo.ValueType)) { //Event Type object listener = propertyInfo.GetValue(target); if (listener == null) { throw new NullReferenceException(propertyInfo.Name); } return(new FairyEventProxy(target, (EventListener)listener)); } //Other Property Type if (updateTrigger == null)/* by UniversalTargetProxyFactory */ { return(null); } return(new FairyPropertyProxy(target, propertyInfo, updateTrigger)); } var fieldInfo = memberInfo as IProxyFieldInfo; if (fieldInfo != null) { if (typeof(IObservableProperty).IsAssignableFrom(fieldInfo.ValueType)) { return(null); } if (typeof(EventListener).IsAssignableFrom(fieldInfo.ValueType)) { //Event Type object listener = fieldInfo.GetValue(target); if (listener == null) { throw new NullReferenceException(fieldInfo.Name); } return(new FairyEventProxy(target, (EventListener)listener)); } //Other Property Type if (updateTrigger == null)/* by UniversalTargetProxyFactory */ { return(null); } return(new FairyFieldProxy(target, fieldInfo, updateTrigger)); } return(null); }
protected virtual ISourceProxy CreateProxy(object source, IPathNode node) { IProxyType proxyType = source.GetType().AsProxy(); if (node is IndexedNode) { var itemInfo = proxyType.GetItem(); if (itemInfo == null) { return(null); } var intIndexedNode = node as IntegerIndexedNode; if (intIndexedNode != null) { return(new IntItemNodeProxy((ICollection)source, intIndexedNode.Value, itemInfo)); } var stringIndexedNode = node as StringIndexedNode; if (stringIndexedNode != null) { return(new StringItemNodeProxy((ICollection)source, stringIndexedNode.Value, itemInfo)); } return(null); } var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name); } if (memberInfo == null || memberInfo.IsStatic()) { return(null); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); var valueType = proxyPropertyInfo.ValueType; if (typeof(IObservableProperty).IsAssignableFrom(valueType)) { object observableValue = proxyPropertyInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservableNodeProxy(source, (IObservableProperty)observableValue)); } // else if (typeof(IInteractionRequest).IsAssignableFrom(valueType)) // { // object request = proxyPropertyInfo.GetValue(source); // if (request == null) // return null; // return new InteractionNodeProxy(source, (IInteractionRequest)request); // } else { return(new PropertyNodeProxy(source, proxyPropertyInfo)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); var valueType = proxyFieldInfo.ValueType; if (typeof(IObservableProperty).IsAssignableFrom(valueType)) { object observableValue = proxyFieldInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservableNodeProxy(source, (IObservableProperty)observableValue)); } // else if (typeof(IInteractionRequest).IsAssignableFrom(valueType)) // { // object request = proxyFieldInfo.GetValue(source); // if (request == null) // return null; // return new InteractionNodeProxy(source, (IInteractionRequest)request); // } else { return(new FieldNodeProxy(source, proxyFieldInfo)); } } var methodInfo = memberInfo as MethodInfo; if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void))) { return(new MethodNodeProxy(source, methodInfo.AsProxy())); } var eventInfo = memberInfo as EventInfo; if (eventInfo != null) { return(new EventNodeProxy(source, eventInfo.AsProxy())); } return(null); }
protected virtual IObjectSourceProxy CreateChainedProxy(object source, IPathNode node, PathToken nextToken, IObjectSourceProxyFactory factory) { var indexedNode = node as IndexedNode; if (indexedNode != null) { var itemPropertyInfo = this.FindItemPropertyInfo(source.GetType()); if (itemPropertyInfo == null) { return(null); } return(new ChainedItemObjectSourceProxy(source, itemPropertyInfo, nextToken, factory, indexedNode.Value)); } var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name); } if (memberInfo == null || memberInfo.IsStatic()) { return(null); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { var propertyType = propertyInfo.PropertyType; if (typeof(IObservableProperty).IsAssignableFrom(propertyType)) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); object observableValue = proxyPropertyInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ChainedObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue, nextToken, factory)); } else { return(new ChainedPropertyObjectSourceProxy(source, propertyInfo, nextToken, factory)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { var fieldType = fieldInfo.FieldType; if (typeof(IObservableProperty).IsAssignableFrom(fieldType)) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); object observableValue = proxyFieldInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ChainedObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue, nextToken, factory)); } else { return(new ChainedFieldObjectSourceProxy(source, fieldInfo, nextToken, factory)); } } return(null); }
protected virtual IObjectSourceProxy CreateStaticLeafProxy(Type type, IPathNode node) { var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = this.FindStaticMemberInfo(type, memberNode.Name); } if (memberInfo == null) { return(null); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { var propertyType = propertyInfo.PropertyType; if (typeof(IObservableProperty).IsAssignableFrom(propertyType)) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); object observableValue = proxyPropertyInfo.GetValue(null); if (observableValue == null) { throw new ArgumentNullException(); } return(new ObservablePropertyObjectSourceProxy((IObservableProperty)observableValue)); } else { return(new LeafPropertyObjectSourceProxy(null, propertyInfo)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { var fieldType = fieldInfo.FieldType; if (typeof(IObservableProperty).IsAssignableFrom(fieldType)) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); object observableValue = proxyFieldInfo.GetValue(null); if (observableValue == null) { throw new ArgumentNullException(); } return(new ObservablePropertyObjectSourceProxy((IObservableProperty)observableValue)); } else { return(new LeafFieldObjectSourceProxy(fieldInfo)); } } var methodInfo = memberInfo as MethodInfo; if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void))) { return(new VoidMethodObjectSourceProxy(methodInfo)); } var eventInfo = memberInfo as EventInfo; if (eventInfo != null) { return(new EventObjectSourceProxy(eventInfo)); } return(null); }
protected virtual IObjectSourceProxy CreateStaticChainedProxy(Type type, IPathNode node, PathToken nextToken, IObjectSourceProxyFactory factory) { var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = this.FindStaticMemberInfo(type, memberNode.Name); } if (memberInfo == null) { return(null); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { var propertyType = propertyInfo.PropertyType; if (typeof(IObservableProperty).IsAssignableFrom(propertyType)) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); object observableValue = proxyPropertyInfo.GetValue(null); if (observableValue == null) { return(null); } return(new ChainedObservablePropertyObjectSourceProxy((IObservableProperty)observableValue, nextToken, factory)); } else { return(new ChainedPropertyObjectSourceProxy(propertyInfo, nextToken, factory)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { var fieldType = fieldInfo.FieldType; if (typeof(IObservableProperty).IsAssignableFrom(fieldType)) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); object observableValue = proxyFieldInfo.GetValue(null); if (observableValue == null) { return(null); } return(new ChainedObservablePropertyObjectSourceProxy((IObservableProperty)observableValue, nextToken, factory)); } else { return(new ChainedFieldObjectSourceProxy(fieldInfo, nextToken, factory)); } } return(null); }
protected virtual IObjectSourceProxy CreateLeafProxy(object source, IPathNode node) { var indexedNode = node as IndexedNode; if (indexedNode != null) { var itemPropertyInfo = this.FindItemPropertyInfo(source.GetType()); if (itemPropertyInfo == null) { return(null); } return(new LeafItemObjectSourceProxy(source, itemPropertyInfo, indexedNode.Value)); } var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name); } if (memberInfo == null || memberInfo.IsStatic()) { return(null); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { var propertyType = propertyInfo.PropertyType; if (typeof(IObservableProperty).IsAssignableFrom(propertyType)) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); object observableValue = proxyPropertyInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue)); } else { return(new LeafPropertyObjectSourceProxy(source, propertyInfo)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { var fieldType = fieldInfo.FieldType; if (typeof(IObservableProperty).IsAssignableFrom(fieldType)) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); object observableValue = proxyFieldInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservablePropertyObjectSourceProxy(source, (IObservableProperty)observableValue)); } else { return(new LeafFieldObjectSourceProxy(source, fieldInfo)); } } var methodInfo = memberInfo as MethodInfo; if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void))) { return(new VoidMethodObjectSourceProxy(source, methodInfo)); } var eventInfo = memberInfo as EventInfo; if (eventInfo != null) { return(new EventObjectSourceProxy(source, eventInfo)); } return(null); }
public virtual object GetValue() { return(propertyInfo.GetValue(source)); }
protected virtual ISourceProxy CreateProxy(object source, IPathNode node) { IProxyType proxyType = source.GetType().AsProxy(); if (node is IndexedNode) { if (!(source is ICollection)) { throw new ProxyException("Type \"{0}\" is not a collection and cannot be accessed by index \"{1}\".", proxyType.Type.Name, node.ToString()); } var itemInfo = proxyType.GetItem(); if (itemInfo == null) { throw new MissingMemberException(proxyType.Type.FullName, "Item"); } var intIndexedNode = node as IntegerIndexedNode; if (intIndexedNode != null) { return(new IntItemNodeProxy((ICollection)source, intIndexedNode.Value, itemInfo)); } var stringIndexedNode = node as StringIndexedNode; if (stringIndexedNode != null) { return(new StringItemNodeProxy((ICollection)source, stringIndexedNode.Value, itemInfo)); } return(null); } var memberNode = node as MemberNode; if (memberNode == null) { return(null); } var memberInfo = memberNode.MemberInfo; if (memberInfo == null) { memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name); } if (memberInfo == null || memberInfo.IsStatic()) { throw new MissingMemberException(proxyType.Type.FullName, memberNode.Name); } var propertyInfo = memberInfo as PropertyInfo; if (propertyInfo != null) { IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy(); var valueType = proxyPropertyInfo.ValueType; if (typeof(IObservableProperty).IsAssignableFrom(valueType)) { object observableValue = proxyPropertyInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservableNodeProxy(source, (IObservableProperty)observableValue)); } else if (typeof(IInteractionRequest).IsAssignableFrom(valueType)) { object request = proxyPropertyInfo.GetValue(source); if (request == null) { return(null); } return(new InteractionNodeProxy(source, (IInteractionRequest)request)); } else { return(new PropertyNodeProxy(source, proxyPropertyInfo)); } } var fieldInfo = memberInfo as FieldInfo; if (fieldInfo != null) { IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy(); var valueType = proxyFieldInfo.ValueType; if (typeof(IObservableProperty).IsAssignableFrom(valueType)) { object observableValue = proxyFieldInfo.GetValue(source); if (observableValue == null) { return(null); } return(new ObservableNodeProxy(source, (IObservableProperty)observableValue)); } else if (typeof(IInteractionRequest).IsAssignableFrom(valueType)) { object request = proxyFieldInfo.GetValue(source); if (request == null) { return(null); } return(new InteractionNodeProxy(source, (IInteractionRequest)request)); } else { return(new FieldNodeProxy(source, proxyFieldInfo)); } } var methodInfo = memberInfo as MethodInfo; if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void))) { return(new MethodNodeProxy(source, methodInfo.AsProxy())); } var eventInfo = memberInfo as EventInfo; if (eventInfo != null) { return(new EventNodeProxy(source, eventInfo.AsProxy())); } return(null); }
//private static readonly ILog log = LogManager.GetLogger(typeof(UnityTargetProxyFactory)); public ITargetProxy CreateProxy(object target, BindingDescription description) { IProxyType type = target.GetType().AsProxy(); IProxyMemberInfo memberInfo = type.GetMember(description.TargetName); if (memberInfo == null) { memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic); } if (memberInfo == null) { throw new MissingMemberException(type.Type.FullName, description.TargetName); } UnityEventBase updateTrigger = null; if (!string.IsNullOrEmpty(description.UpdateTrigger)) { IProxyPropertyInfo updateTriggerPropertyInfo = type.GetProperty(description.UpdateTrigger); IProxyFieldInfo updateTriggerFieldInfo = updateTriggerPropertyInfo == null?type.GetField(description.UpdateTrigger) : null; if (updateTriggerPropertyInfo != null) { updateTrigger = updateTriggerPropertyInfo.GetValue(target) as UnityEventBase; } if (updateTriggerFieldInfo != null) { updateTrigger = updateTriggerFieldInfo.GetValue(target) as UnityEventBase; } if (updateTriggerPropertyInfo == null && updateTriggerFieldInfo == null) { throw new MissingMemberException(type.Type.FullName, description.UpdateTrigger); } //Other Property Type if (updateTrigger == null) /* by UniversalTargetProxyFactory */ { return(null); } } var propertyInfo = memberInfo as IProxyPropertyInfo; if (propertyInfo != null) { if (typeof(IObservableProperty).IsAssignableFrom(propertyInfo.ValueType)) { return(null); } if (typeof(UnityEventBase).IsAssignableFrom(propertyInfo.ValueType)) { //Event Type object unityEvent = propertyInfo.GetValue(target); Type[] paramTypes = GetUnityEventParametersType(propertyInfo.ValueType); return(CreateUnityEventProxy(target, (UnityEventBase)unityEvent, paramTypes)); } //Other Property Type if (updateTrigger == null)/* by UniversalTargetProxyFactory */ { return(null); } return(CreateUnityPropertyProxy(target, propertyInfo, updateTrigger)); } var fieldInfo = memberInfo as IProxyFieldInfo; if (fieldInfo != null) { if (typeof(IObservableProperty).IsAssignableFrom(fieldInfo.ValueType)) { return(null); } if (typeof(UnityEventBase).IsAssignableFrom(fieldInfo.ValueType)) { //Event Type object unityEvent = fieldInfo.GetValue(target); Type[] paramTypes = GetUnityEventParametersType(fieldInfo.ValueType); return(CreateUnityEventProxy(target, (UnityEventBase)unityEvent, paramTypes)); } //Other Property Type if (updateTrigger == null)/* by UniversalTargetProxyFactory */ { return(null); } return(CreateUnityFieldProxy(target, fieldInfo, updateTrigger)); } return(null); }