public void Test_IsNotPrimitiveValueType() { var v1 = new TestValueType(); Assert.IsTrue(ReflectionMethods.IsNotPrimitiveValueType(v1)); var v2 = 0; Assert.IsFalse(ReflectionMethods.IsNotPrimitiveValueType(v2)); }
public XenProperty[] GetXenProperties(XenReflectionProperty[] refProps, bool includeValues = false) { if (refProps == null) { return(null); } if (SupportingTypes.Types == null) { return(null); } var result = new List <XenProperty>(); // The properties are in an intermediate state, right here. // a XenReflectionProperty is not meant to be returned in a request. // build xen properties. foreach (var curRef in refProps) { if (curRef.IsTargetEnum && SupportingTypes.IsRegistered(typeof(Enum))) { if (!SupportingTypes.IsRegistered(curRef, RegistrarMatches.TypeName | RegistrarMatches.Enum)) { continue; } } else { if (!SupportingTypes.IsRegistered(curRef, RegistrarMatches.TypeName)) { continue; } } var xenProp = new XenProperty { Path = new[] { curRef.TargetName }, Value = curRef.GetTargetObject(), CanRead = curRef.CanReadTarget, CanWrite = curRef.CanWriteTarget }; // is the current property an enumeration? if (curRef.IsTargetEnum && SupportingTypes.IsRegistered(typeof(Enum))) { var value = curRef.As <Enum>(); if (value != null) { Descriptor.SetPossibleValues(curRef, xenProp, value); if (xenProp.Value != null) { xenProp.Value = Enum.GetName(xenProp.Value.GetType(), value); } } } else { Descriptor.SetPossibleValues(curRef, xenProp); // non-primitive structures (not System.DateTime, but Xamarin.Forms.Point) if (ReflectionMethods.IsNotPrimitiveValueType(xenProp.Value)) { xenProp.XenType.Descriptor |= XenPropertyDescriptors.ValueType; var vtProps = XenPropertyMethods .GetPrimitiveValueTypeProperties(xenProp.Value) .ToArray(); if (vtProps.Length != 0) { foreach (var vtProp in vtProps) { Descriptor.SetPossibleValues(vtProp); if (vtProp.Value.GetType() != typeof(string)) { var tmp = Convert.ToString(vtProp.Value ?? string.Empty); vtProp.Value = tmp; } } // don't return values to the toolbox that will never be used. xenProp.Value = includeValues ? vtProps : null; } } // enumerables, collections, list. if (curRef.TargetType.IsKindOf(typeof(ICollection <>))) { xenProp.XenType.Descriptor |= XenPropertyDescriptors.Collection; } if (curRef.TargetType.IsKindOf(typeof(IList <>))) { xenProp.XenType.Descriptor |= XenPropertyDescriptors.List; } if (curRef.TargetType.IsKindOf(typeof(IEnumerable <>))) { xenProp.XenType.Descriptor |= XenPropertyDescriptors.Enumerable; var collection = xenProp.Value as IEnumerable <object>; if (collection != null) { var count = collection.Count(); xenProp.XenType.PossibleValues = new[] { count.ToString() }; if (includeValues == false) { // don't send the value back to the toolbox xenProp.Value = null; } } } /* * obj support? * if (!curRef.TargetType.GetTypeInfo().IsValueType && !curRef.TargetType.GetTypeInfo().IsPrimitive) * { * if (!curRef.TargetType.Namespace.StartsWith("System")) * { * var oProps = XenPropertyMethods * .GetObjectProperties(xenProp.Value) * .ToArray(); * * if (oProps.Length != 0) * { * foreach (var oProp in oProps) * { * Descriptor.SetPossibleValues(oProp); * * if (oProp.Value != null && oProp.Value.GetType() != typeof(string)) * { * var tmp = Convert.ToString(oProp.Value ?? string.Empty); * oProp.Value = tmp; * } * } * * // don't return values to the toolbox that will never be used. * xenProp.Value = includeValues ? oProps : null; * } * } * } */ } result.Add(xenProp); } return(result.ToArray()); }