public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            try
            {
                var propIdx = _context.FindProperty(binder.Name);
                if (!_context.IsPropReadable(propIdx))
                {
                    result = null;
                    return(false);
                }

                result = CustomMarshaller.ConvertToDynamicCLRObject(_context.GetPropValue(propIdx));
                return(true);
            }
            catch (PropertyAccessException)
            {
                result = null;
                return(false);
            }
            catch (ValueMarshallingException)
            {
                result = null;
                return(false);
            }
        }
        public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null)
        {
            IEnumerable <string> sourceProperties;
            IEnumerable <string> ignoredPropCollection;

            if (filledProperties == null)
            {
                string[] names = new string[source.GetPropCount()];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = source.GetPropName(i);
                }

                sourceProperties = names;
            }
            else
            {
                sourceProperties = filledProperties.Split(',')
                                   .Select(x => x.Trim())
                                   .Where(x => x.Length > 0)
                                   .ToArray();

                // Проверка существования заявленных свойств
                foreach (var item in sourceProperties)
                {
                    acceptor.FindProperty(item);
                }
            }

            if (ignoredProperties != null)
            {
                ignoredPropCollection = ignoredProperties.Split(',')
                                        .Select(x => x.Trim())
                                        .Where(x => x.Length > 0);
            }
            else
            {
                ignoredPropCollection = new string[0];
            }

            foreach (var srcProperty in sourceProperties.Where(x => !ignoredPropCollection.Contains(x)))
            {
                try
                {
                    var propIdx    = acceptor.FindProperty(srcProperty);
                    var srcPropIdx = source.FindProperty(srcProperty);

                    if (source.IsPropReadable(propIdx) && acceptor.IsPropWritable(propIdx))
                    {
                        acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx));
                    }
                }
                catch (PropertyAccessException)
                {
                }
            }
        }
        public void FillPropertyValuesStr(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null)
        {
            IEnumerable <string> sourceProperties;

            if (filledProperties == null)
            {
                string[] names = new string[source.GetPropCount()];
                for (int i = 0; i < names.Length; i++)
                {
                    names[i] = source.GetPropName(i);
                }

                if (ignoredProperties == null)
                {
                    sourceProperties = names;
                }
                else
                {
                    IEnumerable <string> ignoredPropCollection = ignoredProperties.Split(',')
                                                                 .Select(x => x.Trim())
                                                                 .Where(x => x.Length > 0);

                    sourceProperties = names.Where(x => !ignoredPropCollection.Contains(x));
                }
            }
            else
            {
                sourceProperties = filledProperties.Split(',')
                                   .Select(x => x.Trim())
                                   .Where(x => x.Length > 0);

                // Проверка существования заявленных свойств
                foreach (var item in sourceProperties)
                {
                    acceptor.FindProperty(item); // бросает PropertyAccessException если свойства нет
                }
            }


            foreach (var srcProperty in sourceProperties)
            {
                try
                {
                    var srcPropIdx = source.FindProperty(srcProperty);
                    var accPropIdx = acceptor.FindProperty(srcProperty); // бросает PropertyAccessException если свойства нет

                    if (source.IsPropReadable(srcPropIdx) && acceptor.IsPropWritable(accPropIdx))
                    {
                        acceptor.SetPropValue(accPropIdx, source.GetPropValue(srcPropIdx));
                    }
                }
                catch (PropertyAccessException)
                {
                    // игнорировать свойства Источника, которых нет в Приемнике
                }
            }
        }
        public void PublishProperty(string name, string alias)
        {
            var thisIndex = _thisPropIndexes.RegisterName(name, alias);
            var thatIndex = _inst.FindProperty(name);

            Debug.Assert(thatIndex >= 0);

            _propRedirects.Add(thisIndex, thatIndex);
        }
        public static IValue GetPropValue(this IRuntimeContextInstance context, string propName)
        {
            int propNum = context.FindProperty(propName);

            if (propNum == -1)
            {
                throw RuntimeException.InvalidArgumentValue(propName);
            }

            return(context.GetPropValue(propNum));
        }
Exemple #6
0
        public void SetProperty(IRuntimeContextInstance target, string prop, IValue value)
        {
            int propIdx;

            if (target is ScriptDrivenObject script)
            {
                propIdx = script.FindAnyProperty(prop);
            }
            else
            {
                propIdx = target.FindProperty(prop);
            }
            target.SetPropValue(propIdx, value);
        }
Exemple #7
0
        public IValue GetProperty(IRuntimeContextInstance target, string prop)
        {
            int propIdx;

            if (target is ScriptDrivenObject script)
            {
                propIdx = script.FindAnyProperty(prop);
            }
            else
            {
                propIdx = target.FindProperty(prop);
            }
            return(target.GetPropValue(propIdx));
        }
Exemple #8
0
        public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null)
        {
            var accReflector = acceptor as IReflectableContext;

            if (accReflector == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var srcReflector = source as IReflectableContext;

            if (srcReflector == null)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            IEnumerable <string> sourceProperties;
            IEnumerable <string> ignoredPropCollection;

            if (filledProperties == null)
            {
                sourceProperties = srcReflector.GetProperties().Select(x => x.Identifier);
            }
            else
            {
                sourceProperties = filledProperties.Split(',')
                                   .Select(x => x.Trim())
                                   .Where(x => x.Length > 0)
                                   .ToArray();

                // Проверка существования заявленных свойств
                foreach (var item in sourceProperties)
                {
                    acceptor.FindProperty(item);
                }
            }

            if (ignoredProperties != null)
            {
                ignoredPropCollection = ignoredProperties.Split(',')
                                        .Select(x => x.Trim())
                                        .Where(x => x.Length > 0);
            }
            else
            {
                ignoredPropCollection = new string[0];
            }

            foreach (var srcProperty in sourceProperties.Where(x => !ignoredPropCollection.Contains(x)))
            {
                try
                {
                    var propIdx    = acceptor.FindProperty(srcProperty);
                    var srcPropIdx = source.FindProperty(srcProperty);

                    acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx));
                }
                catch (PropertyAccessException)
                {
                }
            }
        }
        public void FillPropertyValues(IRuntimeContextInstance acceptor, IRuntimeContextInstance source, string filledProperties = null, string ignoredProperties = null)
        {
            var accReflector = acceptor as IReflectableContext;
            if (accReflector == null)
                throw RuntimeException.InvalidArgumentValue();
            
            var srcReflector = source as IReflectableContext;
            if (srcReflector == null)
                throw RuntimeException.InvalidArgumentValue();

            IEnumerable<string> sourceProperties;
            IEnumerable<string> ignoredPropCollection;
            if(filledProperties == null)
            {
                sourceProperties = srcReflector.GetProperties().Select(x => x.Identifier);
            }
            else
            {
                sourceProperties = filledProperties.Split(',')
                    .Select(x => x.Trim())
                    .Where(x => x.Length > 0)
                    .ToArray();

                // Проверка существования заявленных свойств
                foreach (var item in sourceProperties)
                {
                    acceptor.FindProperty(item);
                }
            }

            if(ignoredProperties != null)
            {
                ignoredPropCollection = ignoredProperties.Split(',')
                    .Select(x => x.Trim())
                    .Where(x => x.Length > 0);
            }
            else
            {
                ignoredPropCollection = new string[0];
            }

            foreach (var srcProperty in sourceProperties.Where(x=>!ignoredPropCollection.Contains(x)))
            {
                try
                {
                    var propIdx = acceptor.FindProperty(srcProperty);
                    var srcPropIdx = source.FindProperty(srcProperty);

                    acceptor.SetPropValue(propIdx, source.GetPropValue(srcPropIdx));

                }
                catch(PropertyAccessException)
                {
                }

            }

        }