public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(float).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { float left = (float)srcValue; float right = float.Parse(targetString); if (string.IsNullOrEmpty(mapping.Parameters["precision"])) { return left.Equals(right); //完全精度匹配(几乎不可能实现) } else { int precision = int.Parse(mapping.Parameters["precision"]); double delta = Math.Abs(left - right) * Math.Pow(10, precision); //通常两个数相差在delta范围内算相等 return delta < 1; } } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return ((string)srcValue) == targetString; } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
public BoundRow(int templateIndex, int selectedTemplateIndex, object data, PropertyMapping propertyMapping) : base(templateIndex, selectedTemplateIndex, 0) { base.FieldNames = propertyMapping; this.m_data = data; this.m_properties = propertyMapping.GetPropertyDescriptors(); }
public override void Visit(PropertyMapping propertyMapping) { var writer = serviceLocator.GetWriter<PropertyMapping>(); var xml = writer.Write(propertyMapping); document.ImportAndAppendChild(xml); }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(DateTime).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { DateTime left = (DateTime)srcValue; DateTime right = DateTime.Parse(targetString); return left.Equals(right); //完全精度匹配(几乎不可能实现) } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return ((string)srcValue) == targetString; } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
public void constructor_assigns_property_name_to_property() { var sut = new PropertyMapping<Ok>("Abra", (o, o1) => { }, o => o); sut.PropertyName.Should().Be("Abra"); sut.ColumnName.Should().Be("Abra"); }
public void set_Value_db_null() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); var sut = new PropertyMapping<Ok>("FirstName", (o, o1) => o.FirstName = (string)o1, ok => ok.FirstName); sut.SetColumnValue(actual, DBNull.Value); actual.FirstName.Should().Be(null); }
public void map_without_adapter() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); record["Id"].Returns("Hej"); var sut = new PropertyMapping<Ok>("Id", (o, o1) => o.Id = (string)o1, o => o.Id); sut.Map(record, actual); actual.Id.Should().Be("Hej"); }
protected virtual void DeserializeProperty <T>(PropertyMapping propertyMapping, T instance, TDeserializeState state) { if (IsDataNull(state)) { propertyMapping.SetValue(instance, null); } else { var underlyingValue = DeserializePrimitive(propertyMapping.Type, state); propertyMapping.SetValue(instance, underlyingValue); } }
public ActionResult CreateQuick([Bind(Include = "Id,ConcurrencyKey,PropertyName,DataName,EntityPropertyMappingID")] PropertyMapping propertymapping, string UrlReferrer, bool?IsAddPop, string AssociatedEntity) { //CheckBeforeSave(propertymapping); if (ModelState.IsValid) { var properties = propertymapping.PropertyName.Split(",".ToCharArray()); var jsonproperties = propertymapping.DataName.Split(",".ToCharArray()); if (properties.Count() == jsonproperties.Count()) { foreach (var item in db.PropertyMappings.Where(p => p.EntityPropertyMappingID == propertymapping.EntityPropertyMappingID).ToList()) { db.Entry(item).State = EntityState.Deleted; db.PropertyMappings.Remove(item); db.SaveChanges(); } for (var i = 0; i < properties.Count(); i++) { if (!string.IsNullOrEmpty(properties[i].Trim())) { var obj = new PropertyMapping(); obj.EntityPropertyMappingID = propertymapping.EntityPropertyMappingID; obj.PropertyName = properties[i].Trim(); obj.DataName = jsonproperties[i].Trim(); obj.SourceType = propertymapping.SourceType; obj.MethodType = propertymapping.MethodType; db.PropertyMappings.Add(obj); db.SaveChanges(); } } } return(Json("FROMPOPUP", "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } else { var errors = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors += error.ErrorMessage + ". "; } } return(Json(errors, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } LoadViewDataAfterOnCreate(propertymapping); if (!string.IsNullOrEmpty(AssociatedEntity)) { LoadViewDataForCount(propertymapping, AssociatedEntity); } return(View(propertymapping)); }
public void should_replace_dbnull_with_the_defined_replacement_value_when_mapping_column_value() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); record["Age"].Returns(DBNull.Value); var sut = new PropertyMapping<Ok>("Age", (o, o1) => o.Age= (int)o1, ok => ok.Age); sut.NullValue = 1; sut.Map(record, actual); actual.Age.Should().Be(1); }
public void convert_if_Required() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); var sut = new PropertyMapping <Ok>("Age", (o, o1) => o.Age = (int)o1, ok => ok.Age); sut.PropertyType = typeof(int); sut.SetProperty(actual, (decimal)1); actual.Age.Should().Be(1); }
public void use_column_name_and_not_property_name_in_the_record() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); record["Id2"].Returns("Hej"); var sut = new PropertyMapping<Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnName = "Id2"; sut.Map(record, actual); actual.Id.Should().Be("Hej"); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public AppSchema() { Names = new NameProvider("App", "Apps", "p"); GetAccess = Access.All; CreateAccess = Access.Internal; DeleteAccess = Access.Internal; IsAbstract = false; //// Name = new DomainProperty <string>("Name", "p_na"); Name.IsUnique = true; Name.IsElastic = true; NameKey = new DomainProperty <string>("NameKey", "p_nk"); NameKey.EnforceUnique = true; NameKey.ToLowerCase = true; NameKey.IsIndexed = true; Name.ExactIndexVia = NameKey; Secret = new DomainProperty <string>("Secret", "p_se"); OauthDomains = new DomainProperty <string>("OauthDomains", "p_od"); OauthDomains.IsNullable = true; //// FabName = new ApiProperty <string>("Name"); FabName.GetAccess = Access.All; FabName.IsUnique = true; FabName.LenMin = 3; FabName.LenMax = 64; FabName.ValidRegex = ApiProperty.ValidTitleRegex; FabName.TraversalHas = Matching.None; FabSecret = new ApiProperty <string>("Secret"); FabSecret.LenMin = 32; FabSecret.LenMax = 32; FabSecret.ValidRegex = ApiProperty.ValidCodeRegex; FabOauthDomains = new ApiProperty <string>("OauthDomains"); FabOauthDomains.IsNullable = true; FabOauthDomains.CustomValidation = true; //// FabNameMap = new PropertyMapping <string, string>(Name, FabName, CustomDir.ApiToDomain); FabNameMap.ApiToDomainNote = "Set Domain.NameKey = Api.Name.ToLower()"; FabSecretMap = new PropertyMapping <string, string>(Secret, FabSecret); FabOauthDomainsMap = new PropertyMapping <string, string>(OauthDomains, FabOauthDomains); }
public void set_Value_something() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); var sut = new PropertyMapping <Ok>("FirstName", (o, o1) => o.FirstName = (string)o1, ok => ok.FirstName); sut.PropertyType = typeof(string); sut.SetProperty(actual, "Hello"); actual.FirstName.Should().Be("Hello"); }
public void EitherIsAnyWithTwoParameters() { acceptance .Either(c => c.Expect(x => x.Name, Is.Set), c => c.Expect(x => x.Type, Is.Set)); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1"); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public InstanceSchema() { Names = new NameProvider("Instance", "Instances", "i"); GetAccess = Access.All; CreateAccess = Access.All; DeleteAccess = Access.CreatorUserAndApp; IsAbstract = false; CustomCreate = true; //// Name = new DomainProperty <string>("Name", "i_na"); Name.IsNullable = true; Name.IsElastic = true; Disamb = new DomainProperty <string>("Disamb", "i_di"); Disamb.IsNullable = true; Disamb.IsElastic = true; Note = new DomainProperty <string>("Note", "i_no"); Note.IsNullable = true; //// FabName = new ApiProperty <string>("Name"); FabName.SetOpenAccess(); FabName.IsNullable = true; FabName.LenMin = 1; FabName.LenMax = 128; FabName.ValidRegex = ApiProperty.ValidTitleRegex; FabName.TraversalHas = Matching.None; FabDisamb = new ApiProperty <string>("Disamb"); FabDisamb.SetOpenAccess(); FabDisamb.IsNullable = true; FabDisamb.LenMin = 1; FabDisamb.LenMax = 128; FabDisamb.ValidRegex = ApiProperty.ValidTitleRegex; FabDisamb.TraversalHas = Matching.None; FabNote = new ApiProperty <string>("Note"); FabNote.SetOpenAccess(); FabNote.IsNullable = true; FabNote.LenMin = 1; FabNote.LenMax = 256; FabNote.TraversalHas = Matching.None; //// FabNameMap = new PropertyMapping <string, string>(Name, FabName); FabDisambMap = new PropertyMapping <string, string>(Disamb, FabDisamb); FabNoteMap = new PropertyMapping <string, string>(Note, FabNote); }
public void ShouldUseInheritedOppositeCriteria() { acceptance .OppositeOf <AnotherConvention>(); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); propertyMapping.Set(x => x.Update, Layer.Defaults, true); acceptance.Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void skip_db_null_value() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); record["Id2"].Returns(DBNull.Value); var sut = new PropertyMapping<Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnName = "Id2"; sut.Map(record, actual); actual.Id.Should().BeNull(); }
public object Deserialize(PropertyMapping prop, string memberName, object existing = null) { if (prop == null) { throw Error.ArgumentNull("prop"); } // ArrayMode avoid the dispatcher making nested calls into the RepeatingElementReader again // when reading array elements. FHIR does not support nested arrays, and this avoids an endlessly // nesting series of dispatcher calls if (!_arrayMode && prop.IsCollection) { var reader = new RepeatingElementReader(_current); return(reader.Deserialize(prop, memberName, existing)); } // If this is a primitive type, no classmappings and reflection is involved, // just parse the primitive from the input // NB: no choices for primitives! if (prop.IsPrimitive) { var reader = new PrimitiveValueReader(_current); return(reader.Deserialize(prop.ElementType)); } // A Choice property that contains a choice of any resource // (as used in Resource.contained) if (prop.Choice == ChoiceType.ResourceChoice) { var reader = new ResourceReader(_current); return(reader.Deserialize(existing, nested: true)); } ClassMapping mapping; // Handle other Choices having any datatype or a list of datatypes if (prop.Choice == ChoiceType.DatatypeChoice) { // For Choice properties, determine the actual type of the element using // the suffix of the membername (i.e. deceasedBoolean, deceasedDate) // This function implements type substitution. mapping = determineElementPropertyType(prop, memberName); } // Else use the actual return type of the property else { mapping = _inspector.ImportType(prop.ElementType); } var cplxReader = new ComplexTypeReader(_current); return(cplxReader.Deserialize(mapping, existing)); }
public void use_the_adapter_son() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); record["Id"].Returns("Hej"); var sut = new PropertyMapping<Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnToPropertyAdapter = o => o + "Hello"; sut.Map(record, actual); actual.Id.Should().Be("HejHello"); }
private void write(ClassMapping mapping, object instance, bool summary, PropertyMapping prop, SerializationMode mode) { // Check whether we are asked to just serialize the value element (Value members of primitive Fhir datatypes) // or only the other members (Extension, Id etc in primitive Fhir datatypes) // Default is all if (mode == SerializationMode.ValueElement && !prop.RepresentsValueElement) { return; } if (mode == SerializationMode.NonValueElements && prop.RepresentsValueElement) { return; } var value = prop.GetValue(instance); var isEmptyArray = (value as IList) != null && ((IList)value).Count == 0; // Message.Info("Handling member {0}.{1}", mapping.Name, prop.Name); if (value != null && !isEmptyArray) { string memberName = prop.Name; // For Choice properties, determine the actual name of the element // by appending its type to the base property name (i.e. deceasedBoolean, deceasedDate) if (prop.Choice == ChoiceType.DatatypeChoice) { memberName = determineElementMemberName(prop.Name, value.GetType()); } _current.WriteStartProperty(memberName); var writer = new DispatchingWriter(_current); // Now, if our writer does not use dual properties for primitive values + rest (xml), // or this is a complex property without value element, serialize data normally if (!_current.HasValueElementSupport || !serializedIntoTwoProperties(prop, value)) { writer.Serialize(prop, value, summary, SerializationMode.AllMembers); } else { // else split up between two properties, name and _name writer.Serialize(prop, value, summary, SerializationMode.ValueElement); _current.WriteEndProperty(); _current.WriteStartProperty("_" + memberName); writer.Serialize(prop, value, summary, SerializationMode.NonValueElements); } _current.WriteEndProperty(); } }
public void CollectionContainsWithLambdaShouldBeFalseWhenNoItemsMatching() { acceptance .Expect(x => x.Columns.Contains(c => c.Name == "boo")); var mapping = new PropertyMapping(); mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1")); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeFalse(); }
public void CollectionIsNotEmptyShouldBeTrueWithItemsWhenUsingExpression() { acceptance .Expect(x => x.Columns.IsNotEmpty()); var mapping = new PropertyMapping(); mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1")); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeTrue(); }
/// <summary> /// Adds the property mapping. /// </summary> /// <param name="name">The name.</param> /// <param name="objectType">Type of the object.</param> /// <param name="allowsMultipleValues"> /// if set to <c>true</c> [allows multiple values]. /// </param> public void AddPropertyMapping(string name, Type objectType, bool allowsMultipleValues) { if (name != null && objectType != null) { var m = new PropertyMapping { ObjectType = objectType, AllowsMultipleValuesPerProperty = allowsMultipleValues }; _propertyMap[name.ToUpper( )] = m; } }
public string GetColumnName(PropertyMapping propMapping, string tableAlias, bool performColumnAliasNormalization) { var sqlTableAlias = tableAlias == null ? string.Empty : $"{GetDelimitedIdentifier(tableAlias)}."; var sqlColumnAlias = performColumnAliasNormalization && propMapping.DatabaseColumnName != propMapping.PropertyName ? $" AS {GetDelimitedIdentifier(propMapping.PropertyName)}" : string.Empty; return (ResolveWithCultureInvariantFormatter( $"{sqlTableAlias}{GetDelimitedIdentifier(propMapping.DatabaseColumnName)}{sqlColumnAlias}")); }
public void MultipleExpectSetsShouldValidateToFalseIfOnlyOneMatches() { acceptance .Expect(x => x.Insert, Is.Set) .Expect(x => x.Update, Is.Set); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); }
public void CombinationOfSetAndNotSetShouldValidateToFalseWhenNoneMatch() { acceptance .Expect(x => x.Insert, Is.Not.Set) .Expect(x => x.Update, Is.Set); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeFalse(); }
/// <summary> /// Adds the property mapping. /// </summary> /// <param name="name">The name.</param> /// <param name="resolver">The resolver.</param> /// <param name="allowsMultipleValues"> /// if set to <c>true</c> [allows multiple values]. /// </param> public void AddPropertyMapping(string name, TypeResolverDelegate resolver, bool allowsMultipleValues) { if (name != null && resolver != null) { var m = new PropertyMapping { Resolver = resolver, AllowsMultipleValuesPerProperty = allowsMultipleValues }; _propertyMap[name.ToUpper( )] = m; } }
public void CollectionContainsWithStringShouldBeTrueWhenItemsMatching() { acceptance .Expect(x => x.Columns.Contains("Column1")); var mapping = new PropertyMapping(); mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1")); acceptance .Matches(new PropertyInspector(mapping)) .ShouldBeTrue(); }
public void AnyShouldValidateToTrueIfOneMatches() { acceptance .Any(c => c.Expect(x => x.Name, Is.Set), c => c.Expect(x => x.Type, Is.Set), c => c.Expect(x => x.Insert, Is.Set)); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Name, Layer.Defaults, "Property1"); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
protected override Expression VisitMember(MemberExpression node) { if (directlyInSelectMethod) { PropertyMapping mapping = GetTranslationMapping(node.Member as PropertyInfo); if (mapping != null) { return(GetTranslationExpression(node, mapping, CurrentLanguageCode)); } return(base.VisitMember(node)); } return(base.VisitMember(node)); }
public void MultipleExpectsShouldValidateToTrueIfGivenMatchingModel() { acceptance.Expect(x => x.Insert, Is.Set); acceptance.Expect(x => x.Update, Is.Set); var propertyMapping = new PropertyMapping(); propertyMapping.Set(x => x.Insert, Layer.Defaults, true); propertyMapping.Set(x => x.Update, Layer.Defaults, true); acceptance .Matches(new PropertyInspector(propertyMapping)) .ShouldBeTrue(); }
public void map_without_adapter() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); record["Id"].Returns("Hej"); var sut = new PropertyMapping <Ok>("Id", (o, o1) => o.Id = (string)o1, o => o.Id); sut.Map(record, actual); actual.Id.Should().Be("Hej"); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ public VertexSchema() { Names = new NameProvider("Vertex", "Vertices", "v"); GetAccess = Access.All; CreateAccess = Access.Custom; DeleteAccess = Access.Custom; IsAbstract = true; //// VertexId = new DomainProperty <long>("VertexId", "v_id"); VertexId.IsUnique = true; VertexId.IsIndexed = true; Timestamp = new DomainProperty <long>("Timestamp", "v_ts"); Timestamp.IsElastic = true; VertexType = new DomainProperty <byte>("VertexType", "v_t"); //// FabId = new ApiProperty <long>("Id"); FabId.GetAccess = Access.All; FabId.CreateAccess = Access.None; FabId.ModifyAccess = Access.None; FabId.IsUnique = true; FabId.TraversalHas = Matching.Exact; FabTimestamp = new ApiProperty <long>("Timestamp"); FabTimestamp.GetAccess = Access.All; FabTimestamp.CreateAccess = Access.None; FabTimestamp.ModifyAccess = Access.None; FabTimestamp.TraversalHas = Matching.Custom; FabVertexType = new ApiProperty <byte>("VertexType"); FabVertexType.GetAccess = Access.All; FabVertexType.CreateAccess = Access.None; FabVertexType.ModifyAccess = Access.None; FabVertexType.TraversalHas = Matching.Exact; FabVertexType.FromEnum = "VertexType"; //// FabIdMap = new PropertyMapping <long, long>(VertexId, FabId); FabTimestampMap = new PropertyMapping <long, long>(Timestamp, FabTimestamp, CustomDir.Both); FabTimestampMap.ApiToDomainNote = "Convert Api.Timestamp from Unix-based seconds."; FabTimestampMap.DomainToApiNote = "Convert Domain.Timestamp to Unix-based seconds."; FabVertexTypeMap = new PropertyMapping <byte, byte>(VertexType, FabVertexType); }
public void should_replace_dbnull_with_the_defined_replacement_value_when_mapping_column_value() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); record["Age"].Returns(DBNull.Value); var sut = new PropertyMapping <Ok>("Age", (o, o1) => o.Age = (int)o1, ok => ok.Age); sut.NullValue = 1; sut.Map(record, actual); actual.Age.Should().Be(1); }
public void use_the_adapter_son() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); record["Id"].Returns("Hej"); var sut = new PropertyMapping <Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnToPropertyAdapter = o => o + "Hello"; sut.Map(record, actual); actual.Id.Should().Be("HejHello"); }
public void use_column_name_and_not_property_name_in_the_record() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); record["Id2"].Returns("Hej"); var sut = new PropertyMapping <Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnName = "Id2"; sut.Map(record, actual); actual.Id.Should().Be("Hej"); }
public void skip_db_null_value() { var record = Substitute.For <IDataRecord>(); var actual = new Ok(); record["Id2"].Returns(DBNull.Value); var sut = new PropertyMapping <Ok>("Id", (o, o1) => o.Id = (string)o1, ok => ok.Id); sut.ColumnName = "Id2"; sut.Map(record, actual); actual.Id.Should().BeNull(); }
private static LambdaExpression LanguageCodeLambda(PropertyMapping propertyMapping, ConstantExpression languageCode) { // Target: p => p.Language.Code == "en" var param = Expression.Parameter(propertyMapping.TranslationEntity, "p"); //{p} var languageProperty = Expression.Property( Expression.Property(param, propertyMapping.LanguageProperty), ((MemberExpression)StripConvert(((LambdaExpression)LocalizationConfig.LanguageExpression).Body)).Member.Name); //{p.Language.Code} var equalsExpression = Expression.Equal(languageProperty, languageCode); // {p.Language.Code == "en"} var languageCodeLambda = Expression.Lambda(equalsExpression, param); //{p => p.Language.Code == "en"} return(languageCodeLambda); }
protected virtual PropertyBuilder Map(Member property, string columnName) { var propertyMapping = new PropertyMapping(); var builder = new PropertyBuilder(propertyMapping, typeof(T), property); if (!string.IsNullOrEmpty(columnName)) { builder.Column(columnName); } properties.Add(new PassThroughMappingProvider(propertyMapping)); return(builder); }
public void Apply_CopiesValueFromSourceToTarget() { var propertyMapping = new PropertyMapping <Source, Target, string>(string.Empty, t => t.TargetValue, (s, t) => t.TargetValue = s.SourceValue, string.Empty); var source = new Source(); var target = new Target(); propertyMapping.Apply(source, target); target.TargetValue.Should().Be("Source"); }
public void SetValue(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; if (typeof(int).IsAssignableFrom(srcValue.GetType())) { targetObj.Properties[mapping.TargetProperty].StringValue = ((int)srcValue).ToString(); } else if (srcValue is string) { targetObj.Properties[mapping.TargetProperty].StringValue = (string)srcValue; } else { //其他情况如null,DbNull等,以及不知如何转换的 targetObj.Properties[mapping.TargetProperty].StringValue = string.Empty ; } }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { string enumType = mapping.Parameters["enumType"]; if (string.IsNullOrEmpty(enumType)) throw new System.Configuration.ConfigurationErrorsException("配置EnumPropertyComparer时,必须指定enumType属性"); var type = Type.GetType(enumType); if (type == null) throw new System.Configuration.ConfigurationErrorsException("未找到指定的枚举类型 " + enumType); object srcValue = srcValues[mapping.SourceProperty]; string targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (string.IsNullOrEmpty(targetString) == false) { return srcValue.Equals(int.Parse(targetString)); } else return false; }
public bool AreEqual(SyncSession session, PropertyMapping mapping, NameObjectCollection srcValues, SchemaObjectBase targetObj) { var srcValue = srcValues[mapping.SourceProperty] ?? Common.EmptyString; var targetString = targetObj.Properties[mapping.TargetProperty].StringValue; if (typeof(bool).IsAssignableFrom(srcValue.GetType())) { if (string.IsNullOrEmpty(targetString) == false) { return ((bool)srcValue).Equals(bool.Parse(targetString)); } else return false; // 左边对象有值,而右边对象没值 } else if (srcValue is string) { return string.Equals((string)srcValue, (string)targetString, StringComparison.OrdinalIgnoreCase); } else { return mapping.Parameters["sourceDefaultValue"] == targetString; //源对象为null或其他情形 } }
public void AddOrReplaceProperty(PropertyMapping mapping) { mappedMembers.AddOrReplaceProperty(mapping); }
public void AddPropertyMapping(string name, Type objectType, bool allowsMultipleValues) { if (name != null && objectType != null) { PropertyMapping m = new PropertyMapping(); m.ObjectType = objectType; m.AllowsMultipleValuesPerProperty = allowsMultipleValues; _PropertyMap[name.ToUpper()] = m; } }
public void AddPropertyMapping(string name, TypeResolverDelegate resolver, bool allowsMultipleValues) { if (name != null && resolver != null) { PropertyMapping m = new PropertyMapping(); m.Resolver = resolver; m.AllowsMultipleValuesPerProperty = allowsMultipleValues; _PropertyMap[name.ToUpper()] = m; } }
public void AddProperty(PropertyMapping property) { mergedComponent.AddProperty(property); }
public override void ProcessProperty(PropertyMapping propertyMapping) { Process(propertyMapping, propertyMapping.PropertyInfo); }
/// <summary> /// Removes a property mapping. /// </summary> /// <param name="propertyMapping">The property mapping to be removed.</param> public override void RemovePropertyMapping(PropertyMapping propertyMapping) { Check.NotNull(propertyMapping, "propertyMapping"); ThrowIfReadOnly(); m_properties.Remove(propertyMapping.Property.Name); }
/// <summary> /// Removes a property mapping. /// </summary> /// <param name="propertyMapping">The property mapping to be removed.</param> public abstract void RemovePropertyMapping(PropertyMapping propertyMapping);
/// <summary> /// Adds a property mapping. /// </summary> /// <param name="propertyMapping">The property mapping to be added.</param> public abstract void AddPropertyMapping(PropertyMapping propertyMapping);
private static string GetColumnNameFromPropertyMapping(EdmProperty edmProperty, PropertyMapping propertyMapping) { var colMapping = propertyMapping as ScalarPropertyMapping; if (colMapping == null) { throw new EnumGeneratorException(string.Format( "Expected ScalarPropertyMapping but found {0} when mapping property {1}", propertyMapping.GetType(), edmProperty)); } return colMapping.Column.Name; }
public void AddProperty(PropertyMapping property) { mappedMembers.AddProperty(property); }
/// <summary> /// Adds a property mapping. /// </summary> /// <param name="propertyMapping">The property mapping to be added.</param> public override void AddPropertyMapping(PropertyMapping propertyMapping) { Check.NotNull(propertyMapping, "propertyMapping"); ThrowIfReadOnly(); m_properties.Add(propertyMapping.Property.Name, propertyMapping); }
private void ReadProperty(IEdmEntityType entityType, IEdmProperty property) { string declaredPropertyName; string entityPropertyName = entityType.FullName() + "." + property.Name; if (property.DeclaringType is IEdmEntityType) { declaredPropertyName = (property.DeclaringType as IEdmEntityType).FullName() + "." + property.Name; } else { declaredPropertyName = entityPropertyName; } PropertyMapping mapping; if (_propertyUriMap.TryGetValue(declaredPropertyName, out mapping)) { _propertyUriMap[entityPropertyName] = mapping; } else { mapping = new PropertyMapping { Uri = GetUriMapping(property), IsInverse = GetBooleanAnnotationValue(property, AnnotationsNamespace, "IsInverse", false), IdentifierPrefix = GetStringAnnotationValue(property, AnnotationsNamespace, "IdentifierPrefix") }; // If the property maps to the resource identifier, do not record a property URI if (!String.IsNullOrEmpty(mapping.IdentifierPrefix)) { mapping.Uri = null; } _propertyUriMap[entityPropertyName] = mapping; if (!declaredPropertyName.Equals(entityPropertyName)) { _propertyUriMap[declaredPropertyName] = mapping; } } }
public object Write(PropertyMapping mappingModel) { return _propertyWriter.Write(mappingModel); }
public void set_Value_something() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); var sut = new PropertyMapping<Ok>("FirstName", (o, o1) => o.FirstName = (string)o1, ok => ok.FirstName); sut.PropertyType = typeof (string); sut.SetColumnValue(actual, "Hello"); actual.FirstName.Should().Be("Hello"); }
private void WritePropertyMapping(PropertyMapping propertyMapping) { DebugCheck.NotNull(propertyMapping); var scalarPropertyMapping = propertyMapping as ScalarPropertyMapping; if (scalarPropertyMapping != null) { WritePropertyMapping(scalarPropertyMapping); } else { var complexPropertyMapping = propertyMapping as ComplexPropertyMapping; if (complexPropertyMapping != null) { WritePropertyMapping(complexPropertyMapping); } } }
public void convert_if_Required() { var record = Substitute.For<IDataRecord>(); var actual = new Ok(); var sut = new PropertyMapping<Ok>("Age", (o, o1) => o.Age = (int)o1, ok => ok.Age); sut.PropertyType = typeof(int); sut.SetColumnValue(actual, (decimal)1); actual.Age.Should().Be(1); }