QSharp.QNode[] SaveProp(object item, ImmutablePropertyInfo prop, bool isRef = false) { var child = prop.Value(item); if (IsCollectionType(prop.Type)) { if (child == null) { return(Array <QSharp.QNode> .Empty); } var elementType = Collection_ElementType(prop.Type); if (elementType == typeof(object)) { elementType = null; } return(child.As <System.Collections.IEnumerable>() .Cast <object>() .Select(element => Save(element, isRef, itemType: elementType)) .ToArray()); } else { return child != null ? new[] { Save(child, isRef, itemType: prop.ReducedType != typeof(object) ? prop.ReducedType : null) } } : Array <QSharp.QNode> .Empty; }
//static string ToText(int value) //{ // if (value == 0) // return "0"; // if (value == int.MinValue) // return int.MinValue.ToString(); // var isNegative = false; // if (value < 0) // { // isNegative = true; // value = -value; // } // var chars = new List<char>(); // for (;value > 0; ) // { // chars.Add((char)('0' + (value % 10))); // value /= 10; // } // if (isNegative) // chars.Add('-'); // chars.Reverse(); // return new string(chars.ToArray()); //} public object GetId(object item, ImmutablePropertyInfo idProperty) { if (idProperty == null) { return(null); } //var value = MetaTech.Library.ReflectionExtension.ReflectionHelper._P<object>(item, idProperty.Name); var value = idProperty.Value(item); if (value == null) { return(null); } if (IsPrimitiveType(idProperty.Type)) { return(value); } var type = idProperty.Type; var typeInfo = SerializeInfoByType(type); return(GetId(value, typeInfo.IdProperty)); }
public SerializeTypeInfo(ImmutablePropertyInfo idProperty, ImmutablePropertyInfo[] properties, Dictionary <string, string> refProperties, Dictionary <string, PushInfo[]> pushes, System.Reflection.ConstructorInfo constructor) { this.IdProperty = idProperty; this.Properties = properties; this.Properties_Wo_Id = properties.Where(property => property != idProperty).ToArray(); this.RefProperties = refProperties; this.Pushes = pushes; this.Constructor = constructor; if (constructor != null) { var parameters = constructor.GetParameters(); this.Parameters = parameters .Select(parameter => { var pName = ToUpper(parameter.Name); return(new SerializeParameterInfo(pName, parameter.ParameterType, IdProperty?.Name == pName, refProperties.Find(pName), pushes.Find(pName))); } ) .ToArray(); this.ParameterIndexByName = this.Parameters.Select((p, i) => new { p.Name, i }) .ToDictionary(pair => pair.Name, pair => pair.i); this.Construct = constructor.ToFunc(parameters); } //if (idProperty != null && idProperty.Field != null && idProperty.Field.DeclaringType == typeof(Planet)) //{ // Construct = values => new Planet((long)values[0], (int)values[1], (int)values[2], (int)values[3], (int)values[4], (int)values[5], (int)values[6]); //} }
public object SaveId(object item, ImmutablePropertyInfo idProperty) { return(GetId(item, idProperty) ?? "q"); }