本文整理汇总了C#中IKVM.Reflection.Type类的典型用法代码示例。如果您正苦于以下问题:C# Type类的具体用法?C# Type怎么用?C# Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于IKVM.Reflection命名空间,在下文中一共展示了Type类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HasCast
private static bool HasCast(Type type, Type from, Type to, out MethodInfo op)
{
#if WINRT
System.Collections.Generic.List<MethodInfo> list = new System.Collections.Generic.List<MethodInfo>();
foreach (var item in type.GetRuntimeMethods())
{
if (item.IsStatic) list.Add(item);
}
MethodInfo[] found = list.ToArray();
#else
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo[] found = type.GetMethods(flags);
#endif
for(int i = 0 ; i < found.Length ; i++)
{
MethodInfo m = found[i];
if ((m.Name != "op_Implicit" && m.Name != "op_Explicit") || m.ReturnType != to)
{
continue;
}
ParameterInfo[] paramTypes = m.GetParameters();
if(paramTypes.Length == 1 && paramTypes[0].ParameterType == from)
{
op = m;
return true;
}
}
op = null;
return false;
}
开发者ID:baojiangtao,项目名称:CrazySlug,代码行数:30,代码来源:SurrogateSerializer.cs
示例2: ConversationWrapper
public ConversationWrapper(Conversion conv, Operand op, Type @from, Type to)
{
_conv = conv;
_op = op;
_to = to;
_from = @from;
}
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:7,代码来源:ConversationWrapper.cs
示例3: Read
public override object Read(Type useType, object value, ProtoReader source)
{
Helpers.DebugAssert(fieldNumber == source.FieldNumber);
if (strict) { source.Assert(wireType); }
else if (NeedsHint) { source.Hint(wireType); }
return Tail.Read(useType,value, source);
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:7,代码来源:TagDecorator.cs
示例4: SafeCast
public SafeCast(Operand op, Type t)
{
_op = op;
_t = t;
if (t.IsValueType)
_conditional = _op.Is(_t).Conditional(_op.Cast(_t), new DefaultValue(_t));
}
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:7,代码来源:SafeCast.cs
示例5: Write
public override void Write(Type useType, object value, ProtoWriter dest)
{
if(getSpecified == null || (bool)getSpecified.Invoke(value, null))
{
Tail.Write(useType, value, dest);
}
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:7,代码来源:MemberSpecifiedDecorator.cs
示例6: GetClassLiteralField
internal static FieldInfo GetClassLiteralField(Type type)
{
Debug.Assert(type != Types.Void);
if (classLiteralType == null)
{
#if STATIC_COMPILER
classLiteralType = JVM.CoreAssembly.GetType("ikvm.internal.ClassLiteral`1");
#elif !FIRST_PASS
classLiteralType = typeof([email protected]<>);
#endif
}
#if !STATIC_COMPILER
if (!IsTypeBuilder(type))
{
return classLiteralType.MakeGenericType(type).GetField("Value", BindingFlags.Public | BindingFlags.Static);
}
#endif
if (classLiteralField == null)
{
classLiteralField = classLiteralType.GetField("Value", BindingFlags.Public | BindingFlags.Static);
}
#if !NOEMIT
return TypeBuilder.GetField(classLiteralType.MakeGenericType(type), classLiteralField);
#else
return null;
#endif
}
开发者ID:samskivert,项目名称:ikvm-monotouch,代码行数:27,代码来源:RuntimeHelperTypes.cs
示例7: EventGen
internal EventGen(TypeGen owner, string name, Type type, MethodAttributes mthAttr)
{
_owner = owner;
Name = name;
_type = type;
_attrs = mthAttr;
}
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:7,代码来源:EventGen.cs
示例8: TryCreate
public static ParseableSerializer TryCreate(Type type, TypeModel model)
{
if (type == null) throw new ArgumentNullException("type");
#if WINRT || PORTABLE || COREFX
MethodInfo method = null;
#if WINRT || COREFX
foreach (MethodInfo tmp in type.GetTypeInfo().GetDeclaredMethods("Parse"))
#else
foreach (MethodInfo tmp in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
#endif
{
ParameterInfo[] p;
if (tmp.Name == "Parse" && tmp.IsPublic && tmp.IsStatic && tmp.DeclaringType == type && (p = tmp.GetParameters()) != null && p.Length == 1 && p[0].ParameterType == typeof(string))
{
method = tmp;
break;
}
}
#else
MethodInfo method = type.GetMethod("Parse",
BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly,
null, new Type[] { model.MapType(typeof(string)) }, null);
#endif
if (method != null && method.ReturnType == type)
{
if (Helpers.IsValueType(type))
{
MethodInfo toString = GetCustomToString(type);
if (toString == null || toString.ReturnType != model.MapType(typeof(string))) return null; // need custom ToString, fools
}
return new ParseableSerializer(method);
}
return null;
}
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:35,代码来源:ParseableSerializer.cs
示例9: ResolveIReadOnlyCollection
static Type ResolveIReadOnlyCollection(Type declaredType, Type t)
{
#if WINRT
foreach (Type intImplBasic in declaredType.GetTypeInfo().ImplementedInterfaces)
{
TypeInfo intImpl = intImplBasic.GetTypeInfo();
if (intImpl.IsGenericType && intImpl.Name.StartsWith("IReadOnlyCollection`"))
{
if(t != null)
{
Type[] typeArgs = intImpl.GenericTypeArguments;
if (typeArgs.Length != 1 && typeArgs[0] != t) continue;
}
return intImplBasic;
}
}
#else
foreach (Type intImpl in declaredType.GetInterfaces())
{
if (intImpl.IsGenericType && intImpl.Name.StartsWith("IReadOnlyCollection`"))
{
if(t != null)
{
Type[] typeArgs = intImpl.GetGenericArguments();
if (typeArgs.Length != 1 && typeArgs[0] != t) continue;
}
return intImpl;
}
}
#endif
return null;
}
开发者ID:Erguotou,项目名称:protobuf-net,代码行数:32,代码来源:ImmutableCollectionDecorator.cs
示例10: Read
public override object Read(Type useType, object value, ProtoReader source)
{
Helpers.DebugAssert(value != null);
object newValue = Tail.Read(useType, (Tail.RequiresOldValue ? field.GetValue(value) : null), source);
if(newValue != null) field.SetValue(value,newValue);
return null;
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:7,代码来源:FieldDecorator.cs
示例11: EmitBeq
private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Char:
case ProtoTypeCode.Double:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.Int64:
case ProtoTypeCode.SByte:
case ProtoTypeCode.Single:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
case ProtoTypeCode.UInt64:
ctx.BranchIfEqual(label, false);
break;
default:
MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
null, new Type[] { type, type}, null);
if (method == null || method.ReturnType != ctx.MapType(typeof(bool)))
{
throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
}
ctx.EmitCall(method);
ctx.BranchIfTrue(label, false);
break;
}
}
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:31,代码来源:DefaultValueDecorator.cs
示例12: ArrayDecorator
public ArrayDecorator(TypeModel model, IProtoSerializer tail, int fieldNumber, bool writePacked, WireType packedWireType, Type arrayType, bool overwriteList, bool supportNull)
: base(tail)
{
Helpers.DebugAssert(arrayType != null, "arrayType should be non-null");
Helpers.DebugAssert(arrayType.IsArray && arrayType.GetArrayRank() == 1, "should be single-dimension array; " + arrayType.FullName);
this.itemType = arrayType.GetElementType();
#if NO_GENERICS
Type underlyingItemType = itemType;
#else
Type underlyingItemType = supportNull ? itemType : (Helpers.GetUnderlyingType(itemType) ?? itemType);
#endif
Helpers.DebugAssert(underlyingItemType == Tail.ExpectedType, "invalid tail");
Helpers.DebugAssert(Tail.ExpectedType != model.MapType(typeof(byte)), "Should have used BlobSerializer");
if ((writePacked || packedWireType != WireType.None) && fieldNumber <= 0) throw new ArgumentOutOfRangeException("fieldNumber");
if (!ListDecorator.CanPack(packedWireType))
{
if (writePacked) throw new InvalidOperationException("Only simple data-types can use packed encoding");
packedWireType = WireType.None;
}
this.fieldNumber = fieldNumber;
this.packedWireType = packedWireType;
if (writePacked) options |= OPTIONS_WritePacked;
if (overwriteList) options |= OPTIONS_OverwriteList;
if (supportNull) options |= OPTIONS_SupportNull;
this.arrayType = arrayType;
}
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:27,代码来源:ArrayDecorator.cs
示例13: NetObjectSerializer
public NetObjectSerializer(TypeModel model, Type type, int key, BclHelpers.NetObjectOptions options)
{
bool dynamicType = (options & BclHelpers.NetObjectOptions.DynamicType) != 0;
this.key = dynamicType ? -1 : key;
this.type = dynamicType ? model.MapType(typeof (object)) : type;
this.options = options;
}
开发者ID:he0x,项目名称:xRAT,代码行数:7,代码来源:NetObjectSerializer.cs
示例14: Write
public override void Write(Type useType, object value, ProtoWriter dest)
{
if (!object.Equals(value, defaultValue))
{
Tail.Write(useType, value, dest);
}
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:7,代码来源:DefaultValueDecorator.cs
示例15: NewDelegate
public NewDelegate(Type delegateType, Operand target, string methodName, ITypeMapper typeMapper)
{
_delegateType = delegateType;
_target = target;
_typeMapper = typeMapper;
Initialize(target.GetReturnType(typeMapper), methodName);
}
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:7,代码来源:NewDelegate.cs
示例16: IsReflectionOnly
internal static bool IsReflectionOnly(Type type)
{
while (type.HasElementType)
{
type = type.GetElementType();
}
Assembly asm = type.Assembly;
if (asm != null && asm.ReflectionOnly)
{
return true;
}
if (!type.IsGenericType || type.IsGenericTypeDefinition)
{
return false;
}
// we have a generic type instantiation, it might have ReflectionOnly type arguments
foreach (Type arg in type.GetGenericArguments())
{
if (IsReflectionOnly(arg))
{
return true;
}
}
return false;
}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:25,代码来源:ReflectUtil.cs
示例17: Create
public static AttributeMap[] Create(TypeModel model, Type type, bool inherit)
{
#if FEAT_IKVM
Type attribType = model.MapType(typeof(System.Attribute));
System.Collections.Generic.IList<CustomAttributeData> all = type.__GetCustomAttributes(attribType, inherit);
AttributeMap[] result = new AttributeMap[all.Count];
int index = 0;
foreach (CustomAttributeData attrib in all)
{
result[index++] = new AttributeDataMap(attrib);
}
return result;
#else
#if WINRT
Attribute[] all = System.Linq.Enumerable.ToArray(type.GetTypeInfo().GetCustomAttributes(inherit));
#else
var all = type.GetCustomAttributes(inherit);
#endif
var result = new AttributeMap[all.Length];
for (var i = 0; i < all.Length; i++)
{
result[i] = new ReflectionAttributeMap((Attribute) all[i]);
}
return result;
#endif
}
开发者ID:289997171,项目名称:vicking,代码行数:26,代码来源:AttributeMap.cs
示例18: FieldDecorator
public FieldDecorator(Type forType, FieldInfo field, IProtoSerializer tail) : base(tail)
{
Helpers.DebugAssert(forType != null);
Helpers.DebugAssert(field != null);
this.forType = forType;
this.field = field;
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:7,代码来源:FieldDecorator.cs
示例19: CanOwnDynamicMethod
internal static bool CanOwnDynamicMethod(Type type)
{
return type != null
&& !type.IsInterface
&& !type.HasElementType
&& !type.IsGenericTypeDefinition
&& !type.IsGenericParameter;
}
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:8,代码来源:ReflectUtil.cs
示例20: EnumPair
public EnumPair(int wireValue, object raw, Type type)
{
WireValue = wireValue;
RawValue = raw;
#if !FEAT_IKVM
TypedValue = (Enum)Enum.ToObject(type, raw);
#endif
}
开发者ID:d3x0r,项目名称:Voxelarium,代码行数:8,代码来源:EnumSerializer.cs
注:本文中的IKVM.Reflection.Type类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论