private IProperty VerifyPropertyName(string propertyName, IType type) { if (string.IsNullOrEmpty(propertyName)) { return((IProperty)null); } if (type == null) { return((IProperty)null); } IProperty property = (IProperty)type.GetMember(MemberType.Property, propertyName, MemberAccessTypes.Public); if (property == null) { SampleCompositeType compositeType = type as SampleCompositeType; if (compositeType == null) { return((IProperty)null); } SamplePropertyRenamed samplePropertyRenamed = this.renamedPropertyChanges.Find((Predicate <SamplePropertyRenamed>)(renameChange => { if (renameChange.SampleProperty.DeclaringSampleType != compositeType) { return(false); } return(renameChange.OldName == propertyName); })); if (samplePropertyRenamed == null) { return((IProperty)null); } property = (IProperty)samplePropertyRenamed.SampleProperty; } return(property); }
private void WriteCompositeType(SampleCompositeType compositeType, bool root) { string typeName1 = this.codeSnippets.GetTypeName((SampleType)compositeType); this.WriteSnippet(this.codeSnippets.CompositeTypeHeader, SampleCodeGenerator.CompositeTypeTemplate, typeName1); if (root) { this.textWriter.WriteLine(); this.WriteSnippet(this.codeSnippets.RootTypeConstructor, SampleCodeGenerator.CompositeTypeTemplate, typeName1, SampleCodeGenerator.AssemblyTemplate, this.dataSet.ProjectContext.ProjectAssembly.Name, SampleCodeGenerator.RootFolderTemplate, this.dataSet.Context.DataRootFolder, SampleCodeGenerator.SampleDataNameTemplate, this.dataSet.Name); } foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)compositeType.SampleProperties) { this.textWriter.WriteLine(); string typeName2 = this.codeSnippets.GetTypeName(sampleProperty.PropertySampleType); string propertyDefaultValue = this.codeSnippets.GetPropertyDefaultValue(sampleProperty); if (sampleProperty.IsCollection) { this.WriteSnippet(this.codeSnippets.GetProperty, SampleCodeGenerator.PropertyNameTemplate, sampleProperty.Name, SampleCodeGenerator.PropertyTypeTemplate, typeName2, SampleCodeGenerator.PropertyValueTemplate, propertyDefaultValue); } else { this.WriteSnippet(this.codeSnippets.GetSetProperty, SampleCodeGenerator.PropertyNameTemplate, sampleProperty.Name, SampleCodeGenerator.PropertyTypeTemplate, typeName2, SampleCodeGenerator.PropertyValueTemplate, propertyDefaultValue); } } this.WriteSnippet(this.codeSnippets.CompositeTypeFooter); }
public IProperty AddProperty(IType compositeType, string propertyName, IType propertyType) { SampleCompositeType sampleCompositeType = (SampleCompositeType)compositeType; SampleType sampleType = this.FromType(propertyType); return((IProperty)sampleCompositeType.AddProperty(propertyName, sampleType)); }
private SampleDataDesignTimeTypeGenerator.TypeBuildState BeginCompositeType(SampleCompositeType compositeType) { Type parent = compositeType == this.dataSet.RootType ? typeof(DesignTimeSampleRootType) : typeof(DesignTimeSampleCompositeType); TypeBuilder typeBuilder = RuntimeGeneratedTypesHelper.RuntimeGeneratedTypesAssembly.DefineType(this.designTimeClrNamespace + compositeType.Name, TypeAttributes.Public | TypeAttributes.Sealed, parent); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes); return(new SampleDataDesignTimeTypeGenerator.TypeBuildState(typeBuilder, constructorBuilder)); }
public SampleProperty(string name, SampleType propertySampleType, SampleCompositeType declaringSampleType) : base((IType)declaringSampleType, name, declaringSampleType.DeclaringDataSet.ResolveSampleType(propertySampleType), SampleProperty.seedSortValue++) { this.propertyName = name; this.PropertySampleType = propertySampleType; this.DeclaringSampleType = declaringSampleType; this.sortValue = SampleProperty.seedSortValue; this.DeclaringDataSet.ThrowIfRecursiveRootType(this.PropertySampleType); }
public SampleDataSet CreateDefaultNewSampleDataSource(DataSetContext dataSetContext, string dataSourceName, bool enableAtRuntime) { SampleDataSet dataSet = (SampleDataSet)null; bool flag = false; try { dataSet = this.CreateSampleDataSet(dataSetContext, dataSourceName, enableAtRuntime); if (dataSet != null) { using (dataSet.DisableChangeTracking()) { if (dataSetContext.DataSetType == DataSetType.SampleDataSet) { string uniqueTypeName1 = dataSet.GetUniqueTypeName("Item"); SampleCompositeType compositeType = dataSet.CreateCompositeType(uniqueTypeName1); string uniquePropertyName1 = compositeType.GetUniquePropertyName("Property1"); compositeType.AddProperty(uniquePropertyName1, (SampleType)SampleBasicType.String); string uniquePropertyName2 = compositeType.GetUniquePropertyName("Property2"); compositeType.AddProperty(uniquePropertyName2, (SampleType)SampleBasicType.Boolean); string uniqueTypeName2 = dataSet.GetUniqueTypeName("ItemCollection"); SampleCollectionType collectionType = dataSet.CreateCollectionType(uniqueTypeName2, (SampleType)compositeType); string uniquePropertyName3 = dataSet.RootType.GetUniquePropertyName("Collection"); dataSet.RootType.AddProperty(uniquePropertyName3, (SampleType)collectionType); dataSet.AutoGenerateValues(); } else { string uniquePropertyName = dataSet.RootType.GetUniquePropertyName("Property1"); SampleProperty sampleProperty = dataSet.RootType.AddProperty(uniquePropertyName, (SampleType)SampleBasicType.String); using (SampleDataValueBuilder valueBuilder = dataSet.CreateValueBuilder()) { DocumentCompositeNode rootNode = valueBuilder.RootNode; valueBuilder.RootNode.Properties[(IPropertyId)sampleProperty] = valueBuilder.CreatePropertyValue(rootNode, "Property1", StringTable.DefaultValueDataStore); } dataSet.Save(); } } flag = dataSet.IsSaved; } } finally { if (!flag && dataSet != null) { this.SafelyRemoveSampleDataAndRootFolder(dataSet, true); dataSet = (SampleDataSet)null; } } return(dataSet); }
public DocumentNode CreateCollectionItemForProperty(DocumentCompositeNode documentNode, SampleProperty collectionProperty, string value) { SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType; if (sampleCompositeType == null) { return((DocumentNode)null); } if (collectionProperty.DeclaringSampleType != sampleCompositeType) { return((DocumentNode)null); } return(this.CreateCollectionItemForPropertyInternal(documentNode, collectionProperty, value)); }
public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, SampleProperty sampleProperty, string value) { SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType; if (sampleCompositeType == null) { return((DocumentNode)null); } if (sampleProperty.DeclaringSampleType != sampleCompositeType) { return((DocumentNode)null); } return(this.CreatePropertyValueInternal(documentNode, sampleProperty, value)); }
private Type GenerateCompositeType(SampleCompositeType compositeType, SampleDataDesignTimeTypeGenerator.TypeBuildState buildState) { compositeType.DesignTimeType = buildState.TypeBuilder.UnderlyingSystemType; ILGenerator ilGenerator = buildState.ConstructorBuilder.GetILGenerator(); ConstructorInfo constructor = compositeType.DesignTimeType.BaseType.GetConstructor(Type.EmptyTypes); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Call, constructor); foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)compositeType.SampleProperties) { this.GenerateProperty(buildState.TypeBuilder, sampleProperty, ilGenerator); } ilGenerator.Emit(OpCodes.Ret); return(this.GenerateDesignTimeType(buildState.TypeBuilder)); }
private void PopulateSampleCompositeType(SampleCompositeType compositeType, XmlSchemaComplexType xmlComplexType) { XmlSchemaSequence xmlSchemaSequence = xmlComplexType.Particle as XmlSchemaSequence; if (xmlSchemaSequence == null && xmlComplexType.Particle != null) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidTypeFormat, new object[2] { (object)this.xsdFileName, (object)xmlComplexType.Name })); } if (xmlSchemaSequence != null) { foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaSequence.Items) { XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement; if (xmlSchemaElement != null) { SampleType sampleType = this.GetSampleType(xmlSchemaElement.SchemaTypeName); SampleProperty sampleProperty = compositeType.AddProperty(xmlSchemaElement.Name, sampleType); SampleDataXsdParser.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaElement, sampleProperty); if (sampleProperty.Name != xmlSchemaElement.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlSchemaElement.Name })); } } } } foreach (XmlSchemaAttribute xmlSchemaAttribute in xmlComplexType.Attributes) { SampleBasicType sampleBasicType = this.GetSampleType(xmlSchemaAttribute.SchemaTypeName) as SampleBasicType; SampleProperty sampleProperty = compositeType.AddProperty(xmlSchemaAttribute.Name, (SampleType)sampleBasicType); SampleDataXsdParser.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaAttribute, sampleProperty); if (sampleProperty.Name != xmlSchemaAttribute.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlSchemaAttribute.Name })); } } }
public DocumentNode CreateCollectionItemForProperty(DocumentCompositeNode documentNode, string collectionPropertyName, string value) { SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType; if (sampleCompositeType == null) { return((DocumentNode)null); } SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(collectionPropertyName); if (sampleProperty == null) { return((DocumentNode)null); } return(this.CreateCollectionItemForPropertyInternal(documentNode, sampleProperty, value)); }
public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, string propertyName, string value) { SampleCompositeType sampleCompositeType = documentNode.Type as SampleCompositeType; if (sampleCompositeType == null) { return((DocumentNode)null); } SampleProperty sampleProperty = sampleCompositeType.GetSampleProperty(propertyName); if (sampleProperty == null) { return((DocumentNode)null); } return(this.CreatePropertyValueInternal(documentNode, sampleProperty, value)); }
private void ResetDesignTimeType(SampleNonBasicType sampleType) { if (sampleType == null) { return; } sampleType.DesignTimeType = (Type)null; SampleCompositeType sampleCompositeType = sampleType as SampleCompositeType; if (sampleCompositeType == null) { return; } foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)sampleCompositeType.SampleProperties) { sampleProperty.ResetPropertyInfo(); } }
private XmlSchemaType CreateSchemaCompositeType(SampleCompositeType compositeType) { XmlSchemaComplexType schemaComplexType = new XmlSchemaComplexType(); schemaComplexType.Name = compositeType.Name; this.schemaTypes[schemaComplexType.Name] = (XmlSchemaType)schemaComplexType; XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence(); foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)compositeType.SampleProperties) { if (!sampleProperty.IsBasicType) { XmlSchemaElement xmlSchemaElement = new XmlSchemaElement(); xmlSchemaElement.Name = sampleProperty.Name; if (!sampleProperty.IsBasicType) { XmlSchemaType createSchemaType = this.GetOrCreateSchemaType(sampleProperty.PropertySampleType as SampleNonBasicType); xmlSchemaElement.SchemaTypeName = new XmlQualifiedName(createSchemaType.Name, this.TargetNamespace); } else { xmlSchemaElement.SchemaTypeName = this.GetBasicSchemaType(sampleProperty.PropertySampleType as SampleBasicType); } this.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaElement, sampleProperty); xmlSchemaSequence.Items.Add((XmlSchemaObject)xmlSchemaElement); } } if (xmlSchemaSequence.Items.Count > 0) { schemaComplexType.Particle = (XmlSchemaParticle)xmlSchemaSequence; } foreach (SampleProperty sampleProperty in (IEnumerable <SampleProperty>)compositeType.SampleProperties) { if (sampleProperty.IsBasicType) { XmlSchemaAttribute xmlSchemaAttribute = new XmlSchemaAttribute(); xmlSchemaAttribute.Name = sampleProperty.Name; xmlSchemaAttribute.SchemaTypeName = this.GetBasicSchemaType(sampleProperty.PropertySampleType as SampleBasicType); this.UpdatePropertyFormatInfo((XmlSchemaAnnotated)xmlSchemaAttribute, sampleProperty); schemaComplexType.Attributes.Add((XmlSchemaObject)xmlSchemaAttribute); } } return((XmlSchemaType)schemaComplexType); }
private SampleNonBasicType ReadType(XmlSchemaComplexType xmlComplexType) { XmlSchemaSequence xmlSchemaSequence = xmlComplexType.Particle as XmlSchemaSequence; if (xmlSchemaSequence == null && xmlComplexType.Particle != null) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidTypeFormat, new object[2] { (object)this.xsdFileName, (object)xmlComplexType.Name })); } if (xmlSchemaSequence != null && xmlSchemaSequence.Items.Count == 1) { XmlSchemaElement xmlSchemaElement = xmlSchemaSequence.Items[0] as XmlSchemaElement; if (xmlSchemaElement != null && xmlSchemaElement.MaxOccurs > new Decimal(1)) { SampleCollectionType collectionType = this.dataSet.CreateCollectionType(xmlComplexType.Name, (SampleType)SampleBasicType.String); SampleType sampleType = this.GetSampleType(xmlSchemaElement.SchemaTypeName); collectionType.ChangeItemType(sampleType); if (collectionType.Name != xmlComplexType.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlComplexType.Name })); } return((SampleNonBasicType)collectionType); } } SampleCompositeType compositeType = this.dataSet.CreateCompositeType(xmlComplexType.Name); if (compositeType.Name != xmlComplexType.Name) { throw new InvalidDataException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.InvalidNodeUsage, new object[2] { (object)this.xsdFileName, (object)xmlComplexType.Name })); } this.PopulateSampleCompositeType(compositeType, xmlComplexType); return((SampleNonBasicType)compositeType); }