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


C# Type.Equals方法代码示例

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


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

示例1: getAppSetting

        private static object getAppSetting(Type expectedType, string key)
        {
            string value = ConfigurationManager.AppSettings.Get(key);
            if (value == null)
            {
                Log.Fatal("Configuration.cs", string.Format("AppSetting: {0} is not configured", key));
                throw new Exception(string.Format("AppSetting: {0} is not configured.", key));
            }

            try
            {
                if (expectedType.Equals(typeof(int)))
                {
                    return int.Parse(value);
                }

                if (expectedType.Equals(typeof(string)))
                {
                    return value;
                }

                throw new Exception("Type not supported.");
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Config key:{0} was expected to be of type {1} but was not.", key, expectedType),
                                    ex);
            }
        }
开发者ID:lengocluyen,项目名称:internetpark,代码行数:29,代码来源:Configuration.cs

示例2: Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is BinomialNonInferiorityTesting == false)
            {
                throw new NotImplementedException();
            }

            if (targetType.Equals(typeof(IEnumerable)))
            {
                var values = new List<string>
                             {
                             	Superiority,
                                SuperiorityWithMargin,
                             };

                return values;
            }

            if (targetType.Equals(typeof(object)) || targetType.Equals(typeof(string)))
            {
                var binomialTesting = (BinomialNonInferiorityTesting)value;
                switch (binomialTesting)
                {
                    case BinomialNonInferiorityTesting.Superiority:
                        return Superiority;

                    case BinomialNonInferiorityTesting.SuperiorityWithMargin:
                        return SuperiorityWithMargin;
                }

                return binomialTesting.ToString();
            }

            throw new NotImplementedException("Unhandled targetType: " + targetType);
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:35,代码来源:BinomialNonInferiorityTestingValueConverter.cs

示例3: Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TimeToEventSpecification == false)
            {
                throw new NotImplementedException();
            }

            if (targetType.Equals(typeof(IEnumerable)))
            {
                var values = new List<string>
                             {
                             	EventRate,
                                MedianTime,
                             };

                return values;
            }

            if (targetType.Equals(typeof(object)) || targetType.Equals(typeof(string)))
            {
                var specification = (TimeToEventSpecification)value;
                switch (specification)
                {
                    case TimeToEventSpecification.EventRate:
                        return EventRate;

                    case TimeToEventSpecification.MedianTime:
                        return MedianTime;
                }

                return specification.ToString();
            }

            throw new NotImplementedException("Unhandled targetType: " + targetType);
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:35,代码来源:TimeToEventSpecificationValueConverter.cs

示例4: GetService

        public object GetService(Type serviceType)
        {
            _log.Debug("VerboseDependencyResolver.GetService(Type serviceType), serviceType: " + serviceType.ToString());

            if(serviceType.Equals(typeof(IControllerFactory)))
            {
                // Cannot return controller here, as it is also set via
                // ControllerBuilder.Current.SetControllerFactory.
                //return new VerboseControllerFactory();
                _log.Debug("VerboseDependencyResolver.GetService(Type serviceType) returning null.");
                return null;
            }

            if (serviceType.Equals(typeof(IControllerActivator)))
            {
                _log.Debug("VerboseDependencyResolver.GetService(Type serviceType) returning null.");
                return null;
            }

            if (typeof(IController).IsAssignableFrom(serviceType))
            {
                _log.Debug("VerboseDependencyResolver.GetService(Type serviceType) returning instance of HomeController.");
                return new HomeController();
            }

            _log.Debug("VerboseDependencyResolver.GetService(Type serviceType) returning null.");
            return null;
        }
开发者ID:jacekdalkowski,项目名称:asp-net-mvc-request-lifecycle,代码行数:28,代码来源:VerboseDependencyResolver.cs

示例5: GetObjectValue

        private static object GetObjectValue (string value, Type type)
        {
            if (type.IsEnum)
            {
                return GetEnumValue (type, value);
            }

            if (type.Equals ((typeof(bool))))
            {
                return GetBooleanValue (value);
            }

            if (type.Equals (typeof(DateTime)))
            {
                return GetDateTimeValue (value);
            }

            if (typeof(IConvertible).IsAssignableFrom (type))
            {
                return GetConvertibleValue (type, value);
            }

            string message = String.Format ("Unsupported type being used with NullableResolver: [{0}]", type.Name);
            throw new Exception(message);
        }
开发者ID:aqueduct,项目名称:Aqueduct.SitecoreLib,代码行数:25,代码来源:NullableResolver.cs

示例6: ConvertToType

        /// <summary>
        /// Converts the specified value to a value that fits the target type.
        /// </summary>
        /// <param name="targetType">The target <see cref="Type"/>.</param>
        /// <param name="value">The value to convert.</param>
        /// <returns>The converted value.</returns>
        static object ConvertToType(Type targetType, object value)
        {
            if (targetType.IsAssignableFrom(value.GetType()))
                return value;

            if (targetType.IsEnum)
            {
                if (!Enum.IsDefined(targetType, value.ToString()))
                    throw new ScriptException(string.Format("The value '{0}' is not a member of {1}.", value, targetType));

                return Enum.Parse(targetType, value.ToString(), true);
            }

            if (targetType.Equals(typeof(byte)))
                return Convert.ToByte(value);
            if (targetType.Equals(typeof(sbyte)))
                return Convert.ToSByte(value);
            if (targetType.Equals(typeof(short)))
                return Convert.ToInt16(value);
            if (targetType.Equals(typeof(ushort)))
                return Convert.ToUInt16(value);
            if (targetType.Equals(typeof(int)))
                return Convert.ToInt32(value);
            if (targetType.Equals(typeof(uint)))
                return Convert.ToUInt32(value);
            if (targetType.Equals(typeof(long)))
                return Convert.ToInt64(value);
            if (targetType.Equals(typeof(ulong)))
                return Convert.ToUInt64(value);

            throw new ScriptException(string.Format("Could not convert from {0} to {1}.", value.GetType(), targetType));
        }
开发者ID:Konctantin,项目名称:SharpAssembler,代码行数:38,代码来源:Annotation.cs

示例7: ApplyToFieldInfo

 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(byte[])))
         Info.SetValue(Packet, val);
     else if(Field.Equals(typeof(string)))
         Info.SetValue(Packet,Marshal.ConvertToString((byte[])val));
 }
开发者ID:Easun,项目名称:RiftEMU,代码行数:7,代码来源:ArrayBit.cs

示例8: ApplyToFieldInfo

        public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
        {
            if (Field.Equals(typeof(List<uint>)))
            {
                List<uint> Luint = new List<uint>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Luint.Add(Value.GetUint());
                Info.SetValue(Packet, Luint);
            }
            else if(Field.Equals(typeof(List<ISerializablePacket>)))
            {
                List<ISerializablePacket> Packets = new List<ISerializablePacket>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Packets.Add(Value.GetPacket());
                Info.SetValue(Packet, Packets);
            }
            else if (Field.Equals(typeof(List<bool>)))
            {
                List<bool> Bools = new List<bool>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    Bools.Add((bool)Value.val);
                Info.SetValue(Packet, Bools);
            }
            else if (Field.Equals(typeof(List<float>)))
            {
                List<float> floats = new List<float>();
                foreach (ISerializableField Value in (List<ISerializableField>)val)
                    floats.Add(Value.GetFloat());

                Info.SetValue(Packet, floats);
            }
        }
开发者ID:Easun,项目名称:ChameleonProject,代码行数:32,代码来源:ListBit.cs

示例9: Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TimeToEventHypothesis == false)
            {
                throw new NotImplementedException();
            }

            if (targetType.Equals(typeof(IEnumerable)))
            {
                var values = new List<string>
                             {
                             	RiskRatio,
                                RiskDifference,
                             };

                return values;
            }

            if (targetType.Equals(typeof(object)) || targetType.Equals(typeof(string)))
            {
                var binomialTesting = (TimeToEventHypothesis)value;
                switch (binomialTesting)
                {
                    case TimeToEventHypothesis.RiskRatio:
                        return RiskRatio;

                    case TimeToEventHypothesis.RiskDifference:
                        return RiskDifference;
                }

                return binomialTesting.ToString();
            }

            throw new NotImplementedException("Unhandled targetType: " + targetType);
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:35,代码来源:TimeToEventHypothesisValueConverter.cs

示例10: Distance

		private int Distance (Type type_a, Type type_b) {
			if (type_a.Equals (type_b))
				return 0;

			if (type_a.IsPrimitive && type_b.IsPrimitive &&
				 CanConvertPrimitive (type_a, type_b)) {
				return 1;
			}
			
			int class_distance = 1;
			Type base_a = type_a.BaseType;
			while (base_a != null && !(base_a.Equals (typeof (object)))) {
				if (type_b.Equals (base_a))
					break;

				// FIXME: this needs to check which interfaces bind tighter
				Type[] interfaces = base_a.GetInterfaces ();
				foreach (Type iface in interfaces) {
					if (type_b.Equals (iface))
						return 1;
				}

				class_distance++;
				base_a = base_a.BaseType;
			}

			if (base_a == null || !(type_b.Equals (base_a))) {
				class_distance = -1;
			}

			return class_distance;
		}
开发者ID:emtees,项目名称:old-code,代码行数:32,代码来源:LogoBinder.cs

示例11: Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is TimeToEventAccrual == false)
            {
                throw new NotImplementedException();
            }

            if (targetType.Equals(typeof(IEnumerable)))
            {
                var values = new List<string>
                             {
                             	Uniform,
                                Exponential,
                             };

                return values;
            }

            if (targetType.Equals(typeof(object)) || targetType.Equals(typeof(string)))
            {
                var binomialTesting = (TimeToEventAccrual)value;
                switch (binomialTesting)
                {
                    case TimeToEventAccrual.Uniform:
                        return Uniform;

                    case TimeToEventAccrual.Exponential:
                        return Exponential;
                }

                return binomialTesting.ToString();
            }

            throw new NotImplementedException("Unhandled targetType: " + targetType);
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:35,代码来源:TimeToEventAccrualValueConverter.cs

示例12: GetConverter

        public static Func<string, object> GetConverter(Type valueType)
        {
            if(valueType.Equals(typeof(string)))
            {
                return (s) => s;
            }
            if(valueType.Equals(typeof(int)))
            {
                return (s) => int.Parse(s);
            }
            else if(valueType.Equals(typeof(float)))
            {
                return (s) => float.Parse(s, CultureInfo.InvariantCulture.NumberFormat);
            }
            else if (valueType.Equals(typeof(double)))
            {
                return (s) => double.Parse(s, CultureInfo.InvariantCulture.NumberFormat);
            }
            else if(valueType.Equals(typeof(bool)))
            {
                return (s) => "true".Equals(s);
            }
            else if(valueType.IsEnum)
            {
                return (s) => Enum.Parse(valueType, s);
            }

            throw new NotImplementedException("Cannot create converter for " + valueType);
        }
开发者ID:3DI70R,项目名称:SpeechSequencerCore,代码行数:29,代码来源:ValueBinder.cs

示例13: GetService

 /// <summary>
 /// Gets the service object of the specified type.
 /// </summary>
 /// <param name="serviceType">An object that specifies the type of service object to get.</param>
 /// <returns>
 /// A service object of type serviceType.-or- null if there is no service object of type serviceType.
 /// </returns>
 public override object GetService(Type serviceType) {
   if (serviceType.Equals(typeof(IMouseListener)))
     return this;
   else if (serviceType.Equals(typeof(IHoverListener)))
     return this;
   else
     return null;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:15,代码来源:ClickableIconMaterial.cs

示例14: Convert

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;

            if (!value.GetType().Equals(typeof (PlotType))) throw new ArgumentException();

            if (targetType.Equals(typeof (int))) return (int) (PlotType) value;

            if (targetType.Equals(typeof (object)) || targetType.Equals(typeof (string)))
            {
                var s = (PlotType) value;
                switch (s)
                {
                    case PlotType.Boundaries:
                        return Boundaries;

                    case PlotType.Power:
                        return Power;

                    case PlotType.TreatmentEffect:
                        return TreatmentEffect;

                    case PlotType.ConditionalPower:
                        return ConditionalPower;

                    case PlotType.SpendingFunction:
                        return SpendingFunction;

                    case PlotType.ExpectedSampleSize:
                        return ExpectedSampleSize;

                    case PlotType.BValues:
                        return BValues;

                    default:
                        return s.ToString();
                }
            }

            if (targetType.Equals(typeof (IEnumerable)))
            {
                var values = new List<string>
                {
                    Boundaries,
                    Power,
                    TreatmentEffect,
                    ConditionalPower,
                    SpendingFunction,
                    ExpectedSampleSize,
                    BValues,
                };

                return values;
            }

            throw new NotImplementedException();
        }
开发者ID:subfuzion,项目名称:gsDesign,代码行数:57,代码来源:PlotTypeValueConverter.cs

示例15: CanConvertTo

        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType == null) { throw new ArgumentNullException("destinationType"); } // $NON-NLS-1
            if (destinationType.Equals(typeof(string))
                || destinationType.Equals(typeof(Uri)))
                return true;

            return base.CanConvertTo(context, destinationType);
        }
开发者ID:Carbonfrost,项目名称:ff-foundations-runtime,代码行数:9,代码来源:StreamContextConverter.cs


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