Exemplo n.º 1
0
        public static bool HasValue <T>(this DataboundAsset.DataboundValue <T> dbValue)
        {
            if (dbValue == null)
            {
                return(false);
            }

            return(dbValue.Value() != null);
        }
Exemplo n.º 2
0
        public void Bind(DataboundAsset.DataboundValue databoundValue, string bindingName)
        {
            if (DataBindings.Any(x => x != null && x.Value.Value == databoundValue))
            {
                DataBindings.RemoveAll(x => x != null && x.Value.Value == databoundValue);
            }

            DataBindings.Add(new KeyValuePair <string, object>(bindingName, databoundValue));
        }
Exemplo n.º 3
0
        public static DataboundAsset.DataboundValue CreateDataboundValue(Type type, object def)
        {
            var dvType = typeof(DataboundAsset.DataboundValue <>);
            var constructedListType = dvType.MakeGenericType(type);

            object instance = Activator.CreateInstance(constructedListType);

            DataboundAsset.DataboundValue result = (DataboundAsset.DataboundValue)instance;

            result.ObjectValue = def;
            return(result);
        }
Exemplo n.º 4
0
        private static DataboundAsset.DataboundValue CreateDataboundValue(Type type)
        {
            //if (type == typeof(Color))
            //{
            //    return new DataboundAsset.DataboundValue<Color>();
            //}

            var dvType = typeof(DataboundAsset.DataboundValue <>);
            var constructedListType = dvType.MakeGenericType(type);

            object instance = Activator.CreateInstance(constructedListType);

            DataboundAsset.DataboundValue result = (DataboundAsset.DataboundValue)instance;

            return(result);
        }
Exemplo n.º 5
0
        public static DataboundAsset.DataboundValue <T> GetDBValue <T>(string input)
        {
            if (input.ToLower().Trim().Contains("boundto"))
            {
                var result = new DataboundAsset.DataboundValue <T>(default(T));

                List <KeyValuePair <string, string> > args = SplitArgs(input);

                if (args.Any(x => x.Key == "boundto"))
                {
                    string v = args.First(x => x.Key == "boundto").Value;

                    result.BoundTo = v;
                }


                if (args.Any(x => x.Key.ToLower() == "invert"))
                {
                    result.Invert = bool.Parse(args.First(x => x.Key.ToLower() == "invert").Value);
                }

                if (args.Any(x => x.Key == "bindingdirection"))
                {
                    result.BindingDirection = (BindType)Enum.Parse(typeof(BindType), args.First(x => x.Key == "bindingdirection").Value);
                }


                return(result);
            }
            else
            {
                string typeName = typeof(T).ToString();
                var    x        = typeof(T);
                if (x.Name == "Nullable`1")
                {
                    Type derp = Nullable.GetUnderlyingType(x);

                    T def = (T)ConvertValue(input, derp);
                    return(new DataboundAsset.DataboundValue <T>(def));
                }

                T defaultValue = (T)ConvertValue <T>(input);

                return(new DataboundAsset.DataboundValue <T>(defaultValue));
            }
        }
Exemplo n.º 6
0
        public static object GetDBerValue(string input, Type T)
        {
            object defaultVal = T.GetDefaultValue();

            if (input.ToLower().Trim().Contains("boundto"))
            {
                DataboundAsset.DataboundValue         result = CreateDataboundValue(T);
                List <KeyValuePair <string, string> > args   = SplitArgs(input);

                if (args.Any(x => x.Key.ToLower() == "boundto"))
                {
                    string v = args.First(x => x.Key == "boundto").Value;

                    result.BoundTo = v;
                }

                if (args.Any(x => x.Key.ToLower() == "invert"))
                {
                    result.Invert = bool.Parse(args.First(x => x.Key.ToLower() == "invert").Value);
                }

                if (args.Any(x => x.Key.ToLower() == "bindingdirection"))
                {
                    result.BindingDirection = (BindType)Enum.Parse(typeof(BindType), args.First(x => x.Key.ToLower() == "bindingdirection").Value);
                }

                return(result);
            }
            else
            {
                if (T.Name == "Nullable`1")
                {
                    Type derp = Nullable.GetUnderlyingType(T);

                    object def = ConvertValue(input, derp);
                    //todo def not set
                    return(CreateDataboundValue(T, def));
                }

                object defaultValue = ConvertValue(input, T);

                //todo defaultValue not set
                return(CreateDataboundValue(T, defaultValue));
            }
        }
Exemplo n.º 7
0
        public static T GetVirtualizedValue <T>(this DataboundAsset.DataboundValue <T> dbValue)
        {
            if (dbValue.Value == null && dbValue.ParentAsset == null && dbValue.BoundTo == null)
            {
                return(default(T));
            }

            if (dbValue.ParentAsset == null && dbValue.BoundTo == null)
            {
                return(dbValue.Value);
            }

            if (dbValue.ParentAsset == null)
            {
                return(default(T));
            }

            if (dbValue.Value != null && dbValue.BoundTo == null)
            {
                return(dbValue.Value);
            }

            return(dbValue.ParentAsset.GetVirtualizedValue(dbValue));
        }
Exemplo n.º 8
0
 public static T Value <T>(this DataboundAsset.DataboundValue <T> dbValue) => GetVirtualizedValue(dbValue);
Exemplo n.º 9
0
 public static void SetDVValue <T>(this DataboundAsset.DataboundValue <T> input, object value)
 {
     input.Value = (T)value;
 }