/// <summary> /// Emit the attributes for the new navigation property /// </summary> /// <param name="generator">The ClientApiGenerator instance</param> /// <param name="targetRelationshipEnd">The relationship end that is being targeted</param> /// <param name="propertyDecl">The property declaration to attach the attribute to.</param> /// <param name="additionalAttributes">Additional attributes</param> public void EmitNavigationPropertyAttributes(ClientApiGenerator generator, RelationshipEndMember targetRelationshipEnd, CodeMemberProperty propertyDecl, List <CodeAttributeDeclaration> additionalAttributes) { CodeAttributeDeclaration attribute = EmitSimpleAttribute(FQAdoFrameworkDataClassesName("EdmRelationshipNavigationPropertyAttribute"), targetRelationshipEnd.DeclaringType.NamespaceName, targetRelationshipEnd.DeclaringType.Name, targetRelationshipEnd.Name); propertyDecl.CustomAttributes.Add(attribute); EmitGeneratedCodeAttribute(propertyDecl); if (additionalAttributes != null && additionalAttributes.Count > 0) { try { propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray()); } catch (ArgumentNullException e) { generator.AddError(Strings.InvalidAttributeSuppliedForProperty(propertyDecl.Name), ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty, EdmSchemaErrorSeverity.Error, e); } } }
private void EmitKnownTypeAttributes(EdmType baseType, ClientApiGenerator generator, CodeTypeDeclaration typeDecl) { foreach (EdmType edmType in generator.GetDirectSubTypes(baseType)) { Debug.Assert(edmType.BaseType == baseType, "The types must be directly derived from basetype"); CodeTypeReference subTypeRef; if (generator.Language == LanguageOption.GenerateCSharpCode) { bool useGlobalPrefix = true; subTypeRef = generator.GetFullyQualifiedTypeReference(edmType, useGlobalPrefix); } else { Debug.Assert(generator.Language == LanguageOption.GenerateVBCode, "Did you add a new language?"); subTypeRef = generator.GetLeastPossibleQualifiedTypeReference(edmType); } CodeAttributeDeclaration attribute = EmitSimpleAttribute("System.Runtime.Serialization.KnownTypeAttribute", new CodeTypeOfExpression(subTypeRef)); typeDecl.CustomAttributes.Add(attribute); } }
private IList <EdmSchemaError> GenerateCode(XmlReader sourceReader, LazyTextWriterCreator target, string namespacePrefix) { List <XmlReader> readers = CreateReaders(sourceReader); List <EdmSchemaError> errors = new List <EdmSchemaError>(); EdmItemCollection itemCollection = new EdmItemCollection(readers); #if QFE_ENV _version = _versionExplicitlySet ? _version : GetDataServiceCodeVersionFromEnvironment(); _useDataServiceCollection = _useDataServiceCollectionExplicitlySet ? _useDataServiceCollection : GetUseDataServiceCollectionFromEnvironment(); #endif if (_useDataServiceCollection && _version == DataServiceCodeVersion.V1) { throw new InvalidOperationException(Strings.VersionV1RequiresUseDataServiceCollectionFalse); } // generate code using (ClientApiGenerator generator = new ClientApiGenerator(null, itemCollection, this, errors, namespacePrefix)) { generator.GenerateCode(target); } return(errors); }
/// <summary> /// /// </summary> /// <param name="generator"></param> public NamespaceEmitter(ClientApiGenerator generator, string namespacePrefix, string targetFilePath) : base(generator) { _targetFilePath = targetFilePath != null ? targetFilePath : string.Empty; _namespacePrefix = namespacePrefix; }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="schemaType"></param> protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item) : base(generator, item) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="navigationProperty"></param> public NavigationPropertyEmitter(ClientApiGenerator generator, NavigationProperty navigationProperty, bool declaringTypeUsesStandardBaseType) : base(generator, navigationProperty, declaringTypeUsesStandardBaseType) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="nestedType"></param> public ComplexTypeEmitter(ClientApiGenerator generator, ComplexType complexType) : base(generator, complexType) { }
protected PropertyEmitterBase(ClientApiGenerator generator, MetadataItem item, bool declaringTypeUsesStandardBaseType) : base(generator, item) { Debug.Assert(item != null, "item is null"); _declaringTypeUsesStandardBaseType = declaringTypeUsesStandardBaseType; }
protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item) :base(generator) { Debug.Assert(item != null, "item is null"); _item = item; }
public PropertyTypeReferences(TypeReference typeReference, ComplexType complexType, ClientApiGenerator generator) : this(typeReference, complexType, CollectionKind.None, generator) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="property"></param> public PropertyEmitter(ClientApiGenerator generator, EdmProperty property, bool declaringTypeUsesStandardBaseType) : base(generator, property, declaringTypeUsesStandardBaseType) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="itemType"></param> public EntityTypeEmitter(ClientApiGenerator generator, EntityType entity) : base(generator, entity) { }
public AssociationTypeEmitter(ClientApiGenerator generator, AssociationType associationType) : base(generator, associationType) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="structuredType"></param> protected StructuredTypeEmitter(ClientApiGenerator generator, StructuralType structuralType) : base(generator, structuralType) { }
protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item) : base(generator) { Debug.Assert(item != null, "item is null"); _item = item; }
/// <summary> /// /// </summary> /// <param name="generator"></param> protected Emitter(ClientApiGenerator generator) { Generator = generator; }
public PropertyTypeReferences(TypeReference typeReference, ComplexType complexType, CollectionKind collectionKind, ClientApiGenerator generator) { CodeTypeReference baseType = generator.GetLeastPossibleQualifiedTypeReference(complexType); baseType = GetCollectionTypeReference(typeReference, baseType, collectionKind); _nonNullable = baseType; _nullable = baseType; }
private void GenerateCodeCommon(MetadataArtifactLoader sourceLoader, List <MetadataArtifactLoader> loaders, LazyTextWriterCreator target, string sourceEdmSchemaFilePath, string targetFilePath, bool closeReaders, List <EdmSchemaError> errors) { MetadataArtifactLoaderComposite composite = new MetadataArtifactLoaderComposite(loaders); // create the schema manager from the xml readers Dictionary <MetadataArtifactLoader, XmlReader> readerSourceMap = new Dictionary <MetadataArtifactLoader, XmlReader>(); IList <Schema> schemas; List <XmlReader> readers = composite.GetReaders(readerSourceMap); try { IList <EdmSchemaError> schemaManagerErrors = SchemaManager.ParseAndValidate(readers, composite.GetPaths(), SchemaDataModelOption.EntityDataModel, EdmProviderManifest.Instance, out schemas); errors.AddRange(schemaManagerErrors); } finally { if (closeReaders) { MetadataUtil.DisposeXmlReaders(readers); } } ThrowOnAnyNonWarningErrors(errors); Debug.Assert(readerSourceMap.ContainsKey(sourceLoader), "the source loader didn't produce any of the xml readers..."); XmlReader sourceReader = readerSourceMap[sourceLoader]; // use the index of the "source" xml reader as the index of the "source" schema Debug.Assert(readers.Contains(sourceReader), "the source reader is not in the list of readers"); int index = readers.IndexOf(sourceReader); Debug.Assert(index >= 0, "couldn't find the source reader in the list of readers"); Debug.Assert(readers.Count == schemas.Count, "We have a different number of readers than schemas"); Schema sourceSchema = schemas[index]; Debug.Assert(sourceSchema != null, "sourceSchema is null"); // create the EdmItemCollection from the schemas EdmItemCollection itemCollection = new EdmItemCollection(schemas); if (EntityFrameworkVersionsUtil.ConvertToVersion(itemCollection.EdmVersion) >= EntityFrameworkVersions.Version2) { throw EDesignUtil.InvalidOperation(Strings.TargetEntityFrameworkVersionToNewForEntityClassGenerator); } // generate code ClientApiGenerator generator = new ClientApiGenerator(sourceSchema, itemCollection, this, errors); generator.GenerateCode(target, targetFilePath); }
/// <summary> /// /// </summary> /// <param name="generator"></param> /// <param name="entityContainer"></param> public EntityContainerEmitter(ClientApiGenerator generator, EntityContainer entityContainer) : base(generator, entityContainer) { }
/// <summary> /// /// </summary> /// <param name="generator"></param> public NamespaceEmitter(ClientApiGenerator generator, string codeNamespace, string targetFilePath) : base(generator) { _codeNamespace = codeNamespace; _targetFilePath = targetFilePath != null ? targetFilePath : string.Empty; }
/// <summary> /// Emit the attributes for the new navigation property /// </summary> /// <param name="generator">The ClientApiGenerator instance</param> /// <param name="targetRelationshipEnd">The relationship end that is being targeted</param> /// <param name="propertyDecl">The property declaration to attach the attribute to.</param> /// <param name="additionalAttributes">Additional attributes</param> public void EmitNavigationPropertyAttributes(ClientApiGenerator generator, RelationshipEndMember targetRelationshipEnd, CodeMemberProperty propertyDecl, List<CodeAttributeDeclaration> additionalAttributes) { CodeAttributeDeclaration attribute = EmitSimpleAttribute(FQAdoFrameworkDataClassesName("EdmRelationshipNavigationPropertyAttribute"), targetRelationshipEnd.DeclaringType.NamespaceName, targetRelationshipEnd.DeclaringType.Name, targetRelationshipEnd.Name); propertyDecl.CustomAttributes.Add(attribute); EmitGeneratedCodeAttribute(propertyDecl); if (additionalAttributes != null && additionalAttributes.Count > 0) { try { propertyDecl.CustomAttributes.AddRange(additionalAttributes.ToArray()); } catch (ArgumentNullException e) { generator.AddError(Strings.InvalidAttributeSuppliedForProperty(propertyDecl.Name), ModelBuilderErrorCode.InvalidAttributeSuppliedForProperty, EdmSchemaErrorSeverity.Error, e); } } }