예제 #1
0
        public static T GetValue <T>(this SDK.MetaDataKeyAttribute attrib, SDK.ContentObject instance, object defval)
        {
            object value = defval;

            if (attrib is SDK.MetaDataAttribute inputValue)
            {
                value = inputValue.Value;
            }

            if (attrib is SDK.MetaDataEvaluateAttribute evalValue)
            {
                if (instance == null)
                {
                    throw new ArgumentNullException(nameof(instance));
                }

                if (evalValue.SharedType != null)
                {
                    instance = instance.GetSharedSettings(evalValue.SharedType);
                }

                var propName = evalValue.PropertyName;
                value = instance.TryEvaluate(propName);
            }

            return((T)typeof(T).GetTypeInfo().ConvertBindableValue(value));
        }
예제 #2
0
        public static MemberInfo TryGetReflectedMember(this SDK.ContentObject nodeInstance, String key)
        {
            var pinfo = nodeInstance
                        .GetType()
                        .GetTypeInfo()
                        .FlattenedProperties()
                        .FirstOrDefault(item => item.Name == key);

            if (pinfo != null)
            {
                return(pinfo);
            }

            var minfo = nodeInstance
                        .GetType()
                        .GetTypeInfo()
                        .FlattenedMethods()
                        .FirstOrDefault(item => item.Name == key);

            if (minfo != null)
            {
                return(minfo);
            }

            return(null);
        }
예제 #3
0
        public static void ClearDependencyBindings(this SDK.ContentObject source, IPropertyProvider properties)
        {
            var bindings = CreateBindings(source, properties);

            foreach (var binding in bindings.OfType <Bindings.DependencyBinding>())
            {
                binding.ClearEvaluatedResult();
            }
        }
예제 #4
0
        public static IEnumerable <Bindings.MemberBinding> CreateBindings(this SDK.ContentObject source, IPropertyProvider properties)
        {
            if (source == null)
            {
                return(Enumerable.Empty <Bindings.MemberBinding>());
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            return(_CreateBindings(source, tinfo => tinfo.FlattenedProperties(), properties)
                   .Concat(_CreateBindings(source, tinfo => tinfo.FlattenedMethods(), properties)));
        }
예제 #5
0
        public static PathString GetRelativeSourcePath(this SDK.ContentObject instance, string absoluteSourcePath)
        {
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            if (instance.BuildContext != null)
            {
                return(new PathString(instance.BuildContext.GetRelativeToSource(absoluteSourcePath)));
            }

            // build context is only available during evaluation,
            // if it's missing, we fall back to the pipeline context
            var pipeline = instance.Owner as Evaluation.PipelineInstance;
            var buildctx = pipeline.BuildSettings;

            return(new PathString(buildctx.SourceDirectory).MakeRelativePath(absoluteSourcePath));
        }
예제 #6
0
        public static Object TryEvaluate(this SDK.ContentObject nodeInstance, String key)
        {
            var xinfo = nodeInstance.TryGetReflectedMember(key);

            if (xinfo is PropertyInfo pinfo)
            {
                return(pinfo.GetValue(nodeInstance));
            }
            if (xinfo is FieldInfo finfo)
            {
                return(finfo.GetValue(nodeInstance));
            }
            if (xinfo is MethodInfo minfo)
            {
                return(minfo.Invoke(nodeInstance, null));
            }

            return(null);
        }
예제 #7
0
        public static void EvaluateBindings(this SDK.ContentObject source, IPropertyProvider properties, Func <Guid, Object> dependencyEvaluator)
        {
            var bindings = CreateBindings(source, properties);

            foreach (var binding in bindings.OfType <Bindings.ValueBinding>())
            {
                binding.CopyValueToInstance();
            }

            if (dependencyEvaluator == null)
            {
                return;
            }

            foreach (var binding in bindings.OfType <Bindings.DependencyBinding>())
            {
                binding.EvaluateAndAssign(dependencyEvaluator);
            }
        }
예제 #8
0
        private static Bindings.MemberBinding[] _CreateBindings(SDK.ContentObject source, Func <TypeInfo, IEnumerable <MemberInfo> > func, IPropertyProvider properties)
        {
            var members = func(source.GetType().GetTypeInfo());

            var bindings = new List <Bindings.MemberBinding>();

            foreach (var minfo in members)
            {
                var attrib = minfo.GetInputDescAttribute();
                if (attrib == null)
                {
                    continue;
                }

                var desc = new Bindings.MemberBinding.Description()
                {
                    Member     = minfo,
                    Properties = properties,
                    Target     = source
                };

                var binding = _CreateBinding(attrib, desc);
                if (binding == null)
                {
                    continue;
                }

                bindings.Add(binding);
            }

            if (true) // we interconnect all the VALUE bindings , so when a value of a binding is changed, all of them raise a NotifyPropertyChanged, so they can, more or less, work as a basic state machine
            {
                var valueBindings = bindings.OfType <Bindings.ValueBinding>().ToArray();

                foreach (var vb in valueBindings)
                {
                    vb._AllValueBindings = valueBindings;
                }
            }

            return(bindings.ToArray());
        }
예제 #9
0
        public static void TryAssign(this SDK.ContentObject nodeInstance, MemberInfo xinfo, Object value)
        {
            if (xinfo is PropertyInfo pinfo)
            {
                value = pinfo
                        .PropertyType
                        .GetTypeInfo()
                        .ConvertBindableValue(value);

                pinfo.SetValue(nodeInstance, value);
                return;
            }

            if (xinfo is FieldInfo finfo)
            {
                value = finfo
                        .FieldType
                        .GetTypeInfo()
                        .ConvertBindableValue(value);

                finfo.SetValue(nodeInstance, value);
                return;
            }

            if (xinfo is MethodInfo minfo)
            {
                value = minfo
                        .GetParameters()[0]
                        .ParameterType
                        .GetTypeInfo()
                        .ConvertBindableValue(value);

                minfo.Invoke(nodeInstance, new Object[] { value });
                return;
            }
        }