public void SetPossibleValues(UIReflectionProperty xRef, UIProperty xProp, Enum e) { if (xRef == null || xProp == null) { return; } xProp.UIType = CreateType(xRef); var item = GetItem(xProp.UIType.GetType()); var gen = new EnumGenerator(); var result = gen.Get(e.GetType()); if (item != null) { xProp.UIType.Descriptor = item.Descriptor; } xProp.UIType.PossibleValues = result; xProp.UIType.Descriptor |= UIPropertyDescriptors.Literals; if (e.HasFlags()) { xProp.UIType.Descriptor |= UIPropertyDescriptors.Flags; } }
public void SetPossibleValues(UIReflectionProperty xRef, UIProperty xProp) { if (xRef == null || xProp == null) { return; } xProp.UIType = CreateType(xRef); var entry = GetItem(xProp.Value?.GetType()); if (entry?.Generator == null) { return; } var type = _typeFinder.Find(xProp.UIType.FullName); if (type == null) { return; } xProp.UIType.PossibleValues = entry.Generator.Get(type); if (xProp.UIType.PossibleValues?.Length > 0) { xProp.UIType.Descriptor |= UIPropertyDescriptors.Literals; } }
public UIType CreateType(UIReflectionProperty xRef) { return(new UIType { Descriptor = GetDescriptors(xRef.TargetType), FullName = xRef.TargetType.FullName, }); }
public UIReflectionProperty Convert(object parent, object grandparent) { var xprop = new UIReflectionProperty { ParentObject = parent, GrandParentObject = grandparent, TargetType = GetMethod.ReturnType, CanReadTarget = true, CanWriteTarget = true, TargetName = PropertyName, ParentType = parent.GetType() }; return(xprop); }
public void Contains_using_UIReflectionProperty() { Tr.SetTypes(typeof(int)); var xProp = new UIReflectionProperty { TargetType = typeof(int) }; var usingTypeName = Tr.IsRegistered(xProp, RegistrarMatches.TypeName); var usingEnum = Tr.IsRegistered(xProp, RegistrarMatches.Enum); Assert.IsTrue(usingTypeName, "by TypeName"); Assert.IsFalse(usingEnum, "by Enum"); }
public void Test_flags_and_staticlist() { Dr.Add(typeof(FakeEnumWithFlags), UIPropertyDescriptors.None); var t1 = FakeEnumWithFlags.Test1; var xRef = new UIReflectionProperty { TargetType = typeof(FakeEnumWithFlags), }; var xProp = new UIProperty { Value = t1 }; Dr.SetPossibleValues(xRef, xProp, t1); Assert.IsTrue(xProp.UIType.Descriptor.HasFlag(UIPropertyDescriptors.Flags | UIPropertyDescriptors.Literals)); }
public bool IsRegistered(UIReflectionProperty prop, RegistrarMatches matches) { var nameMatch = Types .Any(t => t.FullName != null && t.FullName.Equals(prop.TargetType.FullName, StringComparison.CurrentCultureIgnoreCase)); if (matches.HasFlag(RegistrarMatches.TypeName | RegistrarMatches.Enum)) { return(nameMatch || prop.IsTargetEnum); } if (matches.HasFlag(RegistrarMatches.TypeName)) { return(nameMatch); } if (matches.HasFlag(RegistrarMatches.Enum)) { return(prop.IsTargetEnum); } return(false); }