本文整理汇总了C#中Type.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Equals方法的具体用法?C# Type.Equals怎么用?C# Type.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFormat
public object GetFormat(Type formatType)
{
if (formatType.Equals(typeof(TestFormatProvider)))
{
return this;
}
else
{
return null;
}
}
示例2: Initialize
public override void Initialize(Type toolType)
{
if (!toolType.Equals(typeof(Control2)))
{
throw new ArgumentException(
string.Format(CultureInfo.CurrentCulture,
"The {0} constructor argument must be of type {1}.",
this.GetType().FullName, typeof(Control2).FullName));
}
base.Initialize(toolType);
}
示例3: ConvertTo
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (!destinationType.Equals(typeof(String)))
{
throw new ArgumentException("Can only convert to string.", "destinationType");
}
if (!value.GetType().BaseType.Equals(typeof(Enum)))
{
throw new ArgumentException("Can only convert an instance of enum.", "value");
}
string name = value.ToString();
object[] attrs =
value.GetType().GetField(name).GetCustomAttributes(typeof(DescriptionAttribute), false);
return (attrs.Length > 0) ? ((DescriptionAttribute)attrs[0]).Description : name;
}
示例4: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Fx.Assert(targetType.Equals(typeof(string)), "TypeToStringValueConverter cannot convert a type to type " + targetType.FullName);
string target = null;
if (value != null)
{
Fx.Assert(value is Type, string.Format(CultureInfo.InvariantCulture, "TypeToStringValueConverter cannot convert from type {0} to string", value.GetType().FullName));
Type editedType = (Type)value;
//handle primitive types
if (editedType.IsPrimitive || editedType.IsValueType ||
editedType == typeof(string) || editedType == typeof(object))
{
target = editedType.Name;
}
//and other ones
else
{
target = editedType.FullName;
}
}
return target;
}
示例5: ConvertBack
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
Fx.Assert(targetType.Equals(typeof(Type)), "TypeToStringValueConverter cannot convert string back to type " + targetType.FullName);
Type target = null;
string stringValue = value as string;
if (!string.IsNullOrEmpty(stringValue))
{
// try to get the type from the type name
target = Type.GetType(stringValue, false, true);
//handle primitive types
if (null == target)
{
stringValue = string.Format(CultureInfo.InvariantCulture, "System.{0}", stringValue);
target = Type.GetType(stringValue, false, true);
}
if (null == target)
{
return Binding.DoNothing;
}
}
return target;
}
示例6: GetEntityName
/// <summary>
/// Gets the name of the entity.
/// </summary>
/// <param name="entityType">Type of the entity.</param>
/// <returns></returns>
protected string GetEntityName(Type entityType)
{
string name = entityType.Name;
if (entityType.Equals(typeof(ILead)))
return "Lead";
if (entityType.Equals(typeof(IContact)))
return "Contact";
return entityType.Name;
}
示例7: ValidatePropertyType
protected void ValidatePropertyType (string propertyName, object value, Type expectedType, bool allowNull)
{
if (!allowNull && (value == null))
throw new ArgumentNullException ("value");
if ((value != null) && !expectedType.Equals (value.GetType ())) {
string msg = Locale.GetText ("Type mismatch between value ({0}) and expected type ({1}).",
value.GetType (), expectedType);
throw new ArgumentException (msg, "value");
}
}
示例8: CanConvertFrom
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return (sourceType.Equals(typeof(Enum)));
}
示例9: IsDefined
public override bool IsDefined(Type type, bool inherit) {
GlobalLog.Print("MyMethodInfo::IsDefined() type:" + type.FullName + " inherit:" + inherit);
return type.Equals(typeof(WebProxyScriptHelper));
}
示例10: IsBindableType
// see: DataBoundControlHelper.IsBindableType
private static bool IsBindableType(Type type) {
Debug.Assert(type != null);
Type underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType != null) {
type = underlyingType;
}
return (type.IsPrimitive ||
type.Equals(typeof(string)) ||
type.Equals(typeof(DateTime)) ||
type.Equals(typeof(Decimal)) ||
type.Equals(typeof(Guid)) ||
type.Equals(typeof(DateTimeOffset)) ||
type.Equals(typeof(TimeSpan)));
}
示例11: TestParse_Invalid
public static void TestParse_Invalid(string input, Type exceptionType)
{
// Overflow exceptions throw as format exceptions in Parse
if (exceptionType.Equals(typeof(OverflowException)))
{
exceptionType = typeof(FormatException);
}
Assert.Throws(exceptionType, () => Guid.Parse(input));
Assert.Throws(exceptionType, () => Guid.ParseExact(input, "N"));
Assert.Throws(exceptionType, () => Guid.ParseExact(input, "D"));
Assert.Throws(exceptionType, () => Guid.ParseExact(input, "B"));
Assert.Throws(exceptionType, () => Guid.ParseExact(input, "P"));
Assert.Throws(exceptionType, () => Guid.ParseExact(input, "X"));
Guid result;
Assert.False(Guid.TryParse(input, out result));
Assert.Equal(Guid.Empty, result);
Assert.False(Guid.TryParseExact(input, "N", out result));
Assert.Equal(Guid.Empty, result);
Assert.False(Guid.TryParseExact(input, "D", out result));
Assert.Equal(Guid.Empty, result);
Assert.False(Guid.TryParseExact(input, "B", out result));
Assert.Equal(Guid.Empty, result);
Assert.False(Guid.TryParseExact(input, "P", out result));
Assert.Equal(Guid.Empty, result);
Assert.False(Guid.TryParseExact(input, "X", out result));
Assert.Equal(Guid.Empty, result);
}
示例12: CheckIsAssignableFrom
private static void CheckIsAssignableFrom(ExecutionEnvironment executionEnvironment, Type dstType, Type srcType)
{
// byref types do not have a TypeHandle so we must treat these separately.
if (dstType.IsByRef && srcType.IsByRef)
{
if (!dstType.Equals(srcType))
throw new ArgumentException(SR.Arg_DlgtTargMeth);
}
// Enable pointers (which don't necessarily have typehandles). todo:be able to handle intptr <-> pointer, check if we need to handle
// casts via pointer where the pointer types aren't identical
if (dstType.Equals(srcType))
{
return;
}
// If assignment compatible in the normal way, allow
if (executionEnvironment.IsAssignableFrom(dstType.TypeHandle, srcType.TypeHandle))
{
return;
}
// they are not compatible yet enums can go into each other if their underlying element type is the same
// or into their equivalent integral type
Type dstTypeUnderlying = dstType;
if (dstType.GetTypeInfo().IsEnum)
{
dstTypeUnderlying = Enum.GetUnderlyingType(dstType);
}
Type srcTypeUnderlying = srcType;
if (srcType.GetTypeInfo().IsEnum)
{
srcTypeUnderlying = Enum.GetUnderlyingType(srcType);
}
if (dstTypeUnderlying.Equals(srcTypeUnderlying))
{
return;
}
throw new ArgumentException(SR.Arg_DlgtTargMeth);
}
示例13: ValueToObject
private static object ValueToObject(Task task, Type type, object obj)
{
if (type.IsPrimitive || type.Equals(typeof(string)))
{
return Convert.ChangeType(obj, type);
}
return null;
}
示例14: testS1
//.........这里部分代码省略.........
S1.create2(new Context(Context.test_kind.NO_FACTORY));
} catch (ucss.uno.DeploymentException e) {
l.assure(e.Message.Length > 0);
} catch (System.Exception) {
l.assure(false);
}
/* When the service manager returns a null pointer then a DeploymentException
* is to be thrown.
*/
try {
S1.create2(new Context(Context.test_kind.CREATION_FAILED));
} catch (ucss.uno.DeploymentException e) {
l.assure(e.Message.Length > 0);
} catch (System.Exception) {
l.assure(false);
}
/** Test creation of components and if the passing of parameters works.
*/
c = new Context(Context.test_kind.NORMAL);
try {
XTest xTest = S1.create1(c);
Component cobj = (Component) xTest;
l.assure(cobj.Args[0].Value == c);
Any a1 = new Any("bla");
Any a2 = new Any(3.14f);
Any a3 = new Any(3.145d);
xTest = S1.create2(c, a1, a2, a3);
cobj = (Component) xTest;
l.assure(cobj.Args[0].Value == c
&& a1.Equals(cobj.Args[1])
&& a2.Equals(cobj.Args[2])
&& a3.Equals(cobj.Args[3]));
bool b1 = true;
byte b2 = 1;
short b3 = 2;
ushort b4 = 3;
int b5 = 4;
uint b6 = 5;
long b7 = 6;
ulong b8 = 7;
float b9 = 0.8f;
double b10 = 0.9;
char b11 = 'A';
string b12 = "BCD";
Type b13 = typeof(ulong);
Any b14 = new Any(22);
Enum2 b15 = Enum2.VALUE4;
Struct1 b16 = new Struct1(1);
PolyStruct b17 = new PolyStruct('A', 1);
PolyStruct b18 = new PolyStruct(new Any(true), 1);
object b19 = new uno.util.WeakComponentBase();
ucss.lang.XComponent b20 = (ucss.lang.XComponent) b19;
bool b21 = b1;
byte b22 = b2;
short b23 = b3;
ushort b24 = b4;
int b25 = b5;
uint b26 = b6;
long b27 = b7;
ulong b28 = b8;
float b29 = b9;
示例15: CanConvertTo
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return (destinationType.Equals(typeof(String)));
}