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


C# IComparable.ToString方法代码示例

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


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

示例1: Compare

        /// <summary>
        ///   The following method compares any 2 objects and test if they are equal.
        ///   It will also compare equality of numbers in a very special way.
        ///   Examples:
        ///   IsEqual(Int64.MaxValue, Int64.MaxValue) //is true
        ///   IsEqual(Int64.MaxValue, Int64.MaxValue-1) //is false
        ///   IsEqual(123, 123.0) //is true
        ///   IsEqual(654f, 654d) //is true
        /// </summary>
        internal static int Compare(IComparable a, IComparable b)
        {
            if (IsNumber(a) && IsNumber(b))
            {
                if (IsFloatingPoint(a) || IsFloatingPoint(b))
                {
                    double da, db;
                    if (Double.TryParse(a.ToString(), out da) && Double.TryParse(b.ToString(), out db))
                        return da.CompareTo(db);
                }
                else
                {
                    if (a.ToString().StartsWith("-") || b.ToString().StartsWith("-"))
                    {
                        var a1 = Convert.ToInt64(a);
                        var b1 = Convert.ToInt64(b);
                        
                        return a1.CompareTo(b1);
                    }
                    else
                    {
                        var a1 = Convert.ToUInt64(a);
                        var b1 = Convert.ToUInt64(b);

                        return a1.CompareTo(b1);
                    }
                }
            }

            return a.CompareTo(b);
        }
开发者ID:spolnik,项目名称:ndatabase,代码行数:40,代码来源:AttributeValueComparator.cs

示例2: FormatCursorLabel

        /// <summary>
        /// Formats a label for the cursor, from the specified data-value passed in
        /// </summary>
        /// <param name="dataValue">The data-value to format</param>
        /// <returns>
        /// The formatted cursor label string
        /// </returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override string FormatCursorLabel(IComparable dataValue)
        {
            //int index = (int)Convert.ChangeType(dataValue, typeof(int));
            //if (index >= 0 && index < _xLabels.Length)
            //    return _xLabels[index];

            //return index.ToString();
            try
            {
                if (dataValue is double)
                {
                    return formatter.displayPrice((double)dataValue);
                }
                else if (dataValue == null)
                {
                    return string.Empty;
                }
                else
                {
                    return dataValue.ToString();
                }
            }
            catch (Exception err)
            {
                Alerting.Alert.LoggerHome.GetLogger(this).Error("Error in CustomLabelFormatter::FormatCursorLabel ", err);
                return string.Empty;
            }
        }
开发者ID:tanveeransari,项目名称:Migration,代码行数:36,代码来源:CustomLabelFormatter.cs

示例3: Compare

		internal static int Compare (IComparable o1, IComparable o2, bool caseSensitive)
		{
			//TODO: turn this "conversion pipeline" into something nicer

			try {
				if (o1 is string && Numeric.IsNumeric (o2))
					o1 = (IComparable) Convert.ChangeType (o1, o2.GetType ());
				else if (o2 is string && Numeric.IsNumeric (o1))
					o2 = (IComparable) Convert.ChangeType (o2, o1.GetType ());
				else if (o1 is string && o2 is Guid)
					o2 = o2.ToString ();
				else if (o2 is string && o1 is Guid)
					o1 = o1.ToString ();
			} catch (FormatException) {
				throw new EvaluateException (String.Format ("Cannot perform compare operation on {0} and {1}.", o1.GetType(), o2.GetType()));
			}

			if (o1 is string && o2 is string && !caseSensitive) {
				o1 = ((string)o1).ToLower();
				o2 = ((string)o2).ToLower();
			}
			
			if (o1.GetType () != o2.GetType ())
				o2 = (IComparable)Convert.ChangeType (o2, o1.GetType ());

			return o1.CompareTo (o2);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:27,代码来源:Comparison.cs

示例4: NotEquals

 public static void NotEquals(IComparable a, IComparable b, string message=null) {
     if(a == null)
         throw new AssertFailedException("a is null");
     if(b==null)
         throw new AssertFailedException("b is null");
     if(a.CompareTo(b) == 0)
         throw new AssertFailedException(String.IsNullOrEmpty(message) ? a.ToString() + " == " + b.ToString() : message);
 }
开发者ID:maka-io,项目名称:netcdf4.net,代码行数:8,代码来源:Assert.cs

示例5: Range

 /// <summary>
 /// Initializes a new instance of the <see cref="Range"/> class. 
 /// Creates an instance of the rule.
 /// </summary>
 /// <param name="primaryProperty">
 /// Property to which the rule applies.
 /// </param>
 /// <param name="min">
 /// Min value.
 /// </param>
 /// <param name="max">
 /// Max value.
 /// </param>
 public Range(IPropertyInfo primaryProperty, IComparable min, IComparable max)
   : base(primaryProperty)
 {
   Max = max;
   Min = min;
   RuleUri.AddQueryParameter("max", max.ToString());
   RuleUri.AddQueryParameter("min", min.ToString());
   InputProperties = new List<IPropertyInfo> { primaryProperty };
 }
开发者ID:nschonni,项目名称:csla-svn,代码行数:22,代码来源:Range.cs

示例6: FindPrev

 public KeyValuePair<RecordKey, RecordUpdate> FindPrev(IComparable<RecordKey> keytest, bool equal_ok)
 {
     FindRecordResult result = _findRecord(keytest, !equal_ok);
     if (result.before_keytest.have_record) {
         return result.before_keytest.record;
     } else {
         throw new KeyNotFoundException("SegmentBlockBasic: failed to find match : " + keytest.ToString());
     }
 }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:9,代码来源:SegmentBlockBasic.cs

示例7: FormatLabel

 public override string FormatLabel(IComparable dataValue)
 {
     try
     {
         return base.FormatLabel(dataValue);
     }
     catch (Exception err)
     {
         LoggerHome.GetLogger(this).Error("Error in CustomDateLabelFormatter::FormatLabel " + dataValue.ToString(), err);
         return string.Empty;
     }
 }
开发者ID:tanveeransari,项目名称:Migration,代码行数:12,代码来源:CustomDateTimeLabelFormatter.cs

示例8: FormatLabel

        public override string FormatLabel(IComparable dataValue)
        {
            try
            {
                DateTime sTemp = (DateTime)dataValue;

                return sTemp.ToShortDateString();
            }
            catch (Exception err)
            {
                LoggerHome.GetLogger(this).Error("Error in CustomDateLabelFormatter::FormatLabel " + dataValue.ToString(), err);
                return string.Empty;
            }
        }
开发者ID:tanveeransari,项目名称:Migration,代码行数:14,代码来源:CustomDateLabelFormatter.cs

示例9: Compare

		internal static int Compare (IComparable o1, IComparable o2, bool caseSensitive)
		{
			//TODO: turn this "conversion pipeline" into something nicer

			try {
				if (o1 is string && Numeric.IsNumeric (o2))
					o1 = (IComparable) Convert.ChangeType (o1, o2.GetType ());
				else if (o2 is string && Numeric.IsNumeric (o1))
					o2 = (IComparable) Convert.ChangeType (o2, o1.GetType ());
				else if (o1 is string && o2 is Guid)
					o2 = o2.ToString ();
				else if (o2 is string && o1 is Guid)
					o1 = o1.ToString ();
			} catch (FormatException) {
				throw new EvaluateException (String.Format ("Cannot perform compare operation on {0} and {1}.", o1.GetType(), o2.GetType()));
			}

			if (o1 is string && o2 is string) {
				o1 = ((string) o1).TrimEnd (IgnoredTrailingChars);
				o2 = ((string) o2).TrimEnd (IgnoredTrailingChars);
				if (!caseSensitive) {
					o1 = ((string) o1).ToLower ();
					o2 = ((string) o2).ToLower ();
				}
			}

			if (o1 is DateTime && o2 is string && Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture) {
				// DateTime is always CultureInfo.InvariantCulture
				o2 = (IComparable) DateTime.Parse ((string)o2, CultureInfo.InvariantCulture);
			} else if (o2 is DateTime && o1 is string && 
			           Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture) {
				// DateTime is always CultureInfo.InvariantCulture
                o1 = (IComparable) DateTime.Parse ((string)o1, CultureInfo.InvariantCulture);
			}
			else if (o2 is DateTime && o1 is string && Thread.CurrentThread.CurrentCulture != CultureInfo.InvariantCulture) {
				// DateTime is always CultureInfo.InvariantCulture
				o1 = (IComparable) DateTime.Parse ((string)o1, CultureInfo.InvariantCulture);
			}

			if (o1.GetType () != o2.GetType ())
				o2 = (IComparable)Convert.ChangeType (o2, o1.GetType ());

			return o1.CompareTo (o2);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:44,代码来源:Comparison.cs

示例10: AssertRangeAttribute

 /// <summary>
 /// <para>Initialzie a new instance of the <see cref="AssertRangeAttribute"/> class with an <see cref="IComparable"/> lower and upper bounds.</para>
 /// </summary>
 /// <param name="lowerBound">
 /// <para>The lower bound of the range.</para>
 /// </param>
 /// <param name="lowerBoundType">
 /// <para>One of the <see cref="RangeBoundaryType"/> values.</para>
 /// </param>
 /// <param name="upperBound">
 /// <para>The lower bound of the range.</para>
 /// </param>
 /// <param name="upperBoundType">
 /// <para>One of the <see cref="RangeBoundaryType"/> values.</para>
 /// </param>
 protected AssertRangeAttribute(IComparable lowerBound, RangeBoundaryType lowerBoundType, IComparable upperBound, RangeBoundaryType upperBoundType)
 {
     if (lowerBound.CompareTo(upperBound) > 0)
     {
         throw new ArgumentOutOfRangeException("lowerBound", SR.ExceptionLowerBoundOutOfRange(lowerBound.ToString(), upperBound.ToString()));
     }
     this.lowerBound = lowerBound;
     this.lowerBoundType = lowerBoundType;
     this.upperBound = upperBound;
     this.upperBoundType = upperBoundType;
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:26,代码来源:AssertRangeAttribute.cs

示例11: CoerceTypes

 private static IComparable CoerceTypes(IComparable value, HeaderType type)
 {
     if (type == HeaderType.Numeric) {
         string valueString = value.ToString();
         double dblVal;
         if (double.TryParse(valueString, NumberStyles.Any, CultureInfo.InvariantCulture, out dblVal)) {
             return dblVal;
         }
         return (double)-127;
     } else if (type == HeaderType.String) {
         return value.ToString();
     }
     return value;
 }
开发者ID:TheSumm,项目名称:Tibialyzer,代码行数:14,代码来源:MainForm.cs

示例12: NotifyAsynchronousSubscribers

 internal void NotifyAsynchronousSubscribers(IComparable queueName, EventQueueState qState, int numberOfNotification)
 {
     for (int i = 0; i < numberOfNotification; ++i)
     {
         QueueEventArgs args = new QueueEventArgs(queueName);
         lock (SyncRoot)
         {
             foreach (ActivityExecutorDelegateInfo<QueueEventArgs> subscriber in qState.AsynchronousListeners)
             {
                 Activity contextActivity = rootWorkflowExecutor.GetContextActivityForId(subscriber.ContextId);
                 Debug.Assert(contextActivity != null);
                 subscriber.InvokeDelegate(contextActivity, args, false);
                 WorkflowTrace.Runtime.TraceInformation("Queuing Service: Notifying async subscriber on queue:'{0}' activity:{1}", queueName.ToString(), subscriber.ActivityQualifiedName);
             }
         }
     }
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:17,代码来源:WorkflowQueuingService.cs

示例13: GetUniqueId

 private string GetUniqueId(IComparable p)
 {
     string id;
     do
         id = p.ToString() + idCounter++;
     while (graph.FindNodeByUserData(id) != null);
     return id;
 }
开发者ID:mrkcass,项目名称:SuffixTreeExplorer,代码行数:8,代码来源:LocationLabeler.cs

示例14: WriteFloat

 private static void WriteFloat(XmlTextWriter writer, string name, IComparable<float> value)
 {
     writer.WriteElementString(name, value.ToString());
 }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:4,代码来源:OarFile.cs

示例15: QueueAsynchronousEvent

 private bool QueueAsynchronousEvent(IComparable queueName, EventQueueState qState)
 {
     if (qState.AsynchronousListeners.Count != 0 || IsNestedListenersExist(queueName))
     {
         Queue q = GetQueue(pendingNotification).Messages;
         q.Enqueue(new KeyValuePair<IComparable, EventQueueState>(queueName, qState));
         WorkflowTrace.Runtime.TraceInformation("Queuing Service: Queued delayed message notification for '{0}'", queueName.ToString());
         return q.Count == 1;
     }
     return false;
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:11,代码来源:WorkflowQueuingService.cs


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