예제 #1
0
        public override bool TryParseIndex(string path, RangeInt cursor, out IWatchContext ctx)
        {
            if (ParserUtils.TryParseIntAt(path, ref cursor, out var index))
            {
                var       comps = GO.GetComponents <Component>();
                Component comp  = comps[index];

                //Type PropertyBagContextType = typeof(PropertyBagContext<>);
                //Type[] typeParams = new Type[] { comp.GetType() };
                //Type PropertyBagContextTypeGen = PropertyBagContextType.MakeGenericType(typeParams);
                //
                //ctx = (IWatchContext)Activator.CreateInstance(PropertyBagContextTypeGen, this, $"[{index}]", comp, ContextFieldInfo.MakeOperator($"[{index}]"));


                Type   PropertyPathContextType = typeof(PropertyPathContext <,>);
                Type[] typeParams = new Type[] { comp.GetType(), comp.GetType() };
                Type   PropertyBagContextTypeGen = PropertyPathContextType.MakeGenericType(typeParams);

                //public PropertyPathContext(IWatchContext parent, IWatchContext rootPathContext, string relativePath, ref TContainer container, PropertyPath propPath, ContextFieldInfo fieldInfo)
                ctx = (IWatchContext)Activator.CreateInstance(PropertyBagContextTypeGen, this, this, $"[{index}]", comp, null, ContextFieldInfo.MakeOperator($"[{index}]"));

                if (ctx != null)
                {
                    return(ctx != null);
                }
            }
            ctx = default;
            return(false);
        }
예제 #2
0
        public override bool TryParse(string path, ref RangeInt cursor, out IWatchContext ctx)
        {
            var c = cursor;

            if (ParserUtils.TryParseScopeSequenceRange(path, ref c, ParserUtils.DelemiterSquareBracket, out var seqIn, out var seqOut))
            {
                if (ParserUtils.TryParseIntAt(path, ref seqIn, out var index))
                {
                    var es = World.EntityManager.GetAllEntities();
                    for (int i = 0; i != es.Length; ++i)
                    {
                        if (es[i].Index == index)
                        {
                            cursor = c;
                            var ctnr = new EntityContainer(World.EntityManager, es[i]);
                            ctx = new PropertyPathContext <EntityContainer, EntityContainer>(this, this, $"[{es[i].Index}]", ctnr, null, ContextFieldInfo.MakeOperator($"[{es[i].Index}]"));
                            return(true);
                        }
                    }
                }
            }
            ctx = null;
            return(false);
        }