/// <summary> /// Inspects the fields for the type specified. /// </summary> /// <param name="type"> /// The type to inspect. /// </param> /// <returns> /// The inspected fields. /// </returns> private static IDictionary <string, InspectedProperty> InspectFields(Type type) { var inspectedProperties = new StringDictionary <InspectedProperty, StringComparerOrdinalIgnoreCase>(); for (var t = type; t != typeof(object) && t != null; t = t.BaseType) { var fields = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); //// TODO correct flattening (duplicated private field names) //// TODO add any filter if required foreach (var field in fields) { if (!field.FieldType.IsTransient()) { var name = field.SerializableName(); if (!inspectedProperties.ContainsKey(name)) { var inspectedProperty = new InspectedProperty(type, field); if (inspectedProperty.HasSetter && inspectedProperty.HasGetter && !inspectedProperty.IsTransient) { inspectedProperties.Add(name, inspectedProperty); } } else { ////TODO ? throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, @"Ambiguous field {0} in {1}", name, type), "type"); } } } } return(inspectedProperties); }
/// <summary> /// Initializes a new instance of the <see cref="KeyPropertyKeyBinding"/> class. /// </summary> /// <param name="inspectedProperty"> /// The inspected property. /// </param> /// <param name="columnBinding"> /// The column binding. /// </param> /// <exception cref="ArgumentException"> /// If the <paramref name="inspectedProperty"/> does not have an entity key. /// </exception> internal KeyPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding) : base(inspectedProperty, columnBinding) { if (!inspectedProperty.HasKey) { throw new ArgumentException("Invalid property, missing entity key", "inspectedProperty"); } this.get = inspectedProperty.Getter; this.set = inspectedProperty.Setter; }
/// <summary> /// Gets the inspected property by the alternate name. /// </summary> /// <param name="name"> /// The property name. /// </param> /// <param name="alternateName"> /// The alternate property name. /// </param> /// <returns> /// The inspected property or null. /// </returns> internal InspectedProperty GetProperty(string name, string alternateName) { InspectedProperty inspectedProperty = null; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(alternateName)) { this.inspectedProperties.TryGetValue(name, out inspectedProperty); if (inspectedProperty != null && !this.inspectedProperties.ContainsKey(alternateName)) { this.inspectedProperties.Add(alternateName, inspectedProperty); } } return(inspectedProperty); }
/// <summary> /// Initializes a new instance of the <see cref="InspectedPropertyKeyBinding"/> class. /// </summary> /// <param name="inspectedProperty"> /// The inspected property. /// </param> /// <param name="columnBinding"> /// The column binding. /// </param> protected InspectedPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding) : base(inspectedProperty.InspectedType, columnBinding) { }
/// <summary> /// Writes the specified property. /// </summary> /// <param name="serializer"> /// The serializer. /// </param> /// <param name="inspectedProperty"> /// The inspected property. /// </param> /// <param name="any"> /// The object to which the property belongs. /// </param> private static void WriteProperty(Serializer serializer, InspectedProperty inspectedProperty, object any) { var value = inspectedProperty.Getter(any); if (value == null) { Encoder.WriteTag(serializer.BinaryWriter, Tags.Null); } else { serializer.Write(inspectedProperty.PropertyType, value.GetType(), value); } }
/// <summary> /// Encodes the specified property. /// </summary> /// <param name="serializer"> /// The serializer. /// </param> /// <param name="inspectedProperty"> /// The inspected property. /// </param> /// <param name="encoderInfo"> /// The encoder info. /// </param> /// <param name="any"> /// The object to which the property belongs. /// </param> private static void EncodeProperty(Serializer serializer, InspectedProperty inspectedProperty, EncoderInfo encoderInfo, object any) { var value = inspectedProperty.Getter(any); if (value == null) { Encoder.WriteTag(serializer.BinaryWriter, Tags.Null); } else { serializer.Encode(encoderInfo, value, true); } }
/// <summary> /// Initializes a new instance of the <see cref="EntityScanTarget"/> class. /// </summary> /// <param name="property"> /// The inspected property. /// </param> /// <param name="entitySpec"> /// The entity specification. /// </param> /// <param name="target"> /// The scan target. /// </param> internal EntityScanTarget(InspectedProperty property, EntitySpec entitySpec, object target) : base(property.PropertyType, entitySpec) { this.target = target; this.setter = property.Setter; }
/// <summary> /// Initializes a new instance of the <see cref="StringPropertyKeyBinding"/> class. /// </summary> /// <param name="inspectedProperty"> /// The inspected property. /// </param> /// <param name="columnBinding"> /// The column binding. /// </param> internal StringPropertyKeyBinding(InspectedProperty inspectedProperty, IColumnBinding columnBinding) : base(inspectedProperty, columnBinding) { this.get = inspectedProperty.Getter; this.set = inspectedProperty.Setter; }