/// <summary> /// Initializes a new instance of the <see cref="ExtendableDtoBase"/> class. /// </summary> /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param> protected ExtendableDtoBase(IDictionary <string, object> arbitraryKeyValuePairs) { this._metadata = ExtendableDtoBase.metadataByDerivedType[this.GetType()]; Assumption.AssertNotNull(this._metadata, nameof(this._metadata)); if (arbitraryKeyValuePairs != null) { foreach (var key in arbitraryKeyValuePairs.Keys) { this[key] = arbitraryKeyValuePairs[key]; } } }
private static ExtendableDtoMetadata Build(Type extendableDtoType) { ExtendableDtoMetadata result = new ExtendableDtoMetadata(); result.ExtendableDtoType = extendableDtoType; Type reservedPropertiesNestedType = ReflectionUtil.GetNestedTypeByName( extendableDtoType, ExtendableDtoBase.ReservedPropertiesNestedTypeName, BindingFlags.Public | BindingFlags.Static ); Assumption.AssertNotNull(reservedPropertiesNestedType, nameof(reservedPropertiesNestedType)); var reservedAttributes = ReflectionUtil.GetAllPublicStaticFields(reservedPropertiesNestedType); Dictionary <string, PropertyInfo> reservedPropertyInfoByName = new Dictionary <string, PropertyInfo>(reservedAttributes.Length); result.ReservedPropertyInfoByReservedKey = reservedPropertyInfoByName; foreach (var reservedAttribue in reservedAttributes) { var property = extendableDtoType.GetProperty(reservedAttribue.Name, BindingFlags.Public | BindingFlags.Instance); Assumption.AssertNotNull(property, nameof(property)); string reservedKey = ReflectionUtil.GetStaticFieldValue <string>(reservedAttribue); Assumption.AssertNotNullOrWhiteSpace(reservedKey, nameof(reservedKey)); reservedPropertyInfoByName.Add(reservedKey, property); } return(result); }
static ExtendableDtoBase() { metadataByDerivedType = ExtendableDtoMetadata.BuildAll(); }