当前位置: 首页>>代码示例>>C#>>正文


C# Template.MapProperties方法代码示例

本文整理汇总了C#中Template.MapProperties方法的典型用法代码示例。如果您正苦于以下问题:C# Template.MapProperties方法的具体用法?C# Template.MapProperties怎么用?C# Template.MapProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Template的用法示例。


在下文中一共展示了Template.MapProperties方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitPropertyMappings

        private void InitPropertyMappings(Template template, MyBusinessObject modelObj)
        {
            Debug.Assert(template != null && template.Shape != null && modelObj != null);

            // Assign model object to template shape
            template.Shape.ModelObject = modelObj;

            // Delete and clear all property mappings
            // (not really necessary in this case)
            project.Repository.Delete(template.GetPropertyMappings());
            template.UnmapAllProperties();

            // Prepare property mappings (One mapping per property!):
            //
            // Float to Style
            // Change color depending on the integer property
            StyleModelMapping lineStyleMapping = new StyleModelMapping(1, MyBusinessObject.FloatPropertyId, StyleModelMapping.MappingType.FloatStyle);
            lineStyleMapping.AddValueRange(float.MinValue, project.Design.LineStyles.None);
            lineStyleMapping.AddValueRange(16.66f, project.Design.LineStyles.Dotted);
            lineStyleMapping.AddValueRange(33.33f, project.Design.LineStyles.Special2);
            lineStyleMapping.AddValueRange(50.00f, project.Design.LineStyles.Special1);
            lineStyleMapping.AddValueRange(66.66f, project.Design.LineStyles.Dashed);
            lineStyleMapping.AddValueRange(83.33f, project.Design.LineStyles.Normal);
            template.MapProperties(lineStyleMapping);
            //
            // Integer to Style
            // Change outline thickness depending on the boolean property
            StyleModelMapping fillStyleMapping = new StyleModelMapping(3, MyBusinessObject.BooleanPropertyId, StyleModelMapping.MappingType.IntegerStyle);
            fillStyleMapping.AddValueRange(0, project.Design.FillStyles.Green);
            fillStyleMapping.AddValueRange(1, project.Design.FillStyles.Red);
            template.MapProperties(fillStyleMapping);
            //
            // Integer to Integer
            // Change shape's angle depending on the integer property
            // Note: Value is modified by a slope factor of 10 because angle is specified in tenths of degrees.
            NumericModelMapping angleMapping = new NumericModelMapping(2, MyBusinessObject.IntegerPropertyId, NumericModelMapping.MappingType.IntegerInteger, 0, 10);
            template.MapProperties(angleMapping);

            // Add model object and update template
            project.Repository.Insert(modelObj);
            project.Repository.Update(template);
        }
开发者ID:LudovicT,项目名称:NShape,代码行数:42,代码来源:Form1.cs

示例2: ModelMappingTest

		public void ModelMappingTest() {
			Project project = new Project();
			project.Repository = new CachedRepository();
			((CachedRepository)project.Repository).Store = RepositoryHelper.CreateXmlStore();
			project.Name = "ModelMappingTest";
			project.Repository.Erase();
			project.Create();
			project.AddLibrary(typeof(Dataweb.NShape.GeneralShapes.Circle).Assembly);

			// Create test data
			object[] floatTestData = CreateFloatTestData();
			object[] intTestData = CreateIntTestData();
			object[] stringTestData = CreateStringTestData();

			// Create model object and retrieve all properties
			GenericModelObject templateModelObject = (GenericModelObject)project.ModelObjectTypes["GenericModelObject"].CreateInstance();
			// Define property lists
			List<PropertyInfo> modelProperties = new List<PropertyInfo>();
			List<PropertyInfo> shapeProperties = new List<PropertyInfo>();
			GetPropertyInfos(templateModelObject.GetType(), modelProperties);
			
			// Test a shape of each shapeType
			foreach (ShapeType shapeType in project.ShapeTypes) {
				using (Shape templateShape = shapeType.CreateInstance()) {
					if (templateShape is IShapeGroup) continue;
					templateShape.ModelObject = templateModelObject;

					// Get mappable shape and model properties
					GetPropertyInfos(templateShape.GetType(), shapeProperties);

					Template template = new Template(shapeType.Name, templateShape);
					foreach (PropertyInfo modelProperty in modelProperties) {
						foreach (PropertyInfo shapeProperty in shapeProperties) {
							IModelMapping modelMapping = CreateModelMapping(shapeProperty, modelProperty);
							if (modelMapping == null) continue;
							//
							// Assign suitable test data
							object[] testValues = null;
							if (modelMapping.CanSetFloat) testValues = floatTestData;
							else if (modelMapping.CanSetInteger) testValues = intTestData;
							else if (modelMapping.CanSetString) testValues = stringTestData;
							//
							// Fill Model mappings and set expected results
							object[] testResults = null;
							if (modelMapping is NumericModelMapping)
								testResults = GetNumericMappingResults((NumericModelMapping)modelMapping, testValues);
							else if (modelMapping is FormatModelMapping)
								testResults = GetFormatMappingResults((FormatModelMapping)modelMapping, testValues);
							else if (modelMapping is StyleModelMapping)
								testResults = GetStyleMappingResults((StyleModelMapping)modelMapping, shapeProperty.PropertyType, testValues, project);
							//
							// Map properties
							template.UnmapAllProperties();
							template.MapProperties(modelMapping);

							// Test property mapping
							using (Shape testShape = template.CreateShape()) {
								IModelObject testModel = testShape.ModelObject;

								// Assign all test values to the model object and check the mapped shape property value.
								object templateShapePropValue = shapeProperty.GetValue(testShape, null);
								int cnt = testValues.Length;
								for (int i = 0; i < cnt; ++i) {
									try {
										// Assign the current test value to the model object's property value.
										// The shape's property has to be changed by the ModelMapping.
										object shapeValue = shapeProperty.GetValue(testShape, null);
										modelProperty.SetValue(testModel, testValues[i], null);
										object resultValue = shapeProperty.GetValue(testShape, null);
										object expectedValue = testResults[i] ?? templateShapePropValue;
										// 
										if (testShape is IPlanarShape && modelMapping.ShapePropertyId == 2) {
											// Angle property: All values are vonverted to positive angles < 360° (0 <= value <= 3600)
											if (expectedValue is int)
												expectedValue = ((3600 + (int)expectedValue) % 3600);
											else if (expectedValue is float)
												expectedValue = ((3600 + (float)expectedValue) % 3600);
										}
										//
										// Check mapping result
										bool areEqual = false;
										if (IsIntegerType(resultValue.GetType()) && IsIntegerType(expectedValue.GetType()))
											areEqual = object.Equals(Convert.ToInt64(resultValue), Convert.ToInt64(expectedValue));
										else if (IsFloatType(resultValue.GetType()) && IsFloatType(expectedValue.GetType()))
											areEqual = object.Equals(Convert.ToDouble(resultValue), Convert.ToDouble(expectedValue));
										else
											areEqual = object.Equals(resultValue, expectedValue);
										// Error reporting
										if (!areEqual) {
											if (object.Equals(shapeValue, resultValue))
												Assert.Fail(
													"Assigning '{0}' to {1} had no effect on {2}'s property '{3}': Property value '{4}' did not change.",
													testValues[i],
													testModel.Type.Name,
													testShape.Type.Name,
													shapeProperty.Name,
													shapeValue);
											else
												Assert.Fail(
													"Assigning '{0}' to {1} had not the expected effect on {2}'s property '{3}': Property value '{4}' changed to '{5}' instead of '{6}'.",
//.........这里部分代码省略.........
开发者ID:jestonitiro,项目名称:nshape,代码行数:101,代码来源:DiagramBaseTest.cs


注:本文中的Template.MapProperties方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。