本文整理汇总了C#中Type.IsGenericTypeEx方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsGenericTypeEx方法的具体用法?C# Type.IsGenericTypeEx怎么用?C# Type.IsGenericTypeEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.IsGenericTypeEx方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddType
void AddType(Type type)
{
if (type == null || type == typeof(object) || type.IsGenericParameter || _usedTypes.Contains(type))
return;
_usedTypes.Add(type);
if (type.IsGenericTypeEx())
foreach (var arg in type.GetGenericArgumentsEx())
AddType(arg);
if (type.IsGenericTypeEx() && type.GetGenericTypeDefinition() != type)
AddType(type.GetGenericTypeDefinition());
AddType(type.BaseTypeEx());
foreach (var i in type.GetInterfacesEx())
AddType(i);
}
示例2: GetTypeName
string GetTypeName(Type type)
{
if (type == null || type == typeof(object))
return null;
if (type.IsGenericParameter)
return type.ToString();
string name;
if (_typeNames.TryGetValue(type, out name))
return name;
if (IsAnonymous(type))
{
_typeNames[type] = null;
return null;
}
if (type.IsGenericTypeEx())
{
var args = type.GetGenericArgumentsEx();
name = "";
if (type.Namespace != "System")
name = type.Namespace + ".";
name += type.Name;
var idx = name.LastIndexOf("`");
if (idx > 0)
name = name.Substring(0, idx);
if (type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
name = "{0}?".Args(GetTypeName(args[0]));
}
else
{
name = string.Format("{0}<{1}>",
name,
args.Select(GetTypeName).Aggregate("", (s,t) => s + "," + t, p => p.TrimStart(',')));
}
_typeNames[type] = name;
return name;
}
if (type.Namespace == "System")
return type.Name;
return EncryptName(type, type.ToString(), "T");
}
示例3: BuildType
void BuildType(Type type)
{
if (!IsUserType(type) ||
IsAnonymous(type) ||
type.AssemblyEx() == GetType().AssemblyEx() ||
type.IsGenericTypeEx() && type.GetGenericTypeDefinition() != type)
return;
var isUserName = IsUserType(type);
var name = EncryptName(isUserName, type.Name, "T");
var idx = name.LastIndexOf("`");
if (idx > 0)
name = name.Substring(0, idx);
if (type.IsGenericTypeEx())
type = type.GetGenericTypeDefinition();
var baseClasses = new[] { type.BaseTypeEx() }
.Where(t => t != null && t != typeof(object))
.Concat(type.GetInterfacesEx()).ToArray();
var ctors = type.GetConstructorsEx().Select(c =>
{
#if SILVERLIGHT || NETFX_CORE
var attrs = c.GetCustomAttributes(false).ToList();
#else
var attrs = c.GetCustomAttributesData();
#endif
var ps = c.GetParameters().Select(p => GetTypeName(p.ParameterType) + " " + EncryptName(p.Name, "p")).ToArray();
return @"{0}
public {1}({2})
{{
throw new NotImplementedException();
}}".Args(
attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
name,
ps.Length == 0 ? "" : ps.Aggregate((s,t) => s + ", " + t));
}).ToList();
if (ctors.Count == 1 && ctors[0].IndexOf("()") >= 0)
ctors.Clear();
var members = type.GetFieldsEx().Intersect(_usedMembers.OfType<FieldInfo>()).Select(f =>
{
#if SILVERLIGHT || NETFX_CORE
var attrs = f.GetCustomAttributes(false).ToList();
#else
var attrs = f.GetCustomAttributesData();
#endif
return @"{0}
public {1} {2};".Args(
attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
GetTypeName(f.FieldType),
EncryptName(isUserName, f.Name, "P"));
})
.Concat(
type.GetPropertiesEx().Intersect(_usedMembers.OfType<PropertyInfo>()).Select(p =>
{
#if SILVERLIGHT || NETFX_CORE
var attrs = p.GetCustomAttributes(false).ToList();
#else
var attrs = p.GetCustomAttributesData();
#endif
return string.Format(@"{0}
{3}{1} {2} {{ get; set; }}",
attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
GetTypeName(p.PropertyType),
EncryptName(isUserName, p.Name, "P"),
type.IsInterfaceEx() ? "" : "public ");
}))
.Concat(
type.GetMethodsEx().Intersect(_usedMembers.OfType<MethodInfo>()).Select(m =>
{
#if SILVERLIGHT || NETFX_CORE
var attrs = m.GetCustomAttributes(false).ToList();
#else
var attrs = m.GetCustomAttributesData();
#endif
var ps = m.GetParameters().Select(p => GetTypeName(p.ParameterType) + " " + EncryptName(p.Name, "p")).ToArray();
return string.Format(@"{0}
{5}{4}{1} {2}({3})
{{
throw new NotImplementedException();
}}",
attrs.Count > 0 ? attrs.Select(a => "\r\n\t\t" + a.ToString()).Aggregate((a1,a2) => a1 + a2) : "",
GetTypeName(m.ReturnType),
EncryptName(isUserName, m.Name, "M"),
ps.Length == 0 ? "" : ps.Aggregate((s,t) => s + ", " + t),
m.IsStatic ? "static " :
m.IsVirtual ? "virtual " :
m.IsAbstract ? "abstract " :
"",
type.IsInterfaceEx() ? "" : "public ");
}))
.ToArray();
{
#if SILVERLIGHT || NETFX_CORE
var attrs = type.GetCustomAttributesEx(false).ToList();
//.........这里部分代码省略.........