public void ComplexType_reference_extensions() { IEdmModel edmModel = this.GetEdmModel(); IEdmComplexType derivedComplexType = edmModel.SchemaElements.OfType <IEdmComplexType>().First(c => c.BaseType != null); IEdmComplexType baseComplexType = derivedComplexType.BaseComplexType(); Assert.IsNotNull(baseComplexType, "Base complex type should not be null!"); IEdmComplexTypeReference derivedComplexTypeRef = (IEdmComplexTypeReference)derivedComplexType.ToTypeReference(); Assert.AreEqual(baseComplexType, derivedComplexTypeRef.BaseComplexType(), "ComplexTypeReference.BaseComplexType()"); Assert.AreEqual(baseComplexType, derivedComplexTypeRef.BaseType(), "ComplexTypeReference.BaseType()"); Assert.AreEqual(derivedComplexType.IsAbstract, derivedComplexTypeRef.IsAbstract(), "StructuralTypeReference.IsAbstract()"); Assert.AreEqual(derivedComplexType.IsOpen, derivedComplexTypeRef.IsOpen(), "StructuralTypeReference.IsOpen()"); Assert.AreEqual(derivedComplexType.DeclaredStructuralProperties().Count(), derivedComplexTypeRef.DeclaredStructuralProperties().Count(), "StructuralTypeReference.DeclaredStructuralProperties()"); Assert.AreEqual(derivedComplexType.StructuralProperties().Count(), derivedComplexTypeRef.StructuralProperties().Count(), "StructuralTypeReference.StructuralProperties()"); }
internal static object CreateResource(IEdmComplexTypeReference complexType, ODataDeserializerContext readContext) { if (complexType == null) { throw Error.ArgumentNull("complexType"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } IEdmModel model = readContext.Model; if (model == null) { throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext); } if (readContext.IsUntyped) { return new EdmComplexObject(complexType); } else { Type clrType = EdmLibHelpers.GetClrType(complexType, readContext.Model); if (clrType == null) { throw Error.InvalidOperation(SRResources.MappingDoesNotContainEntityType, complexType.FullName()); } if (readContext.IsDeltaOfT) { Type elementType = readContext.ResourceType.GetGenericArguments()[0]; if (elementType != clrType) { // Just create the object for inline complex type return Activator.CreateInstance(clrType); } IEnumerable<string> structuralProperties = complexType.StructuralProperties() .Select(edmProperty => EdmLibHelpers.GetClrPropertyName(edmProperty, model)); if (complexType.IsOpen()) { PropertyInfo dynamicDictionaryPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary( complexType.StructuredDefinition(), model); return Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties, dynamicDictionaryPropertyInfo); } else { return Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties); } } else { return Activator.CreateInstance(clrType); } } }
internal static object CreateResource(IEdmComplexTypeReference complexType, ODataDeserializerContext readContext) { if (complexType == null) { throw Error.ArgumentNull("complexType"); } if (readContext == null) { throw Error.ArgumentNull("readContext"); } IEdmModel model = readContext.Model; if (model == null) { throw Error.Argument("readContext", SRResources.ModelMissingFromReadContext); } if (readContext.IsUntyped) { return(new EdmComplexObject(complexType)); } else { Type clrType = EdmLibHelpers.GetClrType(complexType, readContext.Model); if (clrType == null) { throw Error.InvalidOperation(SRResources.MappingDoesNotContainEntityType, complexType.FullName()); } if (readContext.IsDeltaOfT) { Type elementType = readContext.ResourceType.GetGenericArguments()[0]; if (elementType != clrType) { // Just create the object for inline complex type return(Activator.CreateInstance(clrType)); } IEnumerable <string> structuralProperties = complexType.StructuralProperties() .Select(edmProperty => EdmLibHelpers.GetClrPropertyName(edmProperty, model)); if (complexType.IsOpen()) { PropertyInfo dynamicDictionaryPropertyInfo = EdmLibHelpers.GetDynamicPropertyDictionary( complexType.StructuredDefinition(), model); return(Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties, dynamicDictionaryPropertyInfo)); } else { return(Activator.CreateInstance(readContext.ResourceType, clrType, structuralProperties)); } } else { return(Activator.CreateInstance(clrType)); } } }