private void CreatePropertyValue(DocumentCompositeNode compositeNode, SampleProperty sampleProperty) { this.valueBuilder.InitCollectionDepth((DocumentNode)compositeNode); DocumentNode documentNode = this.valueBuilder.GeneratePropertyValue(sampleProperty); compositeNode.Properties[(IPropertyId)sampleProperty] = documentNode; }
private void RemoveNodesByProperty(DocumentCompositeNode compositeNode, SampleProperty deletedProperty) { if (compositeNode == null) { return; } if (compositeNode.Type == deletedProperty.DeclaringSampleType) { if (this.changeCount == 0 && compositeNode.Properties[(IPropertyId)deletedProperty] != null) { ++this.changeCount; } compositeNode.ClearValue((IPropertyId)deletedProperty); } for (int index = compositeNode.Properties.Count - 1; index >= 0; --index) { this.RemoveNodesByProperty(compositeNode.Properties[index] as DocumentCompositeNode, deletedProperty); } if (!compositeNode.SupportsChildren) { return; } for (int index = 0; index < compositeNode.Children.Count; ++index) { this.RemoveNodesByProperty(compositeNode.Children[index] as DocumentCompositeNode, deletedProperty); } }
private void UpdatePropertyValues(DocumentCompositeNode compositeNode, SamplePropertyTypeOrFormatChanged change) { if (compositeNode == null) { return; } SampleProperty sampleProperty = change.SampleProperty; if (compositeNode.Type == sampleProperty.DeclaringSampleType) { if (change.OldType == SampleBasicType.Image) { DocumentPrimitiveNode documentPrimitiveNode = compositeNode.Properties[(IPropertyId)sampleProperty] as DocumentPrimitiveNode; if (documentPrimitiveNode != null) { string relativePath = documentPrimitiveNode.GetValue <string>(); sampleProperty.DeclaringDataSet.UnuseAssetFile(relativePath); } } this.CreatePropertyValue(compositeNode, sampleProperty); ++this.changeCount; } for (int index = 0; index < compositeNode.Properties.Count; ++index) { this.UpdatePropertyValues(compositeNode.Properties[index] as DocumentCompositeNode, change); } if (!compositeNode.SupportsChildren) { return; } for (int index = 0; index < compositeNode.Children.Count; ++index) { this.UpdatePropertyValues(compositeNode.Children[index] as DocumentCompositeNode, change); } }
private Type GenerateProperty(TypeBuilder typeBuilder, SampleProperty sampleProperty, ILGenerator ilDefaultConstructor) { Type beginDesignTimeType = this.GetOrBeginDesignTimeType(sampleProperty.PropertySampleType); FieldBuilder fieldBuilder = typeBuilder.DefineField("_" + sampleProperty.Name, beginDesignTimeType, FieldAttributes.Private); PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(sampleProperty.Name, PropertyAttributes.HasDefault, fieldBuilder.FieldType, (Type[])null); if (sampleProperty.IsBasicType || sampleProperty.IsCollection) { this.InitializeField(fieldBuilder, ilDefaultConstructor, sampleProperty); } MethodAttributes attributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName; MethodBuilder mdBuilder1 = typeBuilder.DefineMethod("get_" + sampleProperty.Name, attributes, fieldBuilder.FieldType, Type.EmptyTypes); ILGenerator ilGenerator1 = mdBuilder1.GetILGenerator(); ilGenerator1.Emit(OpCodes.Ldarg_0); ilGenerator1.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder); ilGenerator1.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(mdBuilder1); if (!sampleProperty.IsCollection) { MethodBuilder mdBuilder2 = typeBuilder.DefineMethod("set_" + sampleProperty.Name, attributes, (Type)null, new Type[1] { fieldBuilder.FieldType }); ILGenerator ilGenerator2 = mdBuilder2.GetILGenerator(); ilGenerator2.DeclareLocal(typeof(bool)); MethodInfo method1 = typeof(object).GetMethod("Equals", BindingFlags.Static | BindingFlags.Public); if (beginDesignTimeType.IsValueType) { ilGenerator2.Emit(OpCodes.Ldarg_0); ilGenerator2.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder); ilGenerator2.Emit(OpCodes.Box, beginDesignTimeType); ilGenerator2.Emit(OpCodes.Ldarg_1); ilGenerator2.Emit(OpCodes.Box, beginDesignTimeType); } else { ilGenerator2.Emit(OpCodes.Ldarg_0); ilGenerator2.Emit(OpCodes.Ldfld, (FieldInfo)fieldBuilder); ilGenerator2.Emit(OpCodes.Ldarg_1); } ilGenerator2.Emit(OpCodes.Call, method1); Label label = ilGenerator2.DefineLabel(); ilGenerator2.Emit(OpCodes.Stloc_0); ilGenerator2.Emit(OpCodes.Ldloc_0); ilGenerator2.Emit(OpCodes.Brtrue_S, label); ilGenerator2.Emit(OpCodes.Ldarg_0); ilGenerator2.Emit(OpCodes.Ldarg_1); ilGenerator2.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); MethodInfo method2 = typeBuilder.BaseType.GetMethod("OnPropertyChanged"); ilGenerator2.Emit(OpCodes.Ldarg_0); ilGenerator2.Emit(OpCodes.Ldstr, sampleProperty.Name); ilGenerator2.Emit(OpCodes.Call, method2); ilGenerator2.MarkLabel(label); ilGenerator2.Emit(OpCodes.Ret); propertyBuilder.SetSetMethod(mdBuilder2); } return(beginDesignTimeType); }
private static void UpdatePropertyFormatInfo(XmlSchemaAnnotated schemaItem, SampleProperty sampleProperty) { XmlAttribute[] unhandledAttributes = schemaItem.UnhandledAttributes; string blendAttributeValue1 = SampleDataXsdParser.GetBlendAttributeValue(unhandledAttributes, SampleProperty.FormatAttribute); string blendAttributeValue2 = SampleDataXsdParser.GetBlendAttributeValue(unhandledAttributes, SampleProperty.FormatParametersAttribute); sampleProperty.ChangeFormat(blendAttributeValue1, blendAttributeValue2); }
public void DeleteProperty(SampleProperty sampleProperty) { for (int index = 0; index < this.sampleProperties.Count; ++index) { if (sampleProperty == this.sampleProperties[index]) { this.sampleProperties.RemoveAt(index); this.DeclaringDataSet.OnPropertyDeleted(sampleProperty); break; } } }
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 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 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 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)); }
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 SampleProperty AddProperty(string name, SampleType sampleType) { if (sampleType == this.DeclaringDataSet.RootType) { throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.RecursiveSampleDataRootTypeNotSupported, new object[1] { (object)this.DeclaringDataSet.RootType.Name })); } if (this.GetSampleProperty(name) != null) { throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, ExceptionStringTable.NameIsAlreadyInUse, new object[1] { (object)name })); } SampleProperty sampleProperty = new SampleProperty(name, sampleType, this); this.sampleProperties.Add(sampleProperty); this.DeclaringDataSet.OnPropertyAdded(sampleProperty); return(sampleProperty); }
private void AddPropertyValues(DocumentCompositeNode compositeNode, SampleProperty newProperty) { if (compositeNode == null) { return; } if (compositeNode.SupportsChildren) { for (int index = 0; index < compositeNode.Children.Count; ++index) { this.AddPropertyValues(compositeNode.Children[index] as DocumentCompositeNode, newProperty); } } for (int index = 0; index < compositeNode.Properties.Count; ++index) { this.AddPropertyValues(compositeNode.Properties[index] as DocumentCompositeNode, newProperty); } if (compositeNode.Type != newProperty.DeclaringSampleType) { return; } this.CreatePropertyValue(compositeNode, newProperty); ++this.changeCount; }
private void UpdatePropertyFormatInfo(XmlSchemaAnnotated schemaItem, SampleProperty sampleProperty) { XmlAttribute blendAttribute1 = this.CreateBlendAttribute(sampleProperty.Format, SampleProperty.FormatAttribute); XmlAttribute blendAttribute2 = this.CreateBlendAttribute(sampleProperty.FormatParameters, SampleProperty.FormatParametersAttribute); if (blendAttribute1 == null && blendAttribute2 == null) { return; } XmlAttribute[] xmlAttributeArray; if (blendAttribute1 == null) { xmlAttributeArray = new XmlAttribute[1] { blendAttribute2 } } ; else if (blendAttribute2 == null) { xmlAttributeArray = new XmlAttribute[1] { blendAttribute1 } } ; else { xmlAttributeArray = new XmlAttribute[2] { blendAttribute1, blendAttribute2 } }; schemaItem.UnhandledAttributes = xmlAttributeArray; }
private DocumentNode CreatePropertyValueInternal(DocumentCompositeNode documentNode, SampleProperty sampleProperty, string value) { DocumentNode documentNode1; if (sampleProperty.PropertySampleType.IsBasicType) { SampleBasicType sampleType = (SampleBasicType)sampleProperty.PropertySampleType; if (value == null) { value = this.valueGenerator.GetRandomValue(sampleType, sampleProperty.Format, sampleProperty.FormatParameters); } documentNode1 = (DocumentNode)this.CreateBasicNode(sampleType, value); } else { documentNode1 = (DocumentNode)this.CreateCompositeNode((SampleNonBasicType)sampleProperty.PropertySampleType); } documentNode.Properties[(IPropertyId)sampleProperty] = documentNode1; return(documentNode1); }
public string GetPropertyDefaultValue(SampleProperty sampleProperty) { SampleType propertySampleType = sampleProperty.PropertySampleType; return(!propertySampleType.IsBasicType ? this.NewInstanceFieldValue.Replace(SampleCodeGenerator.PropertyTypeTemplate, propertySampleType.Name) : this.BasicTypeValues[(SampleBasicType)propertySampleType]); }
public DocumentNode GeneratePropertyValue(SampleProperty sampleProperty) { return(!sampleProperty.IsBasicType ? this.GenerateNonBasicValue((SampleNonBasicType)sampleProperty.PropertySampleType) : this.GenerateBasicValue((SampleBasicType)sampleProperty.PropertySampleType, sampleProperty.Format, sampleProperty.FormatParameters)); }
public bool PushProperty(SampleProperty sampleProperty) { return(this.Push(sampleProperty.PropertySampleType, sampleProperty.Name)); }
private DocumentNode CreateCollectionItemForPropertyInternal(DocumentCompositeNode documentNode, SampleProperty collectionProperty, string value) { SampleCollectionType sampleCollectionType = collectionProperty.PropertySampleType as SampleCollectionType; if (sampleCollectionType == null) { return((DocumentNode)null); } DocumentCompositeNode collectionNode = documentNode.Properties[(IPropertyId)collectionProperty] as DocumentCompositeNode; if (collectionNode == null) { collectionNode = this.CreateCompositeNode((SampleNonBasicType)sampleCollectionType); documentNode.Properties[(IPropertyId)collectionProperty] = (DocumentNode)collectionNode; } return(this.CreateCollectionItemInternal(collectionNode, value)); }
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 CreateCollectionItemForProperty(DocumentCompositeNode documentNode, SampleProperty collectionProperty) { return(this.CreateCollectionItemForProperty(documentNode, collectionProperty, (string)null)); }
public DocumentNode CreatePropertyValue(DocumentCompositeNode documentNode, SampleProperty sampleProperty) { return(this.CreatePropertyValue(documentNode, sampleProperty, (string)null)); }
private void InitializeField(FieldBuilder fieldBuilder, ILGenerator ilConstructor, SampleProperty sampleProperty) { if (ilConstructor == null) { return; } if (!sampleProperty.IsBasicType) { SampleDataDesignTimeTypeGenerator.TypeBuildState typeBuildState = this.buildStates[(SampleNonBasicType)sampleProperty.PropertySampleType]; ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Newobj, (ConstructorInfo)typeBuildState.ConstructorBuilder); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else { SampleBasicType sampleBasicType = (SampleBasicType)sampleProperty.PropertySampleType; if (sampleBasicType == SampleBasicType.String) { FieldInfo field = typeof(string).GetField("Empty", BindingFlags.Static | BindingFlags.Public); ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldsfld, field); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Date) { PropertyInfo property = typeof(DateTime).GetProperty("Today", BindingFlags.Static | BindingFlags.Public); ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Call, property.GetGetMethod()); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Number) { ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldc_R8, 0.0); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else if (sampleBasicType == SampleBasicType.Boolean) { ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldc_I4, 0); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } else { if (sampleBasicType != SampleBasicType.Image) { return; } ilConstructor.Emit(OpCodes.Ldarg_0); ilConstructor.Emit(OpCodes.Ldnull); ilConstructor.Emit(OpCodes.Stfld, (FieldInfo)fieldBuilder); } } }
internal void TransferSortValue(SampleProperty fromProperty) { this.sortValue = fromProperty.sortValue; }