public void WhenDefaultValuesSetOnContext_PropertyInheritsFromContextIfNotSetOnType() { ISerializerSettings config = new SerializerSettings(); ITypeData typeData = config.Types[typeof(SimpleObject)]; typeData.DefaultValueSetting = DefaultValueOption.SuppressDefaultValues; config.DefaultValues[typeof(string)] = "FromType"; typeData.DefaultValues[typeof(int)] = 22; IPropertyData stringProperty = config.Types[typeof(SimpleObject)].FindProperty("StringValue"); Assert.IsFalse(stringProperty.ShouldWriteValue(config, "FromType")); Assert.IsTrue(stringProperty.ShouldWriteValue(config, "")); IPropertyData intProperty = config.Types[typeof(SimpleObject)].FindProperty("IntValue"); Assert.IsFalse(intProperty.ShouldWriteValue(config, 22)); Assert.IsTrue(intProperty.ShouldWriteValue(config, 0)); IPropertyData shortProperty = config.Types[typeof(SimpleObject)].FindProperty("ShortValue"); shortProperty.DefaultValue = (short)9; Assert.IsFalse(shortProperty.ShouldWriteValue(config, (short)9)); Assert.IsTrue(shortProperty.ShouldWriteValue(config, 0)); }
public void TestExecuteWhenFieldDoesNotExistThenExceptionIsThrown() { var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict); var locator = new Mock <IElementLocator>(MockBehavior.Strict); // ReSharper disable once RedundantAssignment IPropertyData property = null; locator.Setup(p => p.TryGetElement("doesnotexist", out property)).Returns(false); locator.Setup(p => p.GetProperty("doesnotexist")).Throws(new ElementExecuteException("Cannot find item")); var enterDataAction = new EnterDataAction(tokenManager.Object) { ElementLocator = locator.Object }; var context = new EnterDataAction.EnterDataContext("doesnotexist", "some value"); ExceptionHelper.SetupForException <ElementExecuteException>( () => enterDataAction.Execute(context), e => { locator.VerifyAll(); tokenManager.VerifyAll(); }); }
private IFunctionData UpdateToVersion1(IFunctionData data) { IPropertyData filePathProperty = data.FindPropertyById(FileShared.FilePathPropertyName); object value; if (filePathProperty.Value is IExpression) { value = filePathProperty.Value; } else if (filePathProperty.Value is string) { value = (TextFileHandle)filePathProperty.Value.ToString(); } else { value = filePathProperty.Value; } return(data .ReplaceProperty(filePathProperty, new Property(FileShared.FilePathPropertyName, typeof(TextFileHandle), ValueUseOption.RuntimeRead, null) { Value = value }) .UpdateOutput(TypeReference.Create(typeof(string))) .UpdateVersion("1")); }
public void TestExecuteClearsDataIfPropertyIsFound() { var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.Setup(p => p.ClearData()); // ReSharper disable once RedundantAssignment IPropertyData element = null; var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetElement("myitem", out element)).Returns(false); locator.Setup(p => p.GetProperty("myitem")).Returns(propData.Object); var getItemAction = new ClearDataAction { ElementLocator = locator.Object }; var context = new ClearDataAction.ClearDataContext("myitem"); var result = getItemAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); propData.VerifyAll(); }
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public override bool Compare(IPropertyData property, string expectedValue, string actualValue) { bool parsedValue; return (expectedValue != null && bool.TryParse(expectedValue, out parsedValue) && !parsedValue) ? !property.CheckElementExists() : property.CheckElementExists(); }
public static Ejb3Column[] BuildColumnFromAnnotation( ColumnAttribute[] anns, FormulaAttribute formulaAnn, Nullability nullability, IPropertyHolder propertyHolder, IPropertyData inferredData, IDictionary <string, Join> secondaryTables, ExtendedMappings mappings) { Ejb3Column[] columns; if (formulaAnn != null) { Ejb3Column formulaColumn = new Ejb3Column(); formulaColumn.SetFormula(formulaAnn.Value); formulaColumn.SetImplicit(false); formulaColumn.Mappings = mappings; formulaColumn.PropertyHolder = propertyHolder; formulaColumn.Bind(); columns = new Ejb3Column[] { formulaColumn }; } else { columns = BuildColumnFromAnnotation(anns, nullability, propertyHolder, inferredData, secondaryTables, mappings); } return(columns); }
/// <summary> /// Reads the properties and constructor arguments from type metadata declared on this type /// </summary> protected virtual IList <IPropertyData> ReadDeclaredProperties() { IList <IPropertyData> properties = new List <IPropertyData>(); MemberInfo[] members = ForType.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach (MemberInfo member in members) { IPropertyData property = null; if (member is PropertyInfo) { property = CreatePropertyHandler((PropertyInfo)member); } else if (member is FieldInfo) { property = CreateFieldHandler((FieldInfo)member); } if (property != null) { properties.Add(property); property.Alias = OwningRepository.PropertyNamingStrategy.GetName(property.Name); OwningRepository.ProcessAttributes(property, member); } } return(properties); }
// ---- internal ---- private string GetTitle() { string result = ""; if (objectData != null) { IPropertyData nameProperty = objectData.Properties[PropertyIds.Name]; if (nameProperty != null) { result = nameProperty.FirstValue as string; } } if (typeDef != null) { if (typeDef.DisplayName != null) { result = typeDef.DisplayName; } } if (bulkUpdate != null) { result = "Bulk Update Properties"; } return(result); }
public static IPropertyData PurchaceorUpgradeRabbitHole(RealEstateManager ths, RabbitHole rabbitHole) { IPropertyData data = null; PropertyData data2 = ths.FindProperty(rabbitHole); if (data2 == null) { if (ths.mOwningHousehold.FamilyFunds >= rabbitHole.RabbitHoleTuning.kInvestCost) { NRaas.StoryProgression.Main.Money.AdjustFunds(ths.mOwningHousehold, "PropertyBought", -rabbitHole.RabbitHoleTuning.kInvestCost); data2 = new PropertyData.RabbitHole(rabbitHole, ths); ths.AddToProperties(data2); } } else if (ths.mOwningHousehold.FamilyFunds >= rabbitHole.RabbitHoleTuning.kBuyoutCost) { ReimburseDeeds(ths, rabbitHole); NRaas.StoryProgression.Main.Money.AdjustFunds(ths.mOwningHousehold, "PropertyBought", -rabbitHole.RabbitHoleTuning.kBuyoutCost); data2.UpgradeToFullOwnership(); ths.UpdateProperty(data2); } data = data2; if (data != null) { Tutorialette.TriggerLesson(Lessons.RealEstate, null); } return(data); }
protected override ActionResult Execute(WindowLocatorActionContext context) { var application = context.Application; var parentWindow = context.Window; var propertyName = context.PropertyName; IPropertyData propertyData = this.WindowLocator.GetWindow(propertyName); this.logger.Debug("Ensuring window is displayed: {0} ({1})", propertyName, propertyData.PropertyType.FullName); IWindow window = null; if (parentWindow == null) { // find window from the application application.FindWindow(propertyData.PropertyType, out window); } else { // find child window from the parent window parentWindow.FindWindow(propertyData.PropertyType, out window); } return(window == null ? ActionResult.Failure(new ControlExecuteException("Could not retrieve a window from property '{0}'", propertyName)) : ActionResult.Successful(window)); }
/// <summary> /// Returns the property data for a type's property /// </summary> /// <typeparam name="T">the type that contains the property</typeparam> /// <typeparam name="P">the property type</typeparam> /// <param name="typeSettings">the type settings object</param> /// <param name="propertyExpression">linq expression that references the property</param> /// <returns>type meta data</returns> public static IPropertyData Property <T, P>(this ITypeSettings typeSettings, Expression <Func <T, P> > propertyExpression) { MemberInfo memberInfo = ReflectionUtils.GetMemberInfo(propertyExpression); IPropertyData property = typeSettings[typeof(T)].FindPropertyByName(memberInfo.Name); return(property); }
public void JsonExProperty_AppliesAlias() { Serializer s = new Serializer(); IPropertyData pd = s.Settings.Types[typeof(JsonPropertyAlias)].FindProperty("MyProperty"); Assert.AreEqual("serialize_this", pd.Alias); }
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public override bool Compare(IPropertyData property, string expectedValue, string actualValue) { // Try matching and parsing the values for each type. bool comparisonResult; if (TryCompare <DateTime>(expectedValue, actualValue, DateTime.TryParse, this.Compare, out comparisonResult)) { return(comparisonResult); } if (TryCompare <bool>(expectedValue, actualValue, bool.TryParse, this.Compare, out comparisonResult)) { return(comparisonResult); } if (TryCompare <int>(expectedValue, actualValue, int.TryParse, this.Compare, out comparisonResult)) { return(comparisonResult); } if (TryCompare <double>(expectedValue, actualValue, double.TryParse, this.Compare, out comparisonResult)) { return(comparisonResult); } // If all specialties fail, use the string comparison. TryCompare <string>(expectedValue, actualValue, StringParse, this.Compare, out comparisonResult); return(comparisonResult); }
public void TestExecuteWhenContextIsValidPropertyFillsThePropertyData() { var tokenManager = new Mock <ITokenManager>(MockBehavior.Strict); tokenManager.Setup(t => t.SetToken("some data")).Returns("translated data"); var propData = new Mock <IPropertyData>(MockBehavior.Strict); propData.Setup(p => p.FillData("translated data")); // ReSharper disable RedundantAssignment IPropertyData element = null; // ReSharper restore RedundantAssignment var locator = new Mock <IElementLocator>(MockBehavior.Strict); locator.Setup(p => p.TryGetElement("myitem", out element)).Returns(false); locator.Setup(p => p.GetProperty("myitem")).Returns(propData.Object); var getItemAction = new EnterDataAction(tokenManager.Object) { ElementLocator = locator.Object }; var context = new EnterDataAction.EnterDataContext("myitem", "some data"); var result = getItemAction.Execute(context); Assert.AreEqual(true, result.Success); locator.VerifyAll(); propData.VerifyAll(); tokenManager.VerifyAll(); }
private static Ejb3Column[] BuildImplicitColumn(IPropertyData inferredData, IDictionary <string, Join> secondaryTables, IPropertyHolder propertyHolder, Nullability nullability, ExtendedMappings mappings) { Ejb3Column[] columns; columns = new Ejb3Column[1]; Ejb3Column column = new Ejb3Column(); column.SetImplicit(false); //not following the spec but more clean if (nullability != Nullability.ForcedNull && inferredData.ClassOrElement.IsPrimitive && !inferredData.Property.GetType().IsArray) //TODO: IsArray in this way ??? { column.SetNullable(false); } column.SetLength(DEFAULT_COLUMN_LENGTH); column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName); column.PropertyHolder = propertyHolder; column.SetJoins(secondaryTables); column.Mappings = mappings; column.Bind(); columns[0] = column; return(columns); }
public override void Process(IMetaData metaData, ICustomAttributeProvider attributeProvider, ISerializerSettings config) { if (metaData is IPropertyData) { IPropertyData property = (IPropertyData)metaData; JsonExDefaultAttribute defaultAttr = ReflectionUtils.GetAttribute <JsonExDefaultAttribute>(attributeProvider, false); if (defaultAttr != null) { switch (defaultAttr.DefaultValueSetting) { case DefaultValueOption.InheritParentSetting: case DefaultValueOption.SuppressDefaultValues: property.DefaultValueSetting = defaultAttr.DefaultValueSetting; if (defaultAttr.DefaultValueSet) { property.DefaultValue = defaultAttr.DefaultValue; } break; case DefaultValueOption.WriteAllValues: property.DefaultValueSetting = defaultAttr.DefaultValueSetting; break; } } } else if (metaData is TypeData) { Type classType = metaData.ForType; TypeData typeData = (TypeData)metaData; // apply assembly defaults first AssemblyCache cache = GetAssemblyCache(classType, config); if (cache.defaultValues != null) { typeData.DefaultValues = new DefaultValueCollection(cache.defaultValues); } if (cache.defaultOption != DefaultValueOption.InheritParentSetting) { typeData.DefaultValueSetting = cache.defaultOption; } bool typeSet = false; foreach (JsonExDefaultValuesAttribute attr in attributeProvider.GetCustomAttributes(typeof(JsonExDefaultValuesAttribute), false)) { if (attr.DefaultValueSetting != DefaultValueOption.InheritParentSetting) { typeData.DefaultValueSetting = attr.DefaultValueSetting; } if (attr.Type != null) { typeData.DefaultValues[attr.Type] = attr.DefaultValue; typeSet = true; } } if (typeData.DefaultValueSetting == DefaultValueOption.InheritParentSetting && typeSet) { typeData.DefaultValueSetting = DefaultValueOption.SuppressDefaultValues; } } }
public void FindProperty_FindsIgnoredProperties() { SerializerSettings context = new SerializerSettings(); ITypeData handler = context.Type <IgnoredFieldClass>(); IPropertyData fieldHandler = handler.FindProperty("IVal"); Assert.IsNotNull(fieldHandler, "Ignored property not found"); }
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public override bool Compare(IPropertyData property, string expectedValue, string actualValue) { bool parsedValue; return((expectedValue != null && bool.TryParse(expectedValue, out parsedValue) && !parsedValue) ? !property.CheckElementExists() : property.CheckElementExists()); }
private IPropertyData FixConnectionTypeProperty(IPropertyData property) { if (property.TypeReference.IsCompiled && property.TypeReference.GetUnderlyingType() == typeof(ConnectionTypeSelection)) { return(property); } return(FixDesignTimeConnectionTypeProperty(property)); }
/// <summary> /// Called when an element is completed. /// </summary> /// <param name="key">The element key.</param> /// <param name="item">The item if located; otherwise <c>null</c>.</param> public void OnLocateComplete(string key, IPropertyData item) { if (item == null || !this.HighlightModeEnabled()) { return; } item.Highlight(); }
/// <summary> /// Adds a property. /// </summary> /// <param name="property">the property to add.</param> public void AddProperty(IPropertyData property) { if (property == null || property.Id == null) { return; } propertyList.Add(property); propertyDict[property.Id] = property; }
public override void Process(IMetaData metaData, ICustomAttributeProvider attributeProvider, ISerializerSettings config) { if (metaData is IPropertyData) { IPropertyData property = (IPropertyData)metaData; if (attributeProvider.IsDefined(typeof(XmlIgnoreAttribute), false)) property.Ignored = true; } }
public void JsonExProperty_AliasOverridesNamingStrategy() { Serializer s = new Serializer(); s.Settings.Types.PropertyNamingStrategy = new DelegateNamingStrategy(delegate(string old) { return("__" + old + "__"); }); IPropertyData pd = s.Settings.Types[typeof(JsonPropertyAlias)].FindProperty("MyProperty"); Assert.AreEqual("serialize_this", pd.Alias); }
public IPropertyData this[string propertyId] { get { IPropertyData property = null; propertyDict.TryGetValue(propertyId, out property); return(property); } }
public void DefaultValuesOnPropertyAreConvertedIfNotSameType() { ISerializerSettings config = new SerializerSettings(); ITypeData typeData = config.Types[typeof(MockDefaultValues)]; IPropertyData property = typeData.FindProperty("ConvertedValue"); Assert.IsFalse(property.ShouldWriteValue(config, (short)32)); Assert.IsTrue(property.ShouldWriteValue(config, 0)); }
public void WhenDefaultValuesSetByAttributeOnType_PropertyInheritsIt() { ISerializerSettings config = new SerializerSettings(); ITypeData typeData = config.Types[typeof(MockDefaultValuesCascade)]; IPropertyData property = typeData.FindProperty("EmptyString"); Assert.IsFalse(property.ShouldWriteValue(config, "")); Assert.IsTrue(property.ShouldWriteValue(config, null)); }
public void WhenSuppressDefaultValuesOnProperty_ValueIsNotDefault_PropertyIsWritten(string propertyName, object value) { Serializer serializer = new Serializer(); ISerializerSettings config = serializer.Settings; IPropertyData property = config.Types[typeof(SimpleObject)].FindProperty(propertyName); property.DefaultValueSetting = DefaultValueOption.SuppressDefaultValues; Assert.IsTrue(property.ShouldWriteValue(config, value)); }
public void WhenSuppressDefaultValuesOnType_CascadesToProperty() { ISerializerSettings config = new SerializerSettings(); ITypeData typeData = config.Types[typeof(SimpleObject)]; typeData.DefaultValueSetting = DefaultValueOption.SuppressDefaultValues; IPropertyData property = config.Types[typeof(SimpleObject)].FindProperty("IntValue"); Assert.IsFalse(property.ShouldWriteValue(config, 0)); }
public void WhenWriteAllValuesOnProperty_ValueIsDefault_PropertyWritten(string propertyName) { Serializer serializer = new Serializer(); ISerializerSettings config = serializer.Settings; IPropertyData property = config.Types[typeof(SimpleObject)].FindProperty(propertyName); SimpleObject testObject = new SimpleObject(); property.DefaultValueSetting = DefaultValueOption.WriteAllValues; Assert.IsTrue(property.ShouldWriteValue(config, property.GetValue(testObject))); }
public void TestNamedArgumentsNotIgnored() { SerializerSettings context = new SerializerSettings(); ITypeData typeData = new TypeData <NamedOnlyExactConstructor>(context); IPropertyData stringPropA = typeData.FindProperty("StringPropA"); IPropertyData stringPropB = typeData.FindProperty("StringPropB"); Assert.IsFalse(stringPropA.Ignored, "stringPropA Constructor argument should not be ignored"); Assert.IsFalse(stringPropB.Ignored, "stringPropA Constructor argument should not be ignored"); }
/// <summary> /// Ignore a property to keep from being serialized, same as if the JsonExIgnore attribute had been set /// </summary> /// <param name="name">the name of the property</param> public virtual void IgnoreProperty(string name) { IPropertyData handler = FindProperty(name); if (handler == null) { throw new ArgumentException("Property " + name + " does not exist on Type " + this.ForType, "name"); } handler.Ignored = true; }
public PropertyDiff(IPropertyData oldField, IPropertyData newField) { AddedAttributes = new List<IAttributeData>(); RemovedAttributes = new List<IAttributeData>(); if (oldField.PropertySignature != newField.PropertySignature) { throw new NtegrityException("Attempted to diff two different Enums!"); } PropertySignature = oldField.PropertySignature; GetAddedAndRemovedAttributes(oldField, newField); }
/// <summary> /// Tries the get the element. /// </summary> /// <param name="propertyName">The key.</param> /// <param name="propertyData">The property data.</param> /// <returns><c>true</c> if the element exists; otherwise <c>false</c>.</returns> public bool TryGetElement(string propertyName, out IPropertyData propertyData) { foreach (var locatorAction in this.filterActions) { locatorAction.OnLocate(propertyName); } var result = this.page.TryGetElement(propertyName, out propertyData); foreach (var locatorAction in this.filterActions) { locatorAction.OnLocateComplete(propertyName, propertyData); } return result; }
private void GetAddedAndRemovedAttributes(IPropertyData beforeField, IPropertyData afterField) { foreach (var oldAttribute in beforeField.AttributeData) { if (afterField.AttributeData.All(x => x.Name != oldAttribute.Name)) { RemovedAttributes.Add(oldAttribute); HasChanged = true; } } foreach (var newAttribute in afterField.AttributeData) { if (beforeField.AttributeData.All(x => x.Name != newAttribute.Name)) { AddedAttributes.Add(newAttribute); HasChanged = true; } } }
/// <summary> /// Generates an expression for an item and adds it to the object /// </summary> /// <param name="data">the item being serialized</param> /// <param name="currentPath">the current path to the object</param> /// <param name="serializer">serializer instance</param> /// <param name="expression">the object expression</param> /// <param name="prop">the property being serialized</param> protected virtual void GenerateItemExpression(object data, JsonPath currentPath, IExpressionBuilder serializer, ObjectExpression expression, IPropertyData prop) { object value = prop.GetValue(data); if (!prop.ShouldWriteValue(this.Config, value)) return; Expression valueExpr; if (prop.HasConverter) { valueExpr = serializer.Serialize(value, currentPath.Append(prop.Alias), prop.TypeConverter); } else { valueExpr = serializer.Serialize(value, currentPath.Append(prop.Alias)); } if (value != null && !ReflectionUtils.AreEquivalentTypes(value.GetType(), prop.PropertyType)) { valueExpr = new CastExpression(value.GetType(), valueExpr); } expression.Add(prop.Alias, valueExpr); }
/// <summary> /// Checks that the constructor matches the constructor parameters by doing type conversion if necessary /// </summary> /// <param name="constructor">the constructor</param> /// <param name="properties">constructor parameter fields</param> /// <returns>true if this constructor matches the types in the constructor parameters</returns> private bool IsLooseMatch(ConstructorInfo constructor, IPropertyData[] properties) { Type[] types = new Type[properties.Length]; for (int i = 0; i < properties.Length; i++) types[i] = properties[i].PropertyType; try { MethodBase mb = Type.DefaultBinder.SelectMethod(BindingFlags.Default, new MethodBase[] { constructor }, types, new ParameterModifier[0]); return mb == constructor; } catch { return false; } }
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public abstract bool Compare(IPropertyData property, string expectedValue, string actualValue);
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public override bool Compare(IPropertyData property, string expectedValue, string actualValue) { return (actualValue == null) || !actualValue.Contains(expectedValue); }
private IList<IPropertyData> SortConstructorParameters(IList<IPropertyData> parameters, bool exactMatch) { StringComparison comparison = exactMatch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; foreach (ConstructorInfo constructor in ForType.GetConstructors()) { ParameterInfo[] ctorParms = constructor.GetParameters(); if (ctorParms.Length != parameters.Count) continue; IPropertyData[] result = new IPropertyData[parameters.Count]; int matchCount = 0; #pragma warning disable 612,618 foreach (IPropertyData property in parameters) { if (property.Position >= 0) { if (exactMatch && ctorParms[property.Position].ParameterType != property.PropertyType) break; //if (!exactMatch && !ctorParms[property.Position].ParameterType.IsAssignableFrom(property.PropertyType)) // break; if (result[property.Position] == null) { result[property.Position] = property; matchCount++; } else { // something else occupies this spot already, so there's a conflict with this constructor so try another // most likely none of them will work in this situation, but we'll let the outer method determine that break; } } else { // named argument, search the list int i; for (i = 0; i < ctorParms.Length; i++) { string parmName = ctorParms[i].Name; if (ctorParms[i].IsDefined(typeof(ConstructorParameterAttribute), false)) parmName = ReflectionUtils.GetAttribute<ConstructorParameterAttribute>(ctorParms[i], false).Name; if (parmName.Equals(property.ConstructorParameterName, comparison) && ((exactMatch && ctorParms[i].ParameterType == property.PropertyType) || (!exactMatch/* && ctorParms[i].ParameterType.IsAssignableFrom(property.PropertyType)*/))) break; } if (i < ctorParms.Length && result[i] == null) { result[i] = property; matchCount++; } else break; } } #pragma warning restore 612,618 if (matchCount == result.Length) { // found a match, return it if (exactMatch) return result; if (IsLooseMatch(constructor, result)) return result; } } return null; }
public void Write(IPropertyData data) { Func<object, string> converter; if (_converters.TryGetValue(data.Value.GetType(), out converter) == false) converter = _converters[typeof (object)]; _writer.WriteElementString(data.Name, converter(data.Value)); }
public static Ejb3Column[] BuildColumnFromAnnotation( ColumnAttribute[] anns, FormulaAttribute formulaAnn, Nullability nullability, IPropertyHolder propertyHolder, IPropertyData inferredData, IDictionary<string, Join> secondaryTables, ExtendedMappings mappings) { Ejb3Column[] columns; if (formulaAnn != null) { Ejb3Column formulaColumn = new Ejb3Column(); formulaColumn.SetFormula(formulaAnn.Value); formulaColumn.SetImplicit(false); formulaColumn.Mappings = mappings; formulaColumn.PropertyHolder = propertyHolder; formulaColumn.Bind(); columns = new Ejb3Column[] {formulaColumn}; } else { columns = BuildColumnFromAnnotation(anns, nullability, propertyHolder, inferredData, secondaryTables, mappings); } return columns; }
private static Ejb3Column[] BuildColumnFromAnnotation(ColumnAttribute[] anns, Nullability nullability, IPropertyHolder propertyHolder, IPropertyData inferredData, IDictionary<string, Join> secondaryTables, ExtendedMappings mappings) { ColumnAttribute[] actualCols = anns; ColumnAttribute[] overriddenCols = propertyHolder.GetOverriddenColumn(StringHelper.Qualify(propertyHolder.Path, inferredData.PropertyName)); if (overriddenCols != null) { //check for overridden first if (anns != null && overriddenCols.Length != anns.Length) throw new AnnotationException("AttributeOverride.column() should override all columns for now"); actualCols = overriddenCols.Length == 0 ? null : overriddenCols; log.DebugFormat("Column(s) overridden for property {0}", inferredData.PropertyName); } if (actualCols == null) return BuildImplicitColumn(inferredData, secondaryTables, propertyHolder, nullability, mappings); int length = actualCols.Length; Ejb3Column[] columns = new Ejb3Column[length]; for (int index = 0; index < length; index++) { ColumnAttribute col = actualCols[index]; String sqlType = col.ColumnDefinition.Equals("") ? null : col.ColumnDefinition; Ejb3Column column = new Ejb3Column(); column.SetImplicit(false); column.SetSqlType(sqlType); column.SetLength(col.Length); column.SetPrecision(col.Precision); column.SetScale(col.Scale); column.SetLogicalColumnName(col.Name); column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName); column.SetNullable(col.Nullable); //TODO force to not null if available? This is a (bad) user choice. column.SetUnique(col.Unique); column.SetInsertable(col.Insertable); column.SetUpdatable(col.Updatable); column.SetSecondaryTableName(col.Table); column.PropertyHolder = propertyHolder; column.SetJoins(secondaryTables); column.Mappings = mappings; column.Bind(); columns[index] = column; } return columns; }
private static Ejb3Column[] BuildImplicitColumn(IPropertyData inferredData, IDictionary<string, Join> secondaryTables, IPropertyHolder propertyHolder, Nullability nullability, ExtendedMappings mappings) { Ejb3Column[] columns; columns = new Ejb3Column[1]; Ejb3Column column = new Ejb3Column(); column.SetImplicit(false); //not following the spec but more clean if (nullability != Nullability.ForcedNull && inferredData.ClassOrElement.IsPrimitive && !inferredData.Property.GetType().IsArray ) //TODO: IsArray in this way ??? { column.SetNullable(false); } column.SetLength(DEFAULT_COLUMN_LENGTH); column.PropertyName = BinderHelper.GetRelativePath(propertyHolder, inferredData.PropertyName); column.PropertyHolder = propertyHolder; column.SetJoins(secondaryTables); column.Mappings = mappings; column.Bind(); columns[0] = column; return columns; }
/// <summary> /// Compares the values using the specified property. /// </summary> /// <param name="property">The property.</param> /// <param name="expectedValue">The expected value.</param> /// <param name="actualValue">The actual value.</param> /// <returns><c>true</c> if the comparison passes, <c>false</c> otherwise.</returns> public override bool Compare(IPropertyData property, string expectedValue, string actualValue) { return (actualValue != null) && actualValue.StartsWith(expectedValue, StringComparison.InvariantCultureIgnoreCase); }
/// <summary> /// Checks the element. /// </summary> /// <param name="propertyData">The property data.</param> /// <returns><c>true</c> if the element exists, <c>false</c> otherwise.</returns> protected override bool CheckElement(IPropertyData propertyData) { return propertyData.CheckElementExists(); }
/// <summary> /// Compares the specified <see paramref="actualValue"/> to the property data <see cref="ComparisonValue"/>. /// </summary> /// <param name="propertyData">The property data.</param> /// <param name="actualValue">The comparison value.</param> /// <returns><c>true</c> if the values match; otherwise <c>false</c>.</returns> public bool Compare(IPropertyData propertyData, string actualValue) { return this.Comparer != null && this.Comparer.Compare(propertyData, this.ComparisonValue, actualValue); }