} // CurrentDataSource public IEnumerable <KeyValuePair <string, object> > GetOpenPropertyValues(object target) { if (target == null) { throw new DataServiceException(500, "GetOpenPropertyValues called on null target"); } DSP.ResourceType resourceType = null; RowComplexType complexType = target as RowComplexType; if (complexType == null) { throw new DataServiceException(500, "GetOpenPropertyValues: Target is not of type RowComplexType"); } resourceType = this.Types.Where(r => r.FullName == complexType.TypeName).SingleOrDefault(); if (resourceType == null) { throw new DataServiceException(500, "Could not find resource type '" + complexType.TypeName + "'"); } // if its a closed type, this method should not be called if (!resourceType.IsOpenType) { throw new DataServiceException(500, "GetOpenPropertyValues called on non open type '" + resourceType.FullName + "'"); } return(complexType.Properties.Where(pair => !resourceType.Properties.Any(p => p.Name == pair.Key))); } // GetOpenPropertyValues
} // GetQueryRootForResourceSet public DSP.ResourceType GetResourceType(object instance) { if (instance == null) { return(null); } DSP.ResourceType resourceType = null; RowComplexType complexType = instance as RowComplexType; if (complexType != null) { string typeName = complexType.TypeName; resourceType = this.Types.FirstOrDefault(r => r.FullName == typeName); } return(resourceType); } // GetResourceType
} // GetPropertyValue public object GetOpenPropertyValue(object target, string propertyName) { if (target == null) { throw new DataServiceException(500, "GetOpenPropertyValue called on null target"); } DSP.ResourceType resourceType = null; RowComplexType complexType = target as RowComplexType; if (complexType == null) { throw new DataServiceException(500, "GetOpenPropertyValue: Target is not of type RowComplexType"); } resourceType = this.Types.Where(r => r.FullName == complexType.TypeName).SingleOrDefault(); if (resourceType == null) { throw new DataServiceException(500, "Could not find resource type '" + complexType.TypeName + "'"); } // if its a closed type, this method should not be called if (!resourceType.IsOpenType) { throw new DataServiceException(500, "GetOpenPropertyValue called on non open type '" + resourceType.FullName + "'"); } // if its a declared property, this method should not be called if (resourceType.Properties.Any(p => p.Name == propertyName)) { throw new DataServiceException(500, "GetOpenPropertyValue called for declared property '" + propertyName + "'"); } object value; if (complexType.Properties.TryGetValue(propertyName, out value)) { return(value); } return(null); } // GetOpenPropertyValue
} // GetResource public object GetValue(object targetResource, string propertyName) { // Check for strongly typed properties PropertyInfo property = targetResource.GetType().GetProperty(propertyName); if (property != null) { return(property.GetValue(targetResource, null)); } RowComplexType complexType = (RowComplexType)targetResource; object propertyValue; if (complexType.Properties.TryGetValue(propertyName, out propertyValue)) { return(propertyValue); } else { return(null); } } // GetValue
public void SetValue(object targetResource, string propertyName, object propertyValue) { RowComplexType targetComplex = targetResource as RowComplexType; targetComplex.Properties[propertyName] = propertyValue; } // SetValue