/// <summary> /// Gets the catel properties. /// </summary> /// <param name="type">Type of the model.</param> /// <param name="includeModelBaseProperties">if set to <c>true</c>, also include model base properties.</param> /// <returns>A hash set containing the Catel properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public Dictionary <string, MemberMetadata> GetCatelProperties(Type type, bool includeModelBaseProperties = false) { Argument.IsNotNull("type", type); var key = GetCacheKey(type, includeModelBaseProperties); return(_catelPropertiesCache.GetFromCacheOrFetch(key, () => { var dictionary = new Dictionary <string, MemberMetadata>(); var propertyDataManager = PropertyDataManager.Default; var catelTypeInfo = propertyDataManager.GetCatelTypeInfo(type); var properties = (from property in catelTypeInfo.GetCatelProperties() select property.Value); if (!includeModelBaseProperties) { properties = properties.Where(x => !x.IsModelBaseProperty); } foreach (var property in properties) { var memberMetadata = new MemberMetadata(type, property.Type, SerializationMemberGroup.CatelProperty, property.Name) { Tag = property }; var propertyInfo = property.GetPropertyInfo(type); if (propertyInfo != null && propertyInfo.PropertyInfo != null) { var nameOverride = GetNameOverrideForSerialization(propertyInfo.PropertyInfo); if (!string.IsNullOrWhiteSpace(nameOverride)) { memberMetadata.MemberNameForSerialization = nameOverride; } } dictionary[property.Name] = memberMetadata; } return dictionary; })); }
/// <summary> /// Gets the fields /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the fields.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary <string, MemberMetadata> GetFields(Type type) { Argument.IsNotNull("type", type); return(_fieldsCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary <string, MemberMetadata>(); var fieldNames = GetFieldNames(type); foreach (var field in fieldNames) { var fieldInfo = type.GetFieldEx(field); if (fieldInfo != null) { dictionary[field] = new MemberMetadata(type, fieldInfo.FieldType, SerializationMemberGroup.Field, field); } } return dictionary; })); }
/// <summary> /// Gets the regular properties. /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the regular properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary <string, MemberMetadata> GetRegularProperties(Type type) { Argument.IsNotNull("type", type); return(_regularPropertiesCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary <string, MemberMetadata>(); var regularPropertyNames = GetRegularPropertyNames(type); foreach (var property in regularPropertyNames) { var propertyInfo = type.GetPropertyEx(property); if (propertyInfo != null) { dictionary[property] = new MemberMetadata(type, propertyInfo.PropertyType, SerializationMemberGroup.RegularProperty, property); } } return dictionary; })); }
/// <summary> /// Gets the regular properties. /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the regular properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary <string, MemberMetadata> GetRegularProperties(Type type) { Argument.IsNotNull("type", type); return(_regularPropertiesCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary <string, MemberMetadata>(); var catelPropertyNames = GetCatelPropertyNames(type, true); var regularProperties = type.GetPropertiesEx(); foreach (var propertyInfo in regularProperties) { if (catelPropertyNames.Contains(propertyInfo.Name) || propertyInfo.DeclaringType == typeof(ModelBase)) { continue; } var memberMetadata = new MemberMetadata(type, propertyInfo.PropertyType, SerializationMemberGroup.RegularProperty, propertyInfo.Name) { Tag = propertyInfo }; var nameOverride = GetNameOverrideForSerialization(propertyInfo); if (!string.IsNullOrWhiteSpace(nameOverride)) { memberMetadata.MemberNameForSerialization = nameOverride; } dictionary[propertyInfo.Name] = memberMetadata; } return dictionary; })); }
/// <summary> /// Gets the fields /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the fields.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary<string, MemberMetadata> GetFields(Type type) { Argument.IsNotNull("type", type); return _fieldsCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary<string, MemberMetadata>(); var fieldNames = GetFieldNames(type); foreach (var field in fieldNames) { var fieldInfo = type.GetFieldEx(field); if (fieldInfo != null) { dictionary[field] = new MemberMetadata(type, fieldInfo.FieldType, SerializationMemberGroup.Field, field); } } return dictionary; }); }
/// <summary> /// Gets the regular properties. /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the regular properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary<string, MemberMetadata> GetRegularProperties(Type type) { Argument.IsNotNull("type", type); return _regularPropertiesCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary<string, MemberMetadata>(); var regularPropertyNames = GetRegularPropertyNames(type); foreach (var property in regularPropertyNames) { var propertyInfo = type.GetPropertyEx(property); if (propertyInfo != null) { dictionary[property] = new MemberMetadata(type, propertyInfo.PropertyType, SerializationMemberGroup.RegularProperty, property); } } return dictionary; }); }
/// <summary> /// Gets the fields /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the fields.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary<string, MemberMetadata> GetFields(Type type) { Argument.IsNotNull("type", type); return _fieldsCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary<string, MemberMetadata>(); var fields = type.GetFieldsEx(); foreach (var fieldInfo in fields) { if (fieldInfo.Name.Contains("__BackingField") || fieldInfo.DeclaringType == typeof (ModelBase)) { continue; } var memberMetadata = new MemberMetadata(type, fieldInfo.FieldType, SerializationMemberGroup.Field, fieldInfo.Name) { Tag = fieldInfo }; var nameOverride = GetNameOverrideForSerialization(fieldInfo); if (!string.IsNullOrWhiteSpace(nameOverride)) { memberMetadata.MemberNameForSerialization = nameOverride; } dictionary[fieldInfo.Name] = memberMetadata; } return dictionary; }); }
/// <summary> /// Gets the regular properties. /// </summary> /// <param name="type">Type of the model.</param> /// <returns>A hash set containing the regular properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> is <c>null</c>.</exception> public Dictionary<string, MemberMetadata> GetRegularProperties(Type type) { Argument.IsNotNull("type", type); return _regularPropertiesCache.GetFromCacheOrFetch(type, () => { var dictionary = new Dictionary<string, MemberMetadata>(); var catelPropertyNames = GetCatelPropertyNames(type, true); var regularProperties = type.GetPropertiesEx(); foreach (var propertyInfo in regularProperties) { if (catelPropertyNames.Contains(propertyInfo.Name) || propertyInfo.DeclaringType == typeof(ModelBase)) { continue; } var memberMetadata = new MemberMetadata(type, propertyInfo.PropertyType, SerializationMemberGroup.RegularProperty, propertyInfo.Name) { Tag = propertyInfo }; var nameOverride = GetNameOverrideForSerialization(propertyInfo); if (!string.IsNullOrWhiteSpace(nameOverride)) { memberMetadata.MemberNameForSerialization = nameOverride; } dictionary[propertyInfo.Name] = memberMetadata; } return dictionary; }); }
/// <summary> /// Gets the catel properties. /// </summary> /// <param name="type">Type of the model.</param> /// <param name="includeModelBaseProperties">if set to <c>true</c>, also include model base properties.</param> /// <returns>A hash set containing the Catel properties.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type" /> is <c>null</c>.</exception> public Dictionary<string, MemberMetadata> GetCatelProperties(Type type, bool includeModelBaseProperties = false) { Argument.IsNotNull("type", type); var key = GetCacheKey(type, includeModelBaseProperties); return _catelPropertiesCache.GetFromCacheOrFetch(key, () => { var dictionary = new Dictionary<string, MemberMetadata>(); var propertyDataManager = PropertyDataManager.Default; var catelTypeInfo = propertyDataManager.GetCatelTypeInfo(type); var properties = (from property in catelTypeInfo.GetCatelProperties() select property.Value); if (!includeModelBaseProperties) { properties = properties.Where(x => !x.IsModelBaseProperty); } foreach (var property in properties) { var memberMetadata = new MemberMetadata(type, property.Type, SerializationMemberGroup.CatelProperty, property.Name) { Tag = property }; var propertyInfo = property.GetPropertyInfo(type); if (propertyInfo != null && propertyInfo.PropertyInfo != null) { var nameOverride = GetNameOverrideForSerialization(propertyInfo.PropertyInfo); if (!string.IsNullOrWhiteSpace(nameOverride)) { memberMetadata.MemberNameForSerialization = nameOverride; } } dictionary[property.Name] = memberMetadata; } return dictionary; }); }