本文整理汇总了C#中System.GetGenericArguments方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetGenericArguments方法的具体用法?C# System.GetGenericArguments怎么用?C# System.GetGenericArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetGenericArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GuessType
/// <summary>
/// Guesses the IType by the type
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static IType GuessType(System.Type type)
{
if(type.FullName.StartsWith(typeof(Nullable<>).FullName))
{
type = type.GetGenericArguments()[0];
}
if (clrTypeToNHibernateType.ContainsKey(type))
{
return clrTypeToNHibernateType[type];
}
else if (type.IsEnum)
{
return Enum(type);
}
else if (
typeof(IUserType).IsAssignableFrom(type) ||
typeof(ICompositeUserType).IsAssignableFrom(type))
{
return Custom(type);
}
else
{
return Entity(type);
}
}
示例2: GetDisplayName
private static string GetDisplayName(System.Reflection.MethodBase method, string name, object[] arglist)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(name);
if (method.IsGenericMethod)
{
sb.Append("<");
int cnt = 0;
foreach (var t in method.GetGenericArguments())
{
if (cnt++ > 0)
sb.Append(",");
sb.Append(t.Name);
}
sb.Append(">");
}
if (arglist != null)
{
sb.Append("(");
for (int i = 0; i < arglist.Length; ++i)
{
if (i > 0)
sb.Append(",");
sb.Append(GetDisplayString(arglist[i]));
}
sb.Append(")");
}
return sb.ToString();
}
示例3: FindIEnumerable
private static System.Type FindIEnumerable(System.Type seqType)
{
if (seqType == null || seqType == typeof(string))
return null;
if (seqType.IsArray)
return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
if (seqType.IsGenericType) {
foreach (System.Type arg in seqType.GetGenericArguments())
{
System.Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
if (ienum.IsAssignableFrom(seqType)) {
return ienum;
}
}
}
System.Type[] ifaces = seqType.GetInterfaces();
if (ifaces != null && ifaces.Length > 0) {
foreach (System.Type iface in ifaces)
{
System.Type ienum = FindIEnumerable(iface);
if (ienum != null) return ienum;
}
}
if (seqType.BaseType != null && seqType.BaseType != typeof(object)) {
return FindIEnumerable(seqType.BaseType);
}
return null;
}
示例4: GetNonNullableType
internal static System.Type GetNonNullableType(System.Type type)
{
if (IsNullableType(type)) {
return type.GetGenericArguments()[0];
}
return type;
}
示例5: AppendTypeName
internal static void AppendTypeName(System.Type t, bool topLevelFullName, StringBuilder sb)
{
string s = topLevelFullName ? t.FullName : t.Name;
if (t.IsGenericType)
{
int index = s.IndexOf("`", StringComparison.Ordinal);
if (index == -1)
{
index = s.Length;
}
sb.Append(s.Substring(0, index));
AppendGenericArguments(t.GetGenericArguments(), sb);
if (index < s.Length)
{
index++;
while ((index < s.Length) && char.IsNumber(s, index))
{
index++;
}
sb.Append(s.Substring(index));
}
}
else
{
sb.Append(s);
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:ObjectDataSourceMethodEditor.cs
示例6: GuessType
/// <summary>
/// Guesses the IType by the type
/// </summary>
/// <param name="type">The type.</param>
/// <returns></returns>
public static IType GuessType(System.Type type)
{
if(type.IsGenericType && typeof(Nullable<>).Equals(type.GetGenericTypeDefinition()))
{
type = type.GetGenericArguments()[0];
}
if (clrTypeToNHibernateType.ContainsKey(type))
{
return clrTypeToNHibernateType[type];
}
else if (type.IsEnum)
{
return (IType) Activator.CreateInstance(typeof (EnumType<>).MakeGenericType(type));
}
else if (
typeof(IUserType).IsAssignableFrom(type) ||
typeof(ICompositeUserType).IsAssignableFrom(type))
{
return Custom(type);
}
else
{
return Entity(type);
}
}
示例7: GetComponentType
protected override Type GetComponentType(System.Reflection.MethodInfo method, object[] arguments)
{
var newtype = typeof(IQueryHandler<,>)
.MakeGenericType(
arguments[0].GetType(),
method.GetGenericArguments()[0]
);
return newtype;
}
示例8: GetCollectionValueType
private static System.Type GetCollectionValueType(System.Type type)
{
if (type == null)
return null;
var genericArguments = type.GetGenericArguments();
if (genericArguments.Length == 0)
return null;
return genericArguments[0];
}
示例9: GenerateClassName
/// <summary>
/// Generates a class name for the Template base
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
/// <remarks>This is probably not the right location to put this but it seemed the most logical choice</remarks>
public string GenerateClassName(System.Type type)
{
if (!type.IsGenericType)
return type.Namespace + "." + type.Name;
return type.Namespace
+ "."
+ type.Name.Substring(0, type.Name.IndexOf('`'))
+ "(Of "
+ string.Join(", ", type.GetGenericArguments()
.Select(GenerateClassName))
+ ")";
}
示例10: TryGetCollectionItemType
public static System.Type TryGetCollectionItemType(System.Type collectionType)
{
if (collectionType == null)
return null;
if (collectionType.IsInterface && IsCollectionType(collectionType))
return collectionType.GetGenericArguments().Single();
System.Type enumerableType = collectionType.GetInterfaces().FirstOrDefault(IsCollectionType);
if (enumerableType == null)
return null;
return enumerableType.GetGenericArguments().Single();
}
示例11: Type
internal static string Type(System.Type type, bool dropNamespaces = false)
{
string assemblyQualifiedName;
Exception exception;
if (type == null)
{
return string.Empty;
}
if (type.IsGenericType && !type.IsGenericTypeDefinition)
{
string str2 = Type(type.GetGenericTypeDefinition(), dropNamespaces);
int num = str2.LastIndexOf('`');
int length = str2.Length - (str2.Length - num);
StringBuilder builder = new StringBuilder(str2, 0, length, 0x200);
builder.Append('[');
bool flag = true;
foreach (System.Type type2 in type.GetGenericArguments())
{
if (!flag)
{
builder.Append(',');
}
flag = false;
builder.Append(Type(type2, dropNamespaces));
}
builder.Append(']');
assemblyQualifiedName = builder.ToString();
}
else if (type.IsArray)
{
string str3 = Type(type.GetElementType(), dropNamespaces);
StringBuilder builder2 = new StringBuilder(str3, str3.Length + 10);
builder2.Append("[");
for (int i = 0; i < (type.GetArrayRank() - 1); i++)
{
builder2.Append(",");
}
builder2.Append("]");
assemblyQualifiedName = builder2.ToString();
}
else
{
assemblyQualifiedName = TypeAccelerators.FindBuiltinAccelerator(type) ?? (dropNamespaces ? type.Name : type.ToString());
}
if ((!type.IsGenericParameter && !type.ContainsGenericParameters) && (!dropNamespaces && (LanguagePrimitives.ConvertStringToType(assemblyQualifiedName, out exception) != type)))
{
assemblyQualifiedName = type.AssemblyQualifiedName;
}
return assemblyQualifiedName;
}
示例12: ChangeType
private static Maybe<object> ChangeType(IEnumerable<string> values, System.Type conversionType, CultureInfo conversionCulture)
{
var type =
conversionType.GetGenericArguments()
.SingleOrDefault()
.ToMaybe()
.FromJust(
new ApplicationException("Non scalar properties should be sequence of type IEnumerable<T>."));
var converted = values.Select(value => ChangeType(value, type, conversionCulture));
return converted.Any(a => a.MatchNothing())
? Maybe.Nothing<object>()
: Maybe.Just(converted.Select(c => ((Just<object>)c).Value).ToArray(type));
}
示例13: WriteToStreamAsync
public override System.Threading.Tasks.Task WriteToStreamAsync(System.Type type, object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
{
var obj = new ExpandoObject() as IDictionary<string, Object>;
if (type.IsSubclassOf(typeof(BaseMetaResponseModel)) && type.IsGenericType)
{
Type innerType = type.GetGenericArguments()[0];
var genericValue = (value as BaseMetaResponseModel);
value = genericValue.Content;
type = innerType;
obj["meta"] = genericValue.Meta;
}
var root = GetRootFieldName(type, value);
obj[root] = value;
return base.WriteToStreamAsync(type, obj as object, writeStream, content, transportContext);
}
示例14: MethodBaseInfo
protected MethodBaseInfo(System.Reflection.MethodBase methodInfo, Dictionary<Type, TypeInfo> referenceTracker)
: base(methodInfo, referenceTracker)
{
var bindingFlags = methodInfo.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
bindingFlags |= methodInfo.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
BindingFlags = bindingFlags;
var genericArguments = methodInfo.IsGenericMethod ? methodInfo.GetGenericArguments() : null;
GenericArgumentTypes = ReferenceEquals(null, genericArguments) || genericArguments.Length == 0
? null
: genericArguments.Select(x => TypeInfo.Create(referenceTracker, x, false, false)).ToList();
var parameters = methodInfo.GetParameters();
ParameterTypes = parameters.Length == 0
? null
: parameters.Select(x => TypeInfo.Create(referenceTracker, x.ParameterType, false, false)).ToList();
}
示例15: GetSurrogate
public ISerializationSurrogate GetSurrogate(System.Type type, StreamingContext context, out ISurrogateSelector selector)
{
if (type.IsGenericType)
{
System.Type genericTypeDefinition = type.GetGenericTypeDefinition();
if (genericTypeDefinition == typeof (List<>))
{
selector = (ISurrogateSelector) this;
return ListSerializationSurrogate.Default;
}
if (genericTypeDefinition == typeof (Dictionary<,>))
{
selector = (ISurrogateSelector) this;
return (ISerializationSurrogate) Activator.CreateInstance(typeof (DictionarySerializationSurrogate<,>).MakeGenericType(type.GetGenericArguments()));
}
}
selector = (ISurrogateSelector) null;
return (ISerializationSurrogate) null;
}