private static List<ResourceInstanceProperty> CloneObjectToResourceInstanceProperties(IEnumerable<ResourceProperty> properties, object o) { List<ResourceInstanceProperty> instanceProperties = new List<ResourceInstanceProperty>(); foreach (ResourceProperty resProperty in properties) { if (resProperty.IsNavigation) continue; object propertyObject = o.GetType().InvokeMember(resProperty.Name, System.Reflection.BindingFlags.GetProperty, null, o, new object[] { }); ResourceInstanceProperty resourceInstanceProperty = null; if (resProperty.Type is ComplexType) { ComplexResourceInstance complexInstance = CloneObjectToComplexResourceInstance(resProperty.Type as ComplexType, propertyObject); resourceInstanceProperty = new ResourceInstanceComplexProperty(resProperty.Type.Name, resProperty.Name, complexInstance); } else { resourceInstanceProperty = new ResourceInstanceSimpleProperty(resProperty.Name, new NodeValue(propertyObject, resProperty.Type)); } instanceProperties.Add(resourceInstanceProperty); } return instanceProperties; }
public static ComplexResourceInstance CreateComplexResourceInstance(ComplexType type) { List<ResourceInstanceProperty> instanceProperties = new List<ResourceInstanceProperty>(); foreach (ResourceProperty childProperty in type.Properties) { ResourceInstanceProperty resourceInstanceProperty = null; if (childProperty.IsComplexType) { resourceInstanceProperty = new ResourceInstanceComplexProperty(childProperty.Type.Name, childProperty.Name, CreateComplexResourceInstance((ComplexType)childProperty.Type)); } else { NodeValue nodeValue = Resource.CreateValue(childProperty); resourceInstanceProperty = new ResourceInstanceSimpleProperty(childProperty.Name, nodeValue); } instanceProperties.Add(resourceInstanceProperty); } ComplexResourceInstance complexInstance = new ComplexResourceInstance(type.Name, instanceProperties.ToArray()); return complexInstance; }
private XmlElement CreateComplexPropertyNode(ResourceInstanceComplexProperty complexPropertyNode) { XmlElement propertyNodeElement = CreateDataWebElement(complexPropertyNode.Name); if (complexPropertyNode.IncludeTypeMetadataHint) { XmlAttribute typeAttribute = CreateDataMetadataAttribute("type"); typeAttribute.Value = this.Workspace.ContextNamespace + "." + complexPropertyNode.TypeName; propertyNodeElement.Attributes.Append(typeAttribute); } if (complexPropertyNode.ComplexResourceInstance == null) { XmlAttribute isnullAttribute = CreateDataWebMetadataAttribute("null"); isnullAttribute.Value = "true"; propertyNodeElement.Attributes.Append(isnullAttribute); } return propertyNodeElement; }
public void VisitResourceInstanceComplexProperty(ResourceInstanceComplexProperty complexPropertyNode, XmlElement parentNode) { XmlElement propertyNodeElement = CreateComplexPropertyNode(complexPropertyNode); if (complexPropertyNode.ComplexResourceInstance != null) { foreach (ResourceInstanceSimpleProperty simpleProperty in complexPropertyNode.ComplexResourceInstance.Properties.OfType<ResourceInstanceSimpleProperty>()) { VisitResourceInstanceSimpleProperty(simpleProperty, propertyNodeElement); } foreach (ResourceInstanceComplexProperty complexProperty in complexPropertyNode.ComplexResourceInstance.Properties.OfType<ResourceInstanceComplexProperty>()) { VisitResourceInstanceComplexProperty(complexProperty, propertyNodeElement); } } if (parentNode == null) { AddNamespacesToTopElement(propertyNodeElement); document.AppendChild(propertyNodeElement); } else { parentNode.AppendChild(propertyNodeElement); } }
private void ModifyProperty(ResourceInstanceComplexProperty property, RowComplexType newResource) { ModifyProperties(property.ComplexResourceInstance, (RowComplexType)newResource.Properties[property.Name], false); }