本文整理汇总了C#中IKVM.Reflection.Type.GetNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetNamespace方法的具体用法?C# Type.GetNamespace怎么用?C# Type.GetNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.GetNamespace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFullName_recursed
void GetFullName_recursed (StringBuilder sb, Type t, bool recursed)
{
if (t.IsGenericParameter) {
sb.Append (t.Name);
return;
}
if (t.DeclaringType != null) {
GetFullName_recursed (sb, t.DeclaringType, true);
sb.Append (".");
}
if (!recursed) {
string ns;
ns = t.GetNamespace ();
if ((ns != null) && (ns != "")) {
sb.Append (ns);
sb.Append (".");
}
}
GetTypeName (sb, t);
}
示例2: FormatType
// TODO: fine tune this so that our output is less verbose. We need to figure
// out a way to do this while not making things confusing.
string FormatType (Type t)
{
if (t == null)
return "";
string type = GetFullName (t);
if (type == null)
return t.ToString ();
if (!type.StartsWith ("System.")) {
if (type.IndexOf (".") == -1)
return type;
if (t.GetNamespace () == this.t.GetNamespace ())
return t.Name;
return type;
}
if (t.HasElementType) {
Type et = t.GetElementType ();
if (t.IsArray)
return FormatType (et) + " []";
if (t.IsPointer)
return FormatType (et) + " *";
if (t.IsByRef)
return "ref " + FormatType (et);
}
switch (type) {
case "System.Byte": return "byte";
case "System.SByte": return "sbyte";
case "System.Int16": return "short";
case "System.Int32": return "int";
case "System.Int64": return "long";
case "System.UInt16": return "ushort";
case "System.UInt32": return "uint";
case "System.UInt64": return "ulong";
case "System.Single": return "float";
case "System.Double": return "double";
case "System.Decimal": return "decimal";
case "System.Boolean": return "bool";
case "System.Char": return "char";
case "System.String": return "string";
case "System.Object": return "object";
case "System.Void": return "void";
}
if (type.LastIndexOf(".") == 6)
return type.Substring(7);
//
// If the namespace of the type is the namespace of what
// we are printing (or is a member of one if its children
// don't print it. This basically means that in C# we would
// automatically get the namespace imported by virtue of the
// namespace {} block.
//
if (this.t.Namespace.StartsWith (t.Namespace + ".") || t.Namespace == this.t.Namespace)
return type.Substring (t.Namespace.Length + 1);
return type;
}