diff --git a/src/AST/Class.cs b/src/AST/Class.cs index 5e207c00..58a96857 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -47,19 +47,12 @@ namespace CppSharp.AST { get { - Class @class; - Type.TryGetClass(out @class); + Type.TryGetClass(out var @class); return @class; } } - public bool IsClass - { - get - { - return Type.IsClass(); - } - } + public bool IsClass => Type.IsClass(); } public enum ClassType @@ -69,7 +62,7 @@ namespace CppSharp.AST Interface } - // Represents a C++ record Decl. + // Represents a C++ record decl. public class Class : DeclarationContext { public List Bases; @@ -104,10 +97,7 @@ namespace CppSharp.AST public bool IsOpaque { get => isOpaque ?? (IsIncomplete && CompleteDeclaration == null); - set - { - isOpaque = value; - } + set => isOpaque = value; } // True if the class is dynamic. @@ -163,39 +153,22 @@ namespace CppSharp.AST } } - public bool HasNonIgnoredBase - { - get - { - return HasBaseClass && !IsValueType - && BaseClass != null - && !BaseClass.IsValueType - && BaseClass.IsGenerated; - } - } + public bool HasNonIgnoredBase => + HasBaseClass && !IsValueType + && BaseClass != null + && !BaseClass.IsValueType + && BaseClass.IsGenerated; - public bool NeedsBase - { - get { return HasNonIgnoredBase && IsGenerated; } - } + public bool NeedsBase => HasNonIgnoredBase && IsGenerated; // When we have an interface, this is the class mapped to that interface. public Class OriginalClass { get; set; } - public bool IsValueType - { - get { return Type == ClassType.ValueType || IsUnion; } - } + public bool IsValueType => Type == ClassType.ValueType || IsUnion; - public bool IsRefType - { - get { return Type == ClassType.RefType && !IsUnion; } - } + public bool IsRefType => Type == ClassType.RefType && !IsUnion; - public bool IsInterface - { - get { return Type == ClassType.Interface; } - } + public bool IsInterface => Type == ClassType.Interface; public bool IsAbstractImpl { @@ -261,10 +234,7 @@ namespace CppSharp.AST } } - public bool IsTemplate - { - get { return IsDependent && TemplateParameters.Count > 0; } - } + public bool IsTemplate => IsDependent && TemplateParameters.Count > 0; public override IEnumerable FindOperator(CXXOperatorKind kind) { diff --git a/src/AST/Declaration.cs b/src/AST/Declaration.cs index 71dfc8fc..405f1f8c 100644 --- a/src/AST/Declaration.cs +++ b/src/AST/Declaration.cs @@ -53,24 +53,14 @@ namespace CppSharp.AST public virtual GenerationKind GenerationKind { - get - { - if (generationKind.HasValue) - return generationKind.Value; - - return GenerationKind.Generate; - } - - set - { - generationKind = value; - } + get => generationKind ?? GenerationKind.Generate; + set => generationKind = value; } /// /// Whether the declaration should be generated. /// - public virtual bool IsGenerated => GenerationKind == GenerationKind.Generate; + public bool IsGenerated => GenerationKind == GenerationKind.Generate; /// /// Whether the declaration has an explicit set generation kind. @@ -81,8 +71,7 @@ namespace CppSharp.AST /// Whether the declaration was explicitly set to be generated via /// the GenerationKind property as opposed to the default generated state. /// - public virtual bool IsExplicitlyGenerated => - generationKind.HasValue && generationKind.Value == GenerationKind.Generate; + public bool IsExplicitlyGenerated => generationKind == GenerationKind.Generate; /// /// Whether the declaration internal bindings should be generated. @@ -92,9 +81,8 @@ namespace CppSharp.AST /// /// Whether a binded version of this declaration is available. /// - public bool IsDeclared => - GenerationKind == GenerationKind.Generate - || GenerationKind == GenerationKind.Internal; + public bool IsDeclared => GenerationKind == GenerationKind.Generate + || GenerationKind == GenerationKind.Internal; public void ExplicitlyIgnore() { @@ -104,13 +92,13 @@ namespace CppSharp.AST [Obsolete("Replace set by ExplicitlyIgnore(). Replace get by GenerationKind == GenerationKind.None.")] public bool ExplicityIgnored { - get { return GenerationKind == GenerationKind.None; } + get => GenerationKind == GenerationKind.None; set { if (value) ExplicitlyIgnore(); } } public virtual bool Ignore { - get { return GenerationKind == GenerationKind.None; } + get => GenerationKind == GenerationKind.None; set { if (value) ExplicitlyIgnore(); } } } @@ -135,12 +123,11 @@ namespace CppSharp.AST // Namespace the declaration is contained in. public DeclarationContext Namespace { - get { return @namespace; } + get => @namespace; set { @namespace = value; - if (OriginalNamespace == null) - OriginalNamespace = @namespace; + OriginalNamespace ??= @namespace; } } @@ -177,12 +164,11 @@ namespace CppSharp.AST public virtual string Name { - get { return name; } + get => name; set { name = value; - if (OriginalName == null) - OriginalName = name; + OriginalName ??= name; } } @@ -192,19 +178,13 @@ namespace CppSharp.AST /// the real and the "effective" name of the declaration to properly /// support things like inline namespaces when handling type maps. /// - public virtual string LogicalName - { - get { return Name; } - } + public virtual string LogicalName => Name; /// /// The effective original name of a declaration is the logical /// original name for the declaration. /// - public virtual string LogicalOriginalName - { - get { return OriginalName; } - } + public virtual string LogicalOriginalName => OriginalName; public static string QualifiedNameSeparator = "::"; @@ -233,8 +213,7 @@ namespace CppSharp.AST var currentNamespace = @namespace; while (currentNamespace != null) { - var isInlineNamespace = currentNamespace is Namespace && - ((Namespace) currentNamespace).IsInline; + var isInlineNamespace = currentNamespace is Namespace {IsInline: true}; if (!isInlineNamespace) namespaces.Push(currentNamespace); currentNamespace = currentNamespace.Namespace; @@ -280,8 +259,7 @@ namespace CppSharp.AST private static string GetDeclName(Declaration decl, string name) { - var specialization = decl as ClassTemplateSpecialization; - if (specialization != null) + if (decl is ClassTemplateSpecialization specialization) return string.Format("{0}<{1}>", name, string.Join(", ", specialization.Arguments.Select( a => a.Type.Type == null ? string.Empty : a.Type.ToString()))); diff --git a/src/AST/DeclarationsList.cs b/src/AST/DeclarationsList.cs index 549359ec..b02aa557 100644 --- a/src/AST/DeclarationsList.cs +++ b/src/AST/DeclarationsList.cs @@ -23,7 +23,7 @@ namespace CppSharp.AST public void AddRange(IEnumerable declarations) { - foreach (Declaration declaration in declarations) + foreach (var declaration in declarations) { Add(declaration); } @@ -31,8 +31,9 @@ namespace CppSharp.AST protected override void InsertItem(int index, Declaration item) { - Kind kind = GetKind(item); - int offset = GetOffset(kind); + var kind = GetKind(item); + var offset = GetOffset(kind); + // USR null means an artificial declaration, add at the end if (item.USR == null) { @@ -40,10 +41,11 @@ namespace CppSharp.AST } else { - int i = BinarySearch(GetStart(kind), offset, item); + var i = BinarySearch(GetStart(kind), offset, item); base.InsertItem(i, item); } - for (Kind i = kind; i <= Kind.Event; i++) + + for (var i = kind; i <= Kind.Event; i++) { if (offsets.ContainsKey(i)) { @@ -55,7 +57,7 @@ namespace CppSharp.AST protected override void RemoveItem(int index) { base.RemoveItem(index); - for (Kind i = Kind.Namespace; i <= Kind.Event; i++) + for (var i = Kind.Namespace; i <= Kind.Event; i++) { if (offsets.ContainsKey(i) && index < offsets[i]) { @@ -64,14 +66,16 @@ namespace CppSharp.AST } } + private IEnumerable OfType(Kind kind) where T : Declaration { if (!offsets.ContainsKey(kind)) { yield break; } - int offset = offsets[kind]; - for (int i = GetStart(kind); i < offset; i++) + + var offset = offsets[kind]; + for (var i = GetStart(kind); i < offset; i++) { yield return (T) this[i]; } @@ -79,47 +83,41 @@ namespace CppSharp.AST private static Kind GetKind(Declaration item) { - if (item is Namespace) - return Kind.Namespace; - if (item is Enumeration) - return Kind.Enum; - if (item is Function) - return Kind.Function; - if (item is Class) - return Kind.Class; - if (item is Template) - return Kind.Template; - if (item is TypedefNameDecl) - return Kind.Typedef; - if (item is Variable) - return Kind.Variable; - if (item is Friend) - return Kind.Friend; - if (item is Event) - return Kind.Event; - throw new System.ArgumentOutOfRangeException(nameof(item), - "Unsupported type of declaration."); + return item switch + { + Namespace _ => Kind.Namespace, + Enumeration _ => Kind.Enum, + Function _ => Kind.Function, + Class _ => Kind.Class, + Template _ => Kind.Template, + TypedefNameDecl _ => Kind.Typedef, + Variable _ => Kind.Variable, + Friend _ => Kind.Friend, + Event _ => Kind.Event, + _ => throw new System.ArgumentOutOfRangeException(nameof(item), "Unsupported type of declaration.") + }; } private int GetOffset(Kind kind) { - if (!offsets.ContainsKey(kind)) + if (offsets.ContainsKey(kind)) + return offsets[kind]; + + for (var i = kind - 1; i >= Kind.Namespace; i--) { - for (Kind i = kind - 1; i >= Kind.Namespace; i--) + if (offsets.ContainsKey(i)) { - if (offsets.ContainsKey(i)) - { - return offsets[kind] = offsets[i]; - } + return offsets[kind] = offsets[i]; } - offsets[kind] = 0; } + + offsets[kind] = 0; return offsets[kind]; } private int GetStart(Kind kind) { - for (Kind i = kind - 1; i >= Kind.Namespace; i--) + for (var i = kind - 1; i >= Kind.Namespace; i--) { if (offsets.ContainsKey(i)) { diff --git a/src/AST/Function.cs b/src/AST/Function.cs index 95513e38..dc9844b6 100644 --- a/src/AST/Function.cs +++ b/src/AST/Function.cs @@ -111,10 +111,7 @@ namespace CppSharp.AST /// It's false in Clang to begin with. I tried fixing it to no avail. /// I don't have any more time at the moment. /// - public bool IsConst - { - get { return DebugText.StartsWith("const ", System.StringComparison.Ordinal); } - } + public bool IsConst => DebugText.StartsWith("const ", System.StringComparison.Ordinal); ExpressionObsolete defaultArgument; private Stmt defaultValue; @@ -193,8 +190,10 @@ namespace CppSharp.AST FunctionType = function.FunctionType; if (function.SpecializationInfo != null) { - SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo); - SpecializationInfo.SpecializedFunction = function; + SpecializationInfo = new FunctionTemplateSpecialization(function.SpecializationInfo) + { + SpecializedFunction = function + }; } } @@ -279,8 +278,8 @@ namespace CppSharp.AST public Type Type => ReturnType.Type; public QualifiedType QualifiedType { - get { return ReturnType; } - set { ReturnType = value; } + get => ReturnType; + set => ReturnType = value; } } } \ No newline at end of file diff --git a/src/AST/Method.cs b/src/AST/Method.cs index acee4aee..0f577a24 100644 --- a/src/AST/Method.cs +++ b/src/AST/Method.cs @@ -196,7 +196,7 @@ namespace CppSharp.AST public override string ToString() { - return DebugText; + return !string.IsNullOrEmpty(DebugText) ? DebugText : Name; } } } diff --git a/src/AST/Template.cs b/src/AST/Template.cs index eeaa9c91..6af7fc6a 100644 --- a/src/AST/Template.cs +++ b/src/AST/Template.cs @@ -35,7 +35,7 @@ namespace CppSharp.AST } /// - /// Represents a template parameter + /// Represents a type template parameter. /// public class TypeTemplateParameter : Declaration { @@ -70,7 +70,7 @@ namespace CppSharp.AST } /// - /// Represents a hard-coded template parameter + /// Represents a non-type template parameter. /// public class NonTypeTemplateParameter : Declaration { @@ -139,12 +139,7 @@ namespace CppSharp.AST // Name of the declaration. public override string Name { - get - { - if (TemplatedDecl != null) - return TemplatedDecl.Name; - return base.Name; - } + get => TemplatedDecl != null ? TemplatedDecl.Name : base.Name; set { base.Name = value; @@ -166,7 +161,7 @@ namespace CppSharp.AST public Declaration TemplatedDecl; - public List Parameters; + public readonly List Parameters; public override string ToString() { @@ -190,12 +185,9 @@ namespace CppSharp.AST /// public class ClassTemplate : Template { - public List Specializations; + public readonly List Specializations; - public Class TemplatedClass - { - get { return TemplatedDecl as Class; } - } + public Class TemplatedClass => TemplatedDecl as Class; public ClassTemplate() { @@ -215,12 +207,7 @@ namespace CppSharp.AST public override string Name { - get - { - if(TemplatedDecl != null) - return TemplatedClass.Name; - return base.Name; - } + get => TemplatedDecl != null ? TemplatedClass.Name : base.Name; set { if(TemplatedDecl != null) @@ -232,12 +219,7 @@ namespace CppSharp.AST public override string OriginalName { - get - { - if(TemplatedDecl != null) - return TemplatedClass.OriginalName; - return base.OriginalName; - } + get => TemplatedDecl != null ? TemplatedClass.OriginalName : base.OriginalName; set { if(TemplatedDecl != null) @@ -293,7 +275,7 @@ namespace CppSharp.AST { public ClassTemplate TemplatedDecl; - public List Arguments; + public readonly List Arguments; public TemplateSpecializationKind SpecializationKind; @@ -327,7 +309,7 @@ namespace CppSharp.AST /// public class FunctionTemplate : Template { - public List Specializations; + public readonly List Specializations; public FunctionTemplate() { @@ -340,10 +322,7 @@ namespace CppSharp.AST Specializations = new List(); } - public Function TemplatedFunction - { - get { return TemplatedDecl as Function; } - } + public Function TemplatedFunction => TemplatedDecl as Function; public override T Visit(IDeclVisitor visitor) { @@ -359,7 +338,7 @@ namespace CppSharp.AST { public FunctionTemplate Template; - public List Arguments; + public readonly List Arguments; public Function SpecializedFunction; @@ -390,12 +369,9 @@ namespace CppSharp.AST /// public class VarTemplate : Template { - public List Specializations; + public readonly List Specializations; - public Variable TemplatedVariable - { - get { return TemplatedDecl as Variable; } - } + public Variable TemplatedVariable => TemplatedDecl as Variable; public VarTemplate() { @@ -421,7 +397,7 @@ namespace CppSharp.AST { public VarTemplate TemplatedDecl; - public List Arguments; + public readonly List Arguments; public TemplateSpecializationKind SpecializationKind; diff --git a/src/AST/Type.cs b/src/AST/Type.cs index 0398c657..a0d4d617 100644 --- a/src/AST/Type.cs +++ b/src/AST/Type.cs @@ -191,10 +191,7 @@ namespace CppSharp.AST Size = type.Size; } - public Type Type - { - get { return QualifiedType.Type; } - } + public Type Type => QualifiedType.Type; public override T Visit(ITypeVisitor visitor, TypeQualifiers quals = new TypeQualifiers()) { @@ -690,12 +687,10 @@ namespace CppSharp.AST { var finalType = Desugared.Type.GetFinalPointee() ?? Desugared.Type; - var tagType = finalType as TagType; - if (tagType != null) + if (finalType is TagType tagType) return tagType.Declaration; - var injectedClassNameType = finalType as InjectedClassNameType; - if (injectedClassNameType == null) + if (!(finalType is InjectedClassNameType injectedClassNameType)) return null; var injectedSpecializationType = (TemplateSpecializationType) @@ -801,11 +796,14 @@ namespace CppSharp.AST : base(type) { if (type.Parameter != null) + { Parameter = new TypeTemplateParameter { Constraint = type.Parameter.Constraint, Name = type.Parameter.Name }; + } + Depth = type.Depth; Index = type.Index; IsParameterPack = type.IsParameterPack; diff --git a/src/AST/TypeExtensions.cs b/src/AST/TypeExtensions.cs index 36e8a519..40890f40 100644 --- a/src/AST/TypeExtensions.cs +++ b/src/AST/TypeExtensions.cs @@ -121,37 +121,33 @@ t = t.Desugar(); TagType tagType = null; - var type = t as TemplateSpecializationType; - if (type != null) + if (t is TemplateSpecializationType type) { if (type.IsDependent) { - if (type.Template is TypeAliasTemplate) - { - type.Desugared.Type.TryGetDeclaration(out decl, value); - decl = decl as T; - return decl != null; - } - - var classTemplate = type.Template as ClassTemplate; - if (classTemplate != null) + switch (type.Template) { - var templatedClass = classTemplate.TemplatedClass; - decl = templatedClass.CompleteDeclaration == null - ? templatedClass as T - : (T) templatedClass.CompleteDeclaration; - if (decl != null) + case TypeAliasTemplate _: + type.Desugared.Type.TryGetDeclaration(out decl, value); + return decl != null; + case ClassTemplate classTemplate: { + var templatedClass = classTemplate.TemplatedClass; + decl = templatedClass.CompleteDeclaration == null + ? templatedClass as T + : (T) templatedClass.CompleteDeclaration; + + if (decl == null) + return false; + if (value != null) type.Template = new ClassTemplate { TemplatedDecl = value }; + return true; } - return false; + case TemplateTemplateParameter templateTemplateParameter: + return (decl = templateTemplateParameter.TemplatedDecl as T) != null; } - - var templateTemplateParameter = type.Template as TemplateTemplateParameter; - if (templateTemplateParameter != null) - return (decl = templateTemplateParameter.TemplatedDecl as T) != null; } tagType = (type.Desugared.Type.GetFinalPointee() ?? type.Desugared.Type) as TagType; } diff --git a/src/Generator/AST/Utils.cs b/src/Generator/AST/Utils.cs index ea43c400..fc5f3e76 100644 --- a/src/Generator/AST/Utils.cs +++ b/src/Generator/AST/Utils.cs @@ -11,8 +11,8 @@ namespace CppSharp.AST { if (!function.IsGenerated) return true; - if (function is Method) - return CheckIgnoreMethod(function as Method); + if (function is Method method) + return CheckIgnoreMethod(method); return false; } @@ -127,9 +127,8 @@ namespace CppSharp.AST private static bool UsesAdditionalTypeParam(Method method) { - var specialization = method.Namespace as ClassTemplateSpecialization; Class template; - if (specialization != null) + if (method.Namespace is ClassTemplateSpecialization specialization) template = specialization.TemplatedDecl.TemplatedClass; else { @@ -143,8 +142,7 @@ namespace CppSharp.AST if (!p.IsDependent) return false; var desugared = p.Type.Desugar(); - var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar() - as TemplateParameterType; + var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar() as TemplateParameterType; return finalType != null && !typeParams.Contains(finalType.Parameter.Name); }); } @@ -165,8 +163,7 @@ namespace CppSharp.AST ITypeMapDatabase typeMaps, bool internalOnly, Type type, ClassTemplateSpecialization specialization) { - TypeMap typeMap; - typeMaps.FindTypeMap(type, out typeMap); + typeMaps.FindTypeMap(type, out var typeMap); return (!internalOnly && (((specialization.Ignore || specialization.TemplatedDecl.TemplatedClass.Ignore) && typeMap == null) || @@ -179,8 +176,7 @@ namespace CppSharp.AST private static ClassTemplateSpecialization GetParentSpecialization(Type type) { - Declaration declaration; - if (type.TryGetDeclaration(out declaration)) + if (type.TryGetDeclaration(out Declaration declaration)) { ClassTemplateSpecialization specialization = null; do @@ -207,8 +203,7 @@ namespace CppSharp.AST public static bool IsMappedToPrimitive(ITypeMapDatabase typeMaps, Type type) { - TypeMap typeMap; - if (!typeMaps.FindTypeMap(type, out typeMap)) + if (!typeMaps.FindTypeMap(type, out var typeMap)) return false; var typePrinterContext = new TypePrinterContext { Type = type }; @@ -258,16 +253,14 @@ namespace CppSharp.AST public static bool IsBuiltinOperator(CXXOperatorKind kind) { - bool isBuiltin; - GetOperatorIdentifier(kind, out isBuiltin); + GetOperatorIdentifier(kind, out var isBuiltin); return isBuiltin; } public static string GetOperatorIdentifier(CXXOperatorKind kind) { - bool isBuiltin; - return GetOperatorIdentifier(kind, out isBuiltin); + return GetOperatorIdentifier(kind, out _); } public static string GetOperatorIdentifier(CXXOperatorKind kind, diff --git a/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs b/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs index dffd6d62..f3a5817f 100644 --- a/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpExpressionPrinter.cs @@ -30,8 +30,7 @@ namespace CppSharp.Generators.CSharp parameter.DefaultArgument.Class == StatementClass.BinaryOperator)) return $"({desugared.Visit(typePrinter)}) {expression}"; var finalType = (desugared.GetFinalPointee() ?? desugared).Desugar(); - Class @class; - if (finalType.TryGetClass(out @class) && @class.IsInterface) + if (finalType.TryGetClass(out var @class) && @class.IsInterface) return $@"({@class.Visit(typePrinter)}) ({ @class.OriginalClass.Visit(typePrinter)}) {expression}"; return expression; @@ -46,17 +45,13 @@ namespace CppSharp.Generators.CSharp switch (callExpr.Declaration.GenerationKind) { case GenerationKind.Generate: - return string.Format("{0}.{1}({2})", - typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), - callExpr.Declaration.Name, - string.Join(", ", callExpr.Arguments.Select(VisitExpression))); + var args = string.Join(", ", callExpr.Arguments.Select(VisitExpression)); + return $"{typePrinter.VisitDeclaration(callExpr.Declaration.Namespace)}.{callExpr.Declaration.Name}({args})"; case GenerationKind.Internal: // a non-ctor can only be internal if it's been converted to a property var property = ((Class) callExpr.Declaration.Namespace).Properties.First( p => p.GetMethod == callExpr.Declaration); - return string.Format("{0}.{1}", - typePrinter.VisitDeclaration(callExpr.Declaration.Namespace), - property.Name); + return $"{typePrinter.VisitDeclaration(callExpr.Declaration.Namespace)}.{property.Name}"; default: return expr.String; } diff --git a/src/Generator/Passes/CheckAmbiguousFunctions.cs b/src/Generator/Passes/CheckAmbiguousFunctions.cs index 04c2884d..b8058034 100644 --- a/src/Generator/Passes/CheckAmbiguousFunctions.cs +++ b/src/Generator/Passes/CheckAmbiguousFunctions.cs @@ -62,8 +62,7 @@ namespace CppSharp.Passes } if (function.IsAmbiguous) - Diagnostics.Debug("Found ambiguous overload: {0}", - function.QualifiedOriginalName); + Diagnostics.Message($"Found ambiguous overload: {function.QualifiedOriginalName}"); return true; } diff --git a/src/Generator/Passes/CheckDuplicatedNamesPass.cs b/src/Generator/Passes/CheckDuplicatedNamesPass.cs index 8d9f526f..a80a7e85 100644 --- a/src/Generator/Passes/CheckDuplicatedNamesPass.cs +++ b/src/Generator/Passes/CheckDuplicatedNamesPass.cs @@ -23,14 +23,12 @@ namespace CppSharp.Passes public bool UpdateName(Declaration decl) { - var function = decl as Function; - if (function != null) + if (decl is Function function) { return UpdateName(function); } - var property = decl as Property; - var isIndexer = property != null && property.Parameters.Count > 0; + var isIndexer = decl is Property property && property.Parameters.Count > 0; if (isIndexer) { return false; @@ -131,10 +129,8 @@ namespace CppSharp.Passes private static bool CheckForSpecializations(Type leftPointee, Type rightPointee) { - Class leftClass; - Class rightClass; - if (!leftPointee.TryGetDeclaration(out leftClass) || - !rightPointee.TryGetDeclaration(out rightClass)) + if (!leftPointee.TryGetDeclaration(out Class leftClass) || + !rightPointee.TryGetDeclaration(out Class rightClass)) return false; var leftSpecialization = leftClass as ClassTemplateSpecialization ?? @@ -206,10 +202,7 @@ namespace CppSharp.Passes switch (kind) { case GeneratorKind.C: - typePrinter = new CppTypePrinter(Context) - { - PrintFlavorKind = CppTypePrintFlavorKind.C - }; + typePrinter = new CppTypePrinter(Context) { PrintFlavorKind = CppTypePrintFlavorKind.C }; break; case GeneratorKind.CPlusPlus: case GeneratorKind.QuickJS: @@ -310,8 +303,7 @@ namespace CppSharp.Passes return; var fullName = decl.QualifiedName; - var function = decl as Function; - if (function != null) + if (decl is Function function) fullName = DeclarationName.FixSignatureForConversions(function, fullName); // If the name is not yet on the map, then add it. diff --git a/src/Parser/ASTConverter.cs b/src/Parser/ASTConverter.cs index e700423c..cd6c417d 100644 --- a/src/Parser/ASTConverter.cs +++ b/src/Parser/ASTConverter.cs @@ -2185,9 +2185,11 @@ namespace CppSharp protected override AST.Comment VisitInlineCommandComment(InlineCommandComment comment) { - var inlineCommandComment = new AST.InlineCommandComment(); - inlineCommandComment.HasTrailingNewline = comment.HasTrailingNewline; - inlineCommandComment.CommandId = comment.CommandId; + var inlineCommandComment = new AST.InlineCommandComment + { + HasTrailingNewline = comment.HasTrailingNewline, + CommandId = comment.CommandId + }; switch (comment.CommentRenderKind) { case InlineCommandComment.RenderKind.RenderNormal: