public static bool HasValue <T>(this DataboundAsset.DataboundValue <T> dbValue) { if (dbValue == null) { return(false); } return(dbValue.Value() != null); }
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)); }
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); }
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); }
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)); } }
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)); } }
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)); }
public static T Value <T>(this DataboundAsset.DataboundValue <T> dbValue) => GetVirtualizedValue(dbValue);
public static void SetDVValue <T>(this DataboundAsset.DataboundValue <T> input, object value) { input.Value = (T)value; }