Esempio n. 1
0
        public void SetPossibleValues(XenReflectionProperty xRef, XenProperty xProp, Enum e)
        {
            if (xRef == null || xProp == null)
            {
                return;
            }

            xProp.XenType = CreateType(xRef);
            var item = GetItem(xProp.XenType.GetType());

            var gen    = new EnumGenerator();
            var result = gen.Get(e.GetType());

            if (item != null)
            {
                xProp.XenType.Descriptor = item.Descriptor;
            }

            xProp.XenType.PossibleValues = result;
            xProp.XenType.Descriptor    |= XenPropertyDescriptors.Literals;

            if (e.HasFlags())
            {
                xProp.XenType.Descriptor |= XenPropertyDescriptors.Flags;
            }
        }
Esempio n. 2
0
        public void SetPossibleValues(XenReflectionProperty xRef, XenProperty xProp)
        {
            if (xRef == null || xProp == null)
            {
                return;
            }

            xProp.XenType = CreateType(xRef);

            var entry = GetItem(xProp.Value?.GetType());

            if (entry?.Generator == null)
            {
                return;
            }

            var type = _typeFinder.Find(xProp.XenType.FullName);

            if (type == null)
            {
                return;
            }

            xProp.XenType.PossibleValues = entry.Generator.Get(type);

            if (xProp.XenType.PossibleValues?.Length > 0)
            {
                xProp.XenType.Descriptor |= XenPropertyDescriptors.Literals;
            }
        }
Esempio n. 3
0
 public XenType CreateType(XenReflectionProperty xRef)
 {
     return(new XenType
     {
         Descriptor = GetDescriptors(xRef.TargetType),
         FullName = xRef.TargetType.FullName,
     });
 }
Esempio n. 4
0
        public XenReflectionProperty Convert(object parent, object grandparent)
        {
            var xprop = new XenReflectionProperty
            {
                ParentObject      = parent,
                GrandParentObject = grandparent,
                TargetType        = GetMethod.ReturnType,
                CanReadTarget     = true,
                CanWriteTarget    = true,
                TargetName        = PropertyName,
                ParentType        = parent.GetType()
            };

            return(xprop);
        }
Esempio n. 5
0
        public void Contains_using_XenReflectionProperty()
        {
            Tr.SetTypes(typeof(int));

            var xProp = new XenReflectionProperty
            {
                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), XenPropertyDescriptors.None);

            var t1 = FakeEnumWithFlags.Test1;

            var xRef = new XenReflectionProperty
            {
                TargetType = typeof(FakeEnumWithFlags),
            };

            var xProp = new XenProperty
            {
                Value = t1
            };

            Dr.SetPossibleValues(xRef, xProp, t1);

            Assert.IsTrue(xProp.XenType.Descriptor.HasFlag(XenPropertyDescriptors.Flags | XenPropertyDescriptors.Literals));
        }
Esempio n. 7
0
        public bool IsRegistered(XenReflectionProperty 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);
        }