public override void ToDictionaryCore(Dictionary <string, object> dictionary, IPropertyMapper propertyMapper, bool includeAutoSelected) { Contract.Assert(dictionary != null); if (Name != null && (includeAutoSelected || !AutoSelected)) { string mappedName = propertyMapper.MapProperty(Name); if (String.IsNullOrEmpty(mappedName)) { throw Error.InvalidOperation(SRResources.InvalidPropertyMapping, Name); } dictionary.Add(mappedName, GetValue()); } }
public IDictionary <string, object> ToDictionary(Func <IEdmModel, IEdmStructuredType, IPropertyMapper> mapperProvider) { if (mapperProvider == null) { throw Error.ArgumentNull("mapperProvider"); } Dictionary <string, object> dictionary = new Dictionary <string, object>(); IEdmStructuredType type = GetEdmType().AsStructured().StructuredDefinition(); IPropertyMapper mapper = mapperProvider(GetModel(), type); if (mapper == null) { throw Error.InvalidOperation(SRResources.InvalidPropertyMapper, typeof(IPropertyMapper).FullName, type.FullTypeName()); } if (Container != null) { dictionary = Container.ToDictionary(mapper, includeAutoSelected: false); } // The user asked for all the structural properties on this instance. if (UseInstanceForProperties && UntypedInstance != null) { foreach (IEdmStructuralProperty property in type.StructuralProperties()) { object propertyValue; if (TryGetPropertyValue(property.Name, out propertyValue)) { string mappingName = mapper.MapProperty(property.Name); if (String.IsNullOrWhiteSpace(mappingName)) { throw Error.InvalidOperation(SRResources.InvalidPropertyMapping, property.Name); } dictionary[mappingName] = propertyValue; } } } return(dictionary); }