本文整理汇总了C#中IKVM.Reflection.Type.GetTypeInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetTypeInfo方法的具体用法?C# Type.GetTypeInfo怎么用?C# Type.GetTypeInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.GetTypeInfo方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
示例2: 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;
}
示例3: 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;
}
示例4: GetCustomToString
private static MethodInfo GetCustomToString(Type type)
{
#if WINRT
foreach (MethodInfo method in type.GetTypeInfo().GetDeclaredMethods("ToString"))
{
if (method.IsPublic && !method.IsStatic && method.GetParameters().Length == 0) return method;
}
return null;
#elif PORTABLE || COREFX
MethodInfo method = Helpers.GetInstanceMethod(type, "ToString", Helpers.EmptyTypes);
if (method == null || !method.IsPublic || method.IsStatic || method.DeclaringType != type) return null;
return method;
#else
return type.GetMethod("ToString", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
null, Helpers.EmptyTypes, null);
#endif
}
示例5: IdentifyImmutable
internal static bool IdentifyImmutable(TypeModel model, Type declaredType, out MethodInfo builderFactory, out MethodInfo add, out MethodInfo addRange, out MethodInfo finish)
{
builderFactory = add = addRange = finish = null;
if (model == null || declaredType == null) return false;
#if WINRT
TypeInfo declaredTypeInfo = declaredType.GetTypeInfo();
#else
Type declaredTypeInfo = declaredType;
#endif
// try to detect immutable collections; firstly, they are all generic, and all implement IReadOnlyCollection<T> for some T
if(!declaredTypeInfo.IsGenericType) return false;
#if WINRT
Type[] typeArgs = declaredTypeInfo.GenericTypeArguments, effectiveType;
#else
Type[] typeArgs = declaredTypeInfo.GetGenericArguments(), effectiveType;
#endif
switch (typeArgs.Length)
{
case 1:
effectiveType = typeArgs;
break; // fine
case 2:
Type kvp = model.MapType(typeof(System.Collections.Generic.KeyValuePair<,>));
if (kvp == null) return false;
kvp = kvp.MakeGenericType(typeArgs);
effectiveType = new Type[] { kvp };
break;
default:
return false; // no clue!
}
if (ResolveIReadOnlyCollection(declaredType, null) == null) return false; // no IReadOnlyCollection<T> found
// and we want to use the builder API, so for generic Foo<T> or IFoo<T> we want to use Foo.CreateBuilder<T>
string name = declaredType.Name;
int i = name.IndexOf('`');
if (i <= 0) return false;
name = declaredTypeInfo.IsInterface ? name.Substring(1, i - 1) : name.Substring(0, i);
Type outerType = model.GetType(declaredType.Namespace + "." + name, declaredTypeInfo.Assembly);
// I hate special-cases...
if (outerType == null && name == "ImmutableSet")
{
outerType = model.GetType(declaredType.Namespace + ".ImmutableHashSet", declaredTypeInfo.Assembly);
}
if (outerType == null) return false;
#if WINRT
foreach (MethodInfo method in outerType.GetTypeInfo().DeclaredMethods)
#else
foreach (MethodInfo method in outerType.GetMethods())
#endif
{
if (!method.IsStatic || method.Name != "CreateBuilder" || !method.IsGenericMethodDefinition || method.GetParameters().Length != 0
|| method.GetGenericArguments().Length != typeArgs.Length) continue;
builderFactory = method.MakeGenericMethod(typeArgs);
break;
}
Type voidType = model.MapType(typeof(void));
if (builderFactory == null || builderFactory.ReturnType == null || builderFactory.ReturnType == voidType) return false;
add = Helpers.GetInstanceMethod(builderFactory.ReturnType, "Add", effectiveType);
if (add == null) return false;
finish = Helpers.GetInstanceMethod(builderFactory.ReturnType, "ToImmutable", Helpers.EmptyTypes);
if (finish == null || finish.ReturnType == null || finish.ReturnType == voidType) return false;
if (!(finish.ReturnType == declaredType || Helpers.IsAssignableFrom(declaredType, finish.ReturnType))) return false;
addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[] { declaredType });
if (addRange == null)
{
Type enumerable = model.MapType(typeof(System.Collections.Generic.IEnumerable<>), false);
if (enumerable != null)
{
addRange = Helpers.GetInstanceMethod(builderFactory.ReturnType, "AddRange", new Type[] { enumerable.MakeGenericType(effectiveType) });
}
}
return true;
}
示例6: IsSubclassOf
internal static bool IsSubclassOf(Type type, Type baseClass)
{
#if WINRT
return type.GetTypeInfo().IsSubclassOf(baseClass);
#else
return type.IsSubclassOf(baseClass);
#endif
}
示例7: GetInstanceMethod
internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] types)
{
return GetInstanceMethod(declaringType.GetTypeInfo(), name, types);
}
示例8: IsAssignableFrom
internal static bool IsAssignableFrom(Type target, Type type)
{
#if WINRT
return target.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo());
#else
return target.IsAssignableFrom(type);
#endif
}
示例9: IsEnum
internal static bool IsEnum(Type type)
{
#if WINRT
return type.GetTypeInfo().IsEnum;
#else
return type.IsEnum;
#endif
}
示例10: IsValueType
internal static bool IsValueType(Type type)
{
#if WINRT
return type.GetTypeInfo().IsValueType;
#else
return type.IsValueType;
#endif
}
示例11: EmitCtor
public void EmitCtor(Type type, params Type[] parameterTypes)
{
Helpers.DebugAssert(type != null);
Helpers.DebugAssert(parameterTypes != null);
if (Helpers.IsValueType(type) && parameterTypes.Length == 0)
{
il.Emit(OpCodes.Initobj, type);
#if DEBUG_COMPILE
Helpers.DebugWriteLine(OpCodes.Initobj + ": " + type);
#endif
}
else
{
ConstructorInfo ctor = Helpers.GetConstructor(type
#if COREFX
.GetTypeInfo()
#endif
, parameterTypes, true);
if (ctor == null) throw new InvalidOperationException("No suitable constructor found for " + type.FullName);
EmitCtor(ctor);
}
}
示例12: CompilerContext
private CompilerContext(Type associatedType, bool isWriter, bool isStatic, TypeModel model, Type inputType)
{
if (model == null) throw new ArgumentNullException("model");
#if FX11
metadataVersion = ILVersion.Net1;
#else
metadataVersion = ILVersion.Net2;
#endif
this.isStatic = isStatic;
this.isWriter = isWriter;
this.model = model;
nonPublic = true;
Type[] paramTypes;
Type returnType;
if (isWriter)
{
returnType = typeof(void);
paramTypes = new Type[] { typeof(object), typeof(ProtoWriter) };
}
else
{
returnType = typeof(object);
paramTypes = new Type[] { typeof(object), typeof(ProtoReader) };
}
int uniqueIdentifier;
#if PLAT_NO_INTERLOCKED
uniqueIdentifier = ++next;
#else
uniqueIdentifier = Interlocked.Increment(ref next);
#endif
method = new DynamicMethod("proto_" + uniqueIdentifier.ToString(), returnType, paramTypes, associatedType
#if COREFX
.GetTypeInfo()
#endif
.IsInterface ? typeof(object) : associatedType, true);
this.il = method.GetILGenerator();
if (inputType != null) this.inputValue = new Local(null, inputType);
}