void SetType(TypeDefinition type) { if (type == null) { throw new ArgumentNullException("type"); } Type = type; GenericParameters = new List <GenericParameter> (type.GenericParameters); List <TypeReference> declTypes = DocUtils.GetDeclaringTypes(type); int maxGenArgs = DocUtils.GetGenericArgumentCount(type); for (int i = 0; i < declTypes.Count - 1; ++i) { int remove = System.Math.Min(maxGenArgs, DocUtils.GetGenericArgumentCount(declTypes[i])); maxGenArgs -= remove; while (remove-- > 0) { GenericParameters.RemoveAt(0); } } if (DocUtils.IsDelegate(type)) { Parameters = type.GetMethod("Invoke").Parameters; ReturnType = type.GetMethod("Invoke").ReturnType; ReturnIsReturn = true; } }
private string GetTypeKind(TypeDefinition type) { if (type.IsInterface) { return("interface"); } if (type.IsValueType) { return("struct"); } if (DocUtils.IsDelegate(type)) { return("delegate of"); } return("class"); }
void SetType(TypeDefinition type) { if (type == null) { throw new ArgumentNullException("type"); } Type = type; GenericParameters = DocUtils.GetGenericParameters(type); if (DocUtils.IsDelegate(type)) { Parameters = type.GetMethod("Invoke").Parameters; ReturnType = type.GetMethod("Invoke").ReturnType; ReturnIsReturn = true; } }
protected override string GetTypeDeclaration(TypeDefinition type) { string visibility = GetTypeVisibility(type.Attributes); if (visibility == null) { return(null); } StringBuilder buf = new StringBuilder(); buf.Append(visibility); buf.Append(" "); MemberFormatter full = new VBMemberFormatter(this.TypeMap); if (DocUtils.IsDelegate(type)) { buf.Append("Delegate "); MethodDefinition invoke = type.GetMethod("Invoke"); bool isFunction = invoke.ReturnType.FullName != "System.Void"; if (isFunction) { buf.Append("Function "); } else { buf.Append("Sub "); } buf.Append(GetName(type)); AppendParameters(buf, invoke, invoke.Parameters); if (isFunction) { buf.Append(" As "); buf.Append(full.GetName(invoke.ReturnType, new DynamicParserContext(invoke.MethodReturnType))).Append(" "); } return(buf.ToString()); } if (type.IsAbstract && !type.IsInterface && !IsModule(type)) { buf.Append("MustInherit "); } if (type.IsSealed && !DocUtils.IsDelegate(type) && !type.IsValueType && !IsModule(type)) { buf.Append("NotInheritable "); } buf.Replace(" MustInherit NotInheritable", ""); buf.Append(GetTypeKind(type)); buf.Append(" "); buf.Append(GetVBType(type.FullName) == null ? GetName(type) : type.Name); if (!type.IsEnum) { TypeReference basetype = type.BaseType; if (basetype != null && basetype.FullName == "System.Object" || type.IsValueType) { basetype = null; } if (basetype != null) { buf.Append(GetLineEnding()).Append("Inherits "); buf.Append(full.GetName(basetype)); } List <string> interfaceNames = DocUtils.GetUserImplementedInterfaces(type) .Select(iface => full.GetName(iface)) .OrderBy(s => s) .ToList(); if (interfaceNames.Count > 0) { buf.Append(GetLineEnding()).Append("Implements "); buf.Append(string.Join(", ", interfaceNames)); } } return(buf.ToString()); }
protected override string GetTypeDeclaration(TypeDefinition type) { string visibility = GetTypeVisibility(type.Attributes); if (visibility == null) { return(null); } StringBuilder buf = new StringBuilder(); buf.Append(visibility); buf.Append(" "); MemberFormatter full = new CSharpFullMemberFormatter(); if (DocUtils.IsDelegate(type)) { buf.Append("delegate "); MethodDefinition invoke = type.GetMethod("Invoke"); buf.Append(full.GetName(invoke.ReturnType, new DynamicParserContext(invoke.MethodReturnType))).Append(" "); buf.Append(GetName(type)); AppendParameters(buf, invoke, invoke.Parameters); AppendGenericTypeConstraints(buf, type); buf.Append(";"); return(buf.ToString()); } if (type.IsAbstract && !type.IsInterface) { buf.Append("abstract "); } if (type.IsSealed && !DocUtils.IsDelegate(type) && !type.IsValueType) { buf.Append("sealed "); } buf.Replace("abstract sealed", "static"); buf.Append(GetTypeKind(type)); buf.Append(" "); buf.Append(GetCSharpType(type.FullName) == null ? GetName(type) : type.Name); if (!type.IsEnum) { TypeReference basetype = type.BaseType; if (basetype != null && basetype.FullName == "System.Object" || type.IsValueType) // FIXME { basetype = null; } List <string> interface_names = DocUtils.GetUserImplementedInterfaces(type) .Select(iface => full.GetName(iface)) .OrderBy(s => s) .ToList(); if (basetype != null || interface_names.Count > 0) { buf.Append(" : "); } if (basetype != null) { buf.Append(full.GetName(basetype)); if (interface_names.Count > 0) { buf.Append(", "); } } for (int i = 0; i < interface_names.Count; i++) { if (i != 0) { buf.Append(", "); } buf.Append(interface_names[i]); } AppendGenericTypeConstraints(buf, type); } return(buf.ToString()); }
protected override string GetTypeDeclaration(TypeDefinition type) { string visibility = GetTypeVisibility(type.Attributes); if (visibility == null) { return(null); } StringBuilder buf = new StringBuilder(); if (IsModule(type)) { AppendModuleDeclaraion(buf, type); return(buf.ToString()); } if (IsDiscriminatedUnionCase(type)) { AppendDiscriminatedUnionCase(buf, type); return(buf.ToString()); } buf.Append("type "); buf.Append(visibility); buf.Append(GetTypeName(type)); buf.Append(" = "); if (IsRecord(type)) { buf.Append("{}"); return(buf.ToString()); } if (IsDiscriminatedUnion(type)) { return(buf.ToString()); } if (type.IsEnum) { return(buf.ToString()); } buf.Append($"{GetTypeKind(type)}"); if (DocUtils.IsDelegate(type)) { buf.Append(" "); MethodDefinition invoke = type.GetMethod("Invoke"); AppendFunctionSignature(buf, invoke); return(buf.ToString()); } AppendBaseType(buf, type); foreach (var interfaceImplementation in type.Interfaces) { var resolvedInterface = interfaceImplementation.InterfaceType.Resolve(); if (type.IsValueType && ignoredValueTypeInterfaces.Any(i => interfaceImplementation.InterfaceType.FullName.StartsWith(i)) || (resolvedInterface != null && resolvedInterface.IsNotPublic)) { continue; } buf.Append($"{GetLineEnding()}{Consts.Tab}interface "); AppendTypeName(buf, GetTypeName(interfaceImplementation.InterfaceType)); } return(buf.ToString()); }