コード例 #1
0
ファイル: ReferenceMapper.cs プロジェクト: Vytek/Tweach
        void MapChildMembers(IReference parentReference, int depth = 0)
        {
            depth++;
            if (depth > maxDepth)
            {
                throw new System.Exception("Serialization depth limit reached. Recursive reference?\nTrace:\n" + Utilities.UpwardsDebugTraceRecursive(parentReference, depth));
            }

            var parentValue = parentReference.GetValue();
            var parentType  = parentValue.GetType();

            if (typeof(IList).IsAssignableFrom(parentType))
            {
                var parentIListValue = (IList)parentValue;

                for (int i = 0; i < parentIListValue.Count; i++)
                {
                    var memberReference = new MemberReference(parentReference, i);
                    SetMemberValue(parentIListValue[i], memberReference, depth);
                    parentReference.AddMember(memberReference);
                }
            }
            else
            {
                IEnumerable <MemberInfo> memberInfos;

                if (!memberTypes.ContainsKey(parentType))
                {
                    memberInfos = parentType
                                  .GetMembers(Utilities.GetBindingFlags(mapInstance, mapStatic, mapPublic, mapNonPublic))
                                  .Where(m => EvaluateMemberInfo(m));

                    memberTypes.Add(parentType, memberInfos.ToList());
                }
                else
                {
                    memberInfos = memberTypes[parentType];
                }

                foreach (var memberInfo in memberInfos)
                {
                    if (!TryGetMemberValue(memberInfo, parentReference.GetValue(), out var memberValue))
                    {
                        continue;
                    }

                    var value = new MemberReference(parentReference, memberInfo);

                    SetMemberValue(memberValue, value, depth);

                    parentReference.AddMember(value);
                }
            }
        }
コード例 #2
0
            public override object GetValue(object obj, object[] index)
            {
                object result = null;

                //always obj == Owner
                var c = (Component_Switch)obj;

                object value;

                if (c.propertyValues.TryGetValue(Signature, out value))
                {
                    IReference iReference = value as IReference;
                    if (iReference != null)
                    {
                        value = iReference.GetValue(obj);
                        SetValue(obj, value, Indexers);
                    }
                    result = value;
                }

                //check the type. result can contains value with another type after change the type of property.
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #3
0
            public override object GetValue(object obj, object[] index)
            {
                object result = null;

                //always obj == Owner
                Component_InvokeMember c = (Component_InvokeMember)obj;

                //!!!!так?
                if (invoke && !c.FlowSupport)
                {
                    c.Invoke();
                }

                object value;

                if (c.propertyValues.TryGetValue(Signature, out value))
                {
                    //update value for Reference type
                    if (referenceSupport)
                    {
                        //convert from ReferenceNoValue
                        if (value != null && value is ReferenceNoValue)
                        {
                            value = ReferenceUtility.MakeReference(ReferenceUtility.GetUnreferencedType(Type.GetNetType()), ((ReferenceNoValue)value).GetByReference);
                        }

                        IReference iReference = value as IReference;
                        if (iReference != null)
                        {
                            //!!!!try catch? где еще так

                            //get value by reference
                            //!!!!
                            value = iReference.GetValue(obj);
                            //value = iReference.GetValue( Owner );

                            //!!!!?
                            if (!ReadOnly)                             //!!!!new
                            {
                                //!!!!
                                SetValue(obj, value, Indexers);
                                //SetValue( Owner, value, Indexers );
                            }
                        }
                    }
                    result = value;
                }

                //check the type. result can contains value with another type after change the type of property.
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #4
0
            public override object GetValue(object obj, object[] index)
            {
                object result = null;

                var c     = (Component_SetVariable)obj;
                var value = c.valuePropertyValue;

                //update value for Reference type
                IReference iReference = value as IReference;

                if (iReference != null)
                {
                    //get value by reference
                    value = iReference.GetValue(obj);
                    SetValue(obj, value, Indexers);
                }
                result = value;

                //check the type. result can contains value with another type after change the type of property.
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #5
0
 public MemberReference(IReference parentFieldCollection, int arrayIndex)
 {
     this.parentReference = parentFieldCollection;
     this.parentValue     = parentFieldCollection.GetValue();
     this.arrayIndex      = arrayIndex;
     isArrayMember        = true;
 }
コード例 #6
0
            public object GetValue(object obj, object[] index, bool allowInvoke)
            {
                object result = null;

                //always obj == Owner
                var c = (Component_CSharpScript)obj;

                //!!!!так?
                if (allowInvoke && invoke && !c.FlowSupport)
                {
                    c.Invoke();
                }

                object value;

                if (c.propertyValues.TryGetValue(Signature, out value))
                {
                    //update value for Reference type
                    if (referenceSupport)
                    {
                        IReference iReference = value as IReference;
                        if (iReference != null)
                        {
                            //!!!!try catch? где еще так

                            //get value by reference
                            //!!!!
                            value = iReference.GetValue(obj);
                            //value = iReference.GetValue( Owner );

                            //!!!!?
                            if (!ReadOnly)                             //!!!!new
                            {
                                //!!!!
                                SetValue(obj, value, Indexers);
                                //SetValue( Owner, value, Indexers );
                            }
                        }
                    }
                    result = value;
                }

                //check the type. result can contains value with another type after change the type of property.
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #7
0
            public override object GetValue(object obj, object[] index)
            {
                var c = (Component_DeclareVariable)obj;

                object result = null;

                object value            = null;
                bool   valueGotFromFlow = false;

                //get value from current flow
                var currentFlow = Flow.CurrentFlow;

                if (currentFlow != null)
                {
                    if (currentFlow.GetVariable(c.GetVariableName(), out object unrefValue))
                    {
                        value            = ReferenceUtility.MakeReference(TypeUnreferenced.GetNetType(), unrefValue, "");
                        valueGotFromFlow = true;
                    }
                }

                //get init value
                if (!valueGotFromFlow)
                {
                    value = c.valuePropertyValue;

                    //update value for Reference type
                    IReference iReference = value as IReference;
                    if (iReference != null)
                    {
                        //get value by reference
                        value = iReference.GetValue(obj);
                        SetValue(obj, value, Indexers);
                    }
                }

                result = value;

                //check the type. result can contains value with another type after change the type of property.
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #8
0
        public override void RenderNodeReferences(Component_FlowGraph_DocumentWindow window, Component_FlowGraphNode node,
                                                  Dictionary <Component, List <Component_FlowGraphNode> > objectToNodes,
                                                  Dictionary <Component_FlowGraphNode.Representation.Item, EditorRenderSelectionState> referenceSelectionStates,
                                                  out Component_FlowGraphNode.Representation.Item outMouseOverReference)
        {
            outMouseOverReference = null;

            var representation = node.GetRepresentation();
            var renderer       = window.ViewportControl.Viewport.CanvasRenderer;

            for (int nItem = 0; nItem < representation.Items.Count; nItem++)
            {
                var item = representation.Items[nItem];

                //references from input
                if (item.Input != null)
                {
                    var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty;
                    if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) &&
                        !MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced))
                    {
                        Component obj = itemProperty.Owner.Owner.ControlledObject;
                        if (obj != null)
                        {
                            var        v          = itemProperty.Property.GetValue(obj, null);
                            IReference iReference = v as IReference;
                            if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference))
                            {
                                iReference.GetMember(obj, out object destObject, out Metadata.Member destMember);
                                var destProperty = destMember as Metadata.Property;
                                if (destProperty != null)
                                {
                                    //reference to property

                                    //!!!!только компоненты? статичные свойства тоже нельзя?
                                    var destComponent = destObject as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep = destNode.GetRepresentation();
                                            Component_FlowGraphNode.Representation.ItemProperty destSocket;
                                            if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket))
                                            {
                                                if (destSocket.Output != null)
                                                {
                                                    var from = GetSocketPositionInUnits(item, true);
                                                    var to   = GetSocketPositionInUnits(destSocket, false);

                                                    if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                    {
                                                        state = EditorRenderSelectionState.None;
                                                    }

                                                    ColorValue color;
                                                    if (state != EditorRenderSelectionState.None)
                                                    {
                                                        color = GetColorMultiplierSelectionState(state);
                                                    }
                                                    else
                                                    {
                                                        color = new ColorValue(0.5, 0.5, 0.5);
                                                    }
                                                    //ColorValue color = GetColorMultiplierSelectionState( state );

                                                    window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver);

                                                    if (mouseOver && outMouseOverReference == null)
                                                    {
                                                        outMouseOverReference = item;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //reference to Component

                                    var unrefValue    = ReferenceUtility.GetUnreferencedValue(iReference.GetValue(obj));
                                    var destComponent = unrefValue as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep    = destNode.GetRepresentation();
                                            var destSocket = destRep.ItemObject;
                                            if (destSocket != null)
                                            {
                                                var from = GetSocketPositionInUnits(item, true);
                                                var to   = GetSocketPositionInUnits(destSocket, false);

                                                if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                {
                                                    state = EditorRenderSelectionState.None;
                                                }

                                                ColorValue color;
                                                if (state != EditorRenderSelectionState.None)
                                                {
                                                    color = GetColorMultiplierSelectionState(state);
                                                }
                                                else
                                                {
                                                    color = new ColorValue(0.5, 0.5, 0.5);
                                                }
                                                //ColorValue color = GetColorMultiplierSelectionState( state );

                                                window.GetFlowGraphStyle().RenderReference(window, from, true, to, color, out bool mouseOver);

                                                if (mouseOver && outMouseOverReference == null)
                                                {
                                                    outMouseOverReference = item;
                                                }
                                            }
                                        }
                                    }

                                    //!!!!invalid reference
                                }
                            }
                        }
                    }
                }

                //references from output (FlowInput)
                if (item.Output != null)
                {
                    var itemProperty = item as Component_FlowGraphNode.Representation.ItemProperty;
                    if (itemProperty != null && ReferenceUtility.IsReferenceType(itemProperty.Property.Type.GetNetType()) &&
                        MetadataManager.GetTypeOfNetType(typeof(FlowInput)).IsAssignableFrom(itemProperty.Property.TypeUnreferenced))
                    {
                        Component obj = itemProperty.Owner.Owner.ControlledObject;
                        if (obj != null)
                        {
                            var        v          = itemProperty.Property.GetValue(obj, null);
                            IReference iReference = v as IReference;
                            if (iReference != null && !string.IsNullOrEmpty(iReference.GetByReference))
                            {
                                iReference.GetMember(obj, out object destObject, out Metadata.Member destMember);

                                var destProperty = destMember as Metadata.Property;
                                if (destProperty != null)
                                {
                                    //!!!!только компоненты? статичные свойства тоже нельзя?
                                    var destComponent = destObject as Component;
                                    if (destComponent != null && objectToNodes.TryGetValue(destComponent, out List <Component_FlowGraphNode> destNodes))
                                    {
                                        foreach (var destNode in destNodes)
                                        {
                                            var destRep = destNode.GetRepresentation();
                                            Component_FlowGraphNode.Representation.ItemProperty destSocket;
                                            if (destRep.ItemByProperty.TryGetValue(destProperty, out destSocket))
                                            {
                                                if (destSocket.Input != null)
                                                {
                                                    var from = GetSocketPositionInUnits(item, false);
                                                    var to   = GetSocketPositionInUnits(destSocket, true);

                                                    if (!referenceSelectionStates.TryGetValue(item, out EditorRenderSelectionState state))
                                                    {
                                                        state = EditorRenderSelectionState.None;
                                                    }

                                                    ColorValue color;
                                                    if (state != EditorRenderSelectionState.None)
                                                    {
                                                        color = GetColorMultiplierSelectionState(state);
                                                    }
                                                    else
                                                    {
                                                        color = new ColorValue(0.3, 0.3, 1);
                                                    }
                                                    //ColorValue color = GetColorMultiplierSelectionState( state );

                                                    window.GetFlowGraphStyle().RenderReference(window, from, false, to, color, out bool mouseOver);

                                                    if (mouseOver && outMouseOverReference == null)
                                                    {
                                                        outMouseOverReference = item;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //!!!!invalid reference
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
            public override object GetValue(object obj, object[] index)
            {
                object result = null;

                //!!!!
                //if( creator.GetAccessor.ReferenceSpecified )
                //{
                //	//with Get accessor

                //	var body = creator.GetAccessor.Value;
                //	if( body != null )
                //	{
                //		result = body.Invoke( obj, new object[ 0 ] );

                //		//!!!!
                //	}
                //}
                //else
                {
                    //without Get accessor

                    string key;
                    IDictionary <string, object> dictionary;
                    if (!Static)
                    {
                        Component c = (Component)obj;
                        key        = GetKey();
                        dictionary = c.VirtualMemberValues;
                    }
                    else
                    {
                        key        = GetVirtualMemberValuesStaticKey();
                        dictionary = virtualMemberValuesStatic;
                    }

                    //Component c = (Component)obj;
                    //if( c.VirtualMemberValues != null && c.VirtualMemberValues.TryGetValue( GetKey(), out object value ) )
                    if (!string.IsNullOrEmpty(key) && dictionary != null && dictionary.TryGetValue(key, out object value))
                    {
                        //update value for Reference type
                        if (referenceSupport)
                        {
                            IReference iReference = value as IReference;
                            if (iReference != null)
                            {
                                //get value by reference
                                //!!!!new
                                value = iReference.GetValue(obj);
                                SetValue(obj, value, Indexers);
                                //value = iReference.GetValue( Creator );
                                //SetValue( Creator, value, Indexers );
                            }
                        }

                        result = value;
                    }

                    //if no value then get default value
                    if (result == null && DefaultValueSpecified && creator.defaultValueProperty != null)
                    {
                        result = creator.defaultValueProperty.GetValue(creator, null);
                    }
                }

                //check the type. result can contains value with another type after change the type of property.
                //!!!!
                //var unrefType = TypeUnreferenced;
                if (result != null && !Type.IsAssignableFrom(MetadataManager.MetadataGetType(result)))
                {
                    result = null;
                }
                if (result == null && Type.GetNetType().IsValueType)
                {
                    result = Type.InvokeInstance(null);
                }

                return(result);
            }
コード例 #10
0
 public MemberReference(IReference parentFieldCollection, MemberInfo memberInfo)
 {
     this.parentReference = parentFieldCollection;
     this.parentValue     = parentFieldCollection.GetValue();
     this.memberInfo      = memberInfo;
 }