/// <summary> /// Inherited constructor /// </summary> protected ConstructorDef(Resolver resolver, dnlib.DotNet.MethodDef source, string name) : base(resolver, source) { // If the source is null.. if (source is null) { // throw an exception throw new ArgumentNullException(nameof(source)); } // If the name is null.. if (name is null) { // throw an exception throw new ArgumentNullException(nameof(name)); } Name = name; IsStatic = source.IsStatic; Arguments = ResolveArguments(resolver, source).ToReadOnlyCollection(); var rawName = source.FullName.Substring(source.FullName.IndexOf(' ', StringComparison.InvariantCulture) + 1).Replace("::", ".", StringComparison.InvariantCulture); RawName = source.IsConstructor ? rawName.Replace(".ctor(", "#ctor(", StringComparison.InvariantCulture) : rawName; Accessor = ResolveAccessor(source); }
private static string ResolveName(dnlib.DotNet.MethodDef source, bool isNested) { ReadOnlySpan <char> CutNamespace() { var type = source.DeclaringType; var fullname = type.FullName.AsSpan(); if (isNested) { return(fullname.Slice(type.FullName.LastIndexOf('/') + 1)); } return(type.Namespace.Length != 0 ? fullname.Slice(type.Namespace.Length + 1) : fullname); } var namespaceCut = CutNamespace(); if (!source.DeclaringType.HasGenericParameters) { return(namespaceCut.ToString()); } var genericsIndex = namespaceCut.IndexOf(GENERIC_CHAR.AsSpan(), StringComparison.InvariantCulture); if (genericsIndex == -1) { return(namespaceCut.ToString()); } var genericCut = namespaceCut.Slice(0, genericsIndex); return(genericCut.ToString()); }
public override bool Execute(object context) { dnlib.DotNet.MethodDef method = (dnlib.DotNet.MethodDef)context; if (method.IsRuntimeSpecialName) return false; if (method.DeclaringType.IsForwarder) return false; return true; }
public override bool Exec(object context) { dnlib.DotNet.MethodDef method = (dnlib.DotNet.MethodDef)context; if (method.IsRuntimeSpecialName) { return(false); } if (method.DeclaringType.IsForwarder) { return(false); } return(true); }
private static IEnumerable <IArgument> ResolveArguments(Resolver resolver, dnlib.DotNet.MethodDef method) => method.Parameters // Filter out invalid arguments .Where(parameter => !string.IsNullOrEmpty(parameter.Name)) // Initialize the arguments .Select(parameter => new ArgumentDef(resolver, parameter, method.ResolveMethodGenerics()));
/// <summary> /// Default constructor /// </summary> internal ConstructorDef(Resolver resolver, dnlib.DotNet.MethodDef source, bool isNested) : this(resolver, source, ResolveName(source, isNested)) { }
private static AccessorType ResolveAccessor(dnlib.DotNet.MethodDef method) => method.Access switch {