Example #1
0
            public void Load(MSBuildBasedProject project, string configuration, string platform)
            {
                PropertyStorageLocations newLocation;
                string v;

                if (treatPropertyValueAsLiteral)
                {
                    v = project.GetProperty(configuration, platform, propertyName, out newLocation);
                }
                else
                {
                    v = project.GetUnevalatedProperty(configuration, platform, propertyName, out newLocation);
                }

                if (newLocation == PropertyStorageLocations.Unknown)
                {
                    newLocation = defaultLocation;
                }

                isLoading = true;
                try {
                    this.Value    = GenericConverter.FromString(v, defaultValue);
                    this.Location = newLocation;
                } finally {
                    isLoading = false;
                }
            }
Example #2
0
        public SupplierDto Convert(SupplierPoco source, SupplierDto destination, ResolutionContext context)
        {
            var gc    = new GenericConverter <SupplierPoco, SupplierDto>();
            var value = gc.Convert(source, destination, context);

            return(value);
        }
Example #3
0
            public bool Save(MSBuildBasedProject project, string configuration, string platform)
            {
                string newValue = GenericConverter.ToString(val);

                project.SetProperty(configuration, platform, propertyName, newValue, location, treatPropertyValueAsLiteral);
                return(true);
            }
Example #4
0
 public void SetProperty <T>(string propertyName, T value,
                             bool treatPropertyValueAsLiteral,
                             PropertyStorageLocations location)
 {
     project.SetProperty(configuration, platform, propertyName,
                         GenericConverter.ToString(value), location, treatPropertyValueAsLiteral);
 }
Example #5
0
        /// <summary>
        /// Execute mapping for baseic types
        /// </summary>
        public void MapTypes()
        {
            var wkbConverter     = new WellKnownBinaryConverter(this._geometryFactory);
            var genericConverter = new GenericConverter();
            var int32Converter   = new Int32Converter();

            var map = new TypeMap(DbType.Int32, typeof(uint), genericConverter);

            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Int32, typeof(int), int32Converter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.String, typeof(string), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.DateTime, typeof(DateTime), genericConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IMapPoint), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(ILineString), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IPolygon), wkbConverter);
            this._typeRegister.Set(map);

            map = new TypeMap(DbType.Binary, typeof(IGeometry), wkbConverter);
            this._typeRegister.Set(map);
        }
Example #6
0
            public void ConvertObject_VTypeNoMismatch_ResultOk()
            {
                int cacheItem = 10;

                int returnItem = GenericConverter.ConvertObject <int>(cacheItem);

                Assert.AreEqual(cacheItem, returnItem);
            }
Example #7
0
            public void TryConvertObject_RTypeMismatch_ReturnNull()
            {
                int cacheItem = 10;

                var returnItem = GenericConverter.TryConvertObject <TestClass>(cacheItem);

                Assert.AreEqual(returnItem, null);
            }
Example #8
0
            public void TryConvertObject_RTypeIsNull_ReturnNull()
            {
                TestClass cacheItem = null;

                var returnItem = GenericConverter.TryConvertObject <TestClass>(cacheItem);

                Assert.IsNull(returnItem);
            }
Example #9
0
            public void TryConvertObject_VTypeMismatch_ReturnZero()
            {
                TestClass cacheItem = new TestClass();

                int returnItem = GenericConverter.TryConvertObject <int>(cacheItem);

                Assert.AreEqual(returnItem, 0);
            }
Example #10
0
            public void ConvertObject_RTypeNoMismatch_ReturnNull()
            {
                TestClass cacheItem = new TestClass();

                var returnItem = GenericConverter.ConvertObject <TestClass>(cacheItem);

                Assert.NotNull(returnItem);
                Assert.AreEqual(returnItem.Test, cacheItem.Test);
            }
        public void Json(string inputFilename, string expectedOutputFilename)
        {
            string input          = File.ReadAllText(inputFilename);
            string expectedOutput = File.ReadAllText(expectedOutputFilename);

            IConverter rebalanceInfoConverter = new GenericConverter <Node>(new ValveFormatParser(),
                                                                            new Tf2RebalanceTransformation(new ItemInfoSource(_itemInfos),
                                                                                                           new ClassNameSource()));
            IRebalanceInfoFormatter formatter = new RebalanceInfoJsonFormatter();

            IEnumerable <RebalanceInfo> rebalanceInfos = rebalanceInfoConverter.Execute(input);
            string output = formatter.Create(rebalanceInfos);

            Assert.AreEqual(expectedOutput, output);
        }
Example #12
0
        public T GetProperty <T>(string propertyName, T defaultValue,
                                 bool treatPropertyValueAsLiteral)
        {
            string v;

            if (treatPropertyValueAsLiteral)
            {
                v = project.GetProperty(configuration, platform, propertyName);
            }
            else
            {
                v = project.GetUnevalatedProperty(configuration, platform, propertyName);
            }
            return(GenericConverter.FromString(v, defaultValue));
        }
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method.
        /// </summary>
        /// <returns>
        /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed.
        /// </returns>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information. </param><param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services. </param><param name="value">The object to edit. </param>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            AppearanceEditor editor;

            if (context != null && context.Instance != null && provider != null)
            {
                object currentValue = value;
                if (value is string)
                {
                    var convet = new GenericConverter <MonthCalanderAppearance>();
                    currentValue = convet.ConvertTo(value, typeof(MonthCalanderAppearance));
                }
                editor = new AppearanceEditor((MonthCalanderAppearance)currentValue);
                editor.ShowDialog();
                value = editor.Value;
                if (context.Instance is MonthCalander)
                {
                    ((MonthCalander)context.Instance).Appearance.Assign(editor.Value);
                    ((MonthCalander)context.Instance).SetThemeDefaults();
                }
            }
            return(value);
        }
Example #14
0
        public static string[] AlteOderGeloeschteDateienLoeschenUndHochzuladendeZurueckGeben(
            string gaitoBotEditorID,
            DateiPublizierungsInfos[] dateien)
        {
            de.springwald.gaitobot.publizierung.Gaitobot_de_publizieren.DateiPublizierungsInfos[] dateien1 = GenericConverter <DateiPublizierungsInfos[], de.springwald.gaitobot.publizierung.Gaitobot_de_publizieren.DateiPublizierungsInfos[]> .ConvertTo(dateien);

            return(PublizierDienst.Webdienst.AlteOderGeloeschteDateienLoeschenUndHochzuladendeZurueckGeben(gaitoBotEditorID, dateien1));
        }
 /// <summary>
 /// Sets the value of the specified meta data item. The value is escaped before
 /// setting it to ensure characters like ';' or '$' are not interpreted by MSBuild.
 /// </summary>
 public void SetEvaluatedMetadata <T>(string metadataName, T value)
 {
     SetEvaluatedMetadata(metadataName, GenericConverter.ToString(value));
 }
 /// <summary>
 /// Gets the value of the metadata item with the specified name.
 /// Returns defaultValue for non-existing meta data items.
 /// </summary>
 public T GetEvaluatedMetadata <T>(string metadataName, T defaultValue)
 {
     return(GenericConverter.FromString(GetEvaluatedMetadata(metadataName), defaultValue));
 }
Example #17
0
        //static class GenericDelegate<TDelegate> where TDelegate : MulticastDelegate
        //{
        //    // TResult F(Tuple<PhpValue, Context>, arg1, ..., argN) => value.AsCallable().Invoke(Context, new[]{ arg1, ..., argN })
        //    public static readonly MethodInfo/*!*/s_func = CreateFunc();

        //    static MethodInfo CreateFunc()
        //    {

        //    }
        //}

        ///// <summary>
        ///// Converts given value to <see cref="PhpValue"/>.
        ///// </summary>
        ///// <typeparam name="T">Source CLR type.</typeparam>
        ///// <param name="value">Value to be converted.</param>
        ///// <returns>Value converted to <see cref="PhpValue"/>.</returns>
        //public static PhpValue ToPhpValue<T>(this T value) => GenericConverter<T>.s_toPhpValue(value);

        /// <summary>
        /// Casts <see cref="PhpValue"/> to a given type <typeparamref name="T"/>.
        /// Throws an exception if cast is not possible.
        /// </summary>
        /// <typeparam name="T">Conversion target.</typeparam>
        /// <param name="value">Value to be converted.</param>
        /// <returns>Value as <typeparamref name="T"/>.</returns>
        public static T Cast <T>(this PhpValue value) => GenericConverter <T> .s_fromPhpValue(value);
        private void ReportSelectorComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedReport = ReportSelectorComboBox.SelectedItem as LeaveAnalysis;
            ReportSummaryText.Text = selectedReport.Summary;

            ReportPropertyGrid.RowDefinitions.Clear();
            ReportPropertyGrid.Children.Clear();
            foreach (var property in selectedReport.GetType().GetProperties())
            {
                if (property.CanRead && property.CanWrite)
                {
                    var foundIgnoreAttribute = false;
                    foreach (var attribute in property.GetCustomAttributes(false))
                        if (attribute.GetType() == typeof(IgnorwAnalysisPropertyAttribute))
                            foundIgnoreAttribute = true;
                    if (foundIgnoreAttribute) continue;

                    AnalysisPropertyConverter converter = null;
                    foreach (var attribute in property.GetCustomAttributes(false))
                        if (attribute.GetType() == typeof(AnalysisPropertyConverterAttribute))
                            converter = (attribute as AnalysisPropertyConverterAttribute).MakeConverter();
                    if (converter == null) converter = new GenericConverter(property.PropertyType);

                    var lambdaProperty = property;
                    ReportPropertyGrid.RowDefinitions.Add(new RowDefinition());

                    var propLabel = new Label { Content = property.Name };
                    Grid.SetRow(propLabel, ReportPropertyGrid.RowDefinitions.Count - 1);
                    Grid.SetColumn(propLabel, 0);
                    ReportPropertyGrid.Children.Add(propLabel);

                    var propEditBox = new TextBox { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch };
                    Grid.SetRow(propEditBox, ReportPropertyGrid.RowDefinitions.Count - 1);
                    Grid.SetColumn(propEditBox, 1);
                    ReportPropertyGrid.Children.Add(propEditBox);

                    DefaultBackground = propEditBox.Background;

                    propEditBox.Text = converter.ConvertToString(property.GetValue(selectedReport, null));

                    propEditBox.TextChanged += (_sender, _args) =>
                    {
                        var value = propEditBox.Text;
                        try
                        {
                            var newValue = converter.ConvertFromString(value);
                            lambdaProperty.SetValue(selectedReport, newValue, null);
                            propEditBox.Background = DefaultBackground;
                        }
                        catch (Exception xp)
                        {
                            propEditBox.Background = ErrorBackground;
                        }
                    };
                }
            }
        }
		/// <summary>
		/// Converts a value to the specified type
		/// </summary>
		/// <param name="value">The value to convert</param>
		/// <param name="targetType">The type to which the value should be converted</param>
		/// <param name="targetDefaultValue">The default value to use instead of null or DBNull.Value</param>
		/// <param name="format">The format used for conversion</param>
		/// <param name="conversionObserver">Conversion observer</param>
		/// <returns>The converted value</returns>
		public static object Convert(object value, Type targetType, object targetDefaultValue, IFormatProvider format, IConversionObserver conversionObserver)
		{
			if (targetType == null)
			{
				throw new ArgumentNullException("targetType");
			}

			TypeInfo targetTypeInfo = targetType.GetTypeInfo();
			if (targetTypeInfo == null)
			{
				throw new ArgumentException(string.Format("Unable to get type information for type {0}", targetType));
			}

			if (targetTypeInfo.IsValueType && ((targetDefaultValue == null) || (ConversionsHelper.IsDBNull(targetDefaultValue))))
			{
				// converting to a value type, but having the default value as null / DBNull
				targetDefaultValue = ConversionsHelper.GetDefaultValue(targetType);
			}

			if ((value == null) || ConversionsHelper.IsDBNull(value) || ConversionsHelper.IsStringEmptyOrWhitespace(value))
			{
				// converting null / DBNull / empty or whitespaces-only string to target type => just return default value
				if(conversionObserver != null)
				{
					conversionObserver.NotifyKnownFallbackToDefaultValue(
						value: value,
						targetType: targetType,
						defaultTargetValue: targetDefaultValue,
						format: format,
						fallbackReason: new ArgumentNullException("value"));
				}

				return targetDefaultValue;
			}

			object converted = targetDefaultValue;

			try
			{
				// Handle Nullable<T>: try to convert to underlying T
				bool targetIsGenericType = ConversionsHelper.IsGenericType(targetTypeInfo);
				if (targetIsGenericType)
				{
					Type nullableTypeArg;
					if (ConversionsHelper.TryParseNullableType(targetType, out nullableTypeArg))
					{
						targetType = nullableTypeArg;
					}
				}

				var bootstrapper = Converter.Settings.SpecializedConversionsBootstrapper;
				if (bootstrapper == null)
				{
					bootstrapper = new DefaultSpecializedConversionsBootstrapper();
				}

				var converter = SpecializedConverterLocator.GetSpecializedConverter(value.GetType(), targetType, bootstrapper.DiscoveredSpecializedConverters);
				if (converter == null)
				{
					converter = new GenericConverter(targetType);
				}

				converted = converter.Convert(value, targetDefaultValue, format, conversionObserver);
			}
			catch (Exception ex)
			{
				if (
					// Convert.ChangeType may throw InvalidCastException when:
					//   - This conversion is not supported OR
					//   - value is null and conversionType is a value type OR
					//   - value does not implement the IConvertible interface
					(ex is InvalidCastException) ||

					// Convert.ChangeType may throw FormatException when :
					//   - value is not in a format for conversionType recognized by provider.
					(ex is FormatException) ||

					// Convert.ChangeType may throw OverflowException when:
					//   - value represents a number that is out of the range of conversionType.
					// - or -
					// Enum.Parse may throw OverflowException when:
					//   - value is outside the range of the underlying type of enumType
					(ex is OverflowException) ||

					// Convert.ChangeType may throw ArgumentNullException when :
					//   - conversionType is null.
					// - or -
					// Enum.IsDefined may throw System.ArgumentNullException when:
					//   - enumType or value is null
					// - or -
					// Enum.Parse may throw ArgumentNullException when :
					//   - enumType or value is null.
					(ex is ArgumentNullException) ||

					// Enum.IsDefined may throw System.ArgumentException when:
					//   - enumType is not an Enum.
					//   - The type of value is an enumeration, but it is not an enumeration of type enumType.
					//   - The type of value is not an underlying type of enumType.
					// - or -
					// Enum.Parse may throw ArgumentException when:
					//   - enumType is not an Enum
					//   - value is either an empty string or only contains white space
					//   - value is a name, but not one of the named constants defined for the enumeration
					(ex is ArgumentException) ||

					// Enum.IsDefined may throwSystem.InvalidOperationException when:
					//   - value is not type System.SByte, System.Int16, System.Int32, System.Int64, System.Byte, System.UInt16, System.UInt32, or System.UInt64, or System.String.
					(ex is InvalidOperationException))
				{
					if (conversionObserver != null)
					{
						conversionObserver.NotifyCaughtConversionException(
							value: value,
							targetType: targetType,
							defaultTargetValue: targetDefaultValue,
							format: format,
							conversionException: ex);
					}
				}
				else
				{
					throw;
				}
			}

			return converted;
		}
Example #20
0
        public static T Get <T>(string key)
        {
            var retObj = GetInstance()[key];

            return(GenericConverter.ConvertObject <T>(retObj));
        }
        /// <summary>
        /// Converts a value to the specified type
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <param name="targetType">The type to which the value should be converted</param>
        /// <param name="targetDefaultValue">The default value to use instead of null or DBNull.Value</param>
        /// <param name="format">The format used for conversion</param>
        /// <param name="conversionObserver">Conversion observer</param>
        /// <returns>The converted value</returns>
        public static object Convert(object value, Type targetType, object targetDefaultValue, IFormatProvider format, IConversionObserver conversionObserver)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            TypeInfo targetTypeInfo = targetType.GetTypeInfo();

            if (targetTypeInfo == null)
            {
                throw new ArgumentException(string.Format("Unable to get type information for type {0}", targetType));
            }

            if (targetTypeInfo.IsValueType && ((targetDefaultValue == null) || (ConversionsHelper.IsDBNull(targetDefaultValue))))
            {
                // converting to a value type, but having the default value as null / DBNull
                targetDefaultValue = ConversionsHelper.GetDefaultValue(targetType);
            }

            if ((value == null) || ConversionsHelper.IsDBNull(value) || ConversionsHelper.IsStringEmptyOrWhitespace(value))
            {
                // converting null / DBNull / empty or whitespaces-only string to target type => just return default value
                if (conversionObserver != null)
                {
                    conversionObserver.NotifyKnownFallbackToDefaultValue(
                        value: value,
                        targetType: targetType,
                        defaultTargetValue: targetDefaultValue,
                        format: format,
                        fallbackReason: new ArgumentNullException("value"));
                }

                return(targetDefaultValue);
            }

            object converted = targetDefaultValue;

            try
            {
                // Handle Nullable<T>: try to convert to underlying T
                bool targetIsGenericType = ConversionsHelper.IsGenericType(targetTypeInfo);
                if (targetIsGenericType)
                {
                    Type nullableTypeArg;
                    if (ConversionsHelper.TryParseNullableType(targetType, out nullableTypeArg))
                    {
                        targetType = nullableTypeArg;
                    }
                }

                var bootstrapper = Converter.Settings.SpecializedConversionsBootstrapper;
                if (bootstrapper == null)
                {
                    bootstrapper = new DefaultSpecializedConversionsBootstrapper();
                }

                var converter = SpecializedConverterLocator.GetSpecializedConverter(value.GetType(), targetType, bootstrapper.DiscoveredSpecializedConverters);
                if (converter == null)
                {
                    converter = new GenericConverter(targetType);
                }

                converted = converter.Convert(value, targetDefaultValue, format, conversionObserver);
            }
            catch (Exception ex)
            {
                if (
                    // Convert.ChangeType may throw InvalidCastException when:
                    //   - This conversion is not supported OR
                    //   - value is null and conversionType is a value type OR
                    //   - value does not implement the IConvertible interface
                    (ex is InvalidCastException) ||

                    // Convert.ChangeType may throw FormatException when :
                    //   - value is not in a format for conversionType recognized by provider.
                    (ex is FormatException) ||

                    // Convert.ChangeType may throw OverflowException when:
                    //   - value represents a number that is out of the range of conversionType.
                    // - or -
                    // Enum.Parse may throw OverflowException when:
                    //   - value is outside the range of the underlying type of enumType
                    (ex is OverflowException) ||

                    // Convert.ChangeType may throw ArgumentNullException when :
                    //   - conversionType is null.
                    // - or -
                    // Enum.IsDefined may throw System.ArgumentNullException when:
                    //   - enumType or value is null
                    // - or -
                    // Enum.Parse may throw ArgumentNullException when :
                    //   - enumType or value is null.
                    (ex is ArgumentNullException) ||

                    // Enum.IsDefined may throw System.ArgumentException when:
                    //   - enumType is not an Enum.
                    //   - The type of value is an enumeration, but it is not an enumeration of type enumType.
                    //   - The type of value is not an underlying type of enumType.
                    // - or -
                    // Enum.Parse may throw ArgumentException when:
                    //   - enumType is not an Enum
                    //   - value is either an empty string or only contains white space
                    //   - value is a name, but not one of the named constants defined for the enumeration
                    (ex is ArgumentException) ||

                    // Enum.IsDefined may throwSystem.InvalidOperationException when:
                    //   - value is not type System.SByte, System.Int16, System.Int32, System.Int64, System.Byte, System.UInt16, System.UInt32, or System.UInt64, or System.String.
                    (ex is InvalidOperationException))
                {
                    if (conversionObserver != null)
                    {
                        conversionObserver.NotifyCaughtConversionException(
                            value: value,
                            targetType: targetType,
                            defaultTargetValue: targetDefaultValue,
                            format: format,
                            conversionException: ex);
                    }
                }
                else
                {
                    throw;
                }
            }

            return(converted);
        }
Example #22
0
            public void ConvertObject_RTypeMismatch_ReturnNull()
            {
                int cacheItem = 10;

                Assert.Throws <InvalidCastException>(() => GenericConverter.ConvertObject <TestClass>(cacheItem));
            }
Example #23
0
            public void ConvertObject_VTypeMismatch_ThrowsException()
            {
                TestClass cacheItem = new TestClass();

                Assert.Throws <InvalidCastException>(() => GenericConverter.ConvertObject <int>(cacheItem));
            }