當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。