private bool MatchesType(AssemblyItem item)
        {
            var declaringTypeFullName = item.Method.DeclaringType.FullName;

            if (TypeName.EndsWith('*'))
            {
                // Wildcard match
                return(declaringTypeFullName.StartsWith(
                           TypeName.Substring(0, TypeName.Length - 1),
                           StringComparison.Ordinal));
            }
            else
            {
                // Exact match
                if (string.Equals(
                        item.Method.DeclaringType.FullName,
                        TypeName,
                        StringComparison.Ordinal))
                {
                    return(true);
                }

                // If we're matching all members of the type, include nested types
                if (MethodName == null && declaringTypeFullName.StartsWith(
                        $"{TypeName}/",
                        StringComparison.Ordinal))
                {
                    return(true);
                }

                return(false);
            }
        }
Example #2
0
            public Field(TypeSyntax type, ISymbol symbol, MemberDeclarationSyntax declaration, AttributeSyntax fieldAttribute)
            {
                string typeName = type.GetText().ToString().Split('.').Last().TrimEnd();

                TypeName    = typeName;
                ActualType  = typeName;
                IsArray     = TypeName.EndsWith("[]") || TypeName.StartsWith("List<");
                Name        = symbol.Name;
                Symbol      = symbol;
                Declaration = declaration;
                Index       = int.Parse(fieldAttribute.ArgumentList.Arguments.First().GetText().ToString());

                OriginalType = null;
                CountType    = null;
                IsAbsolute   = false;
                IsVarLength  = false;
                FixedLength  = -1;
                IsGeneric    = symbol.ContainingType.TypeParameters.Any(genericParameter => genericParameter.Name == typeName);
                var attributes = declaration.AttributeLists.SelectMany(list => list.Attributes);

                foreach (var attribute in attributes)
                {
                    switch (attribute.Name.GetText().ToString())
                    {
                    case absoluteAttribute:
                        IsAbsolute = true;
                        break;

                    case varLengthAttribute:
                        IsVarLength = true;
                        break;

                    case fixedLengthAttribute:
                        FixedLength = int.Parse(attribute.ArgumentList.Arguments.First().GetText().ToString());
                        break;

                    case actualTypeAttribute:
                        TypeName     = GetAttributeTypeArgument(attribute);
                        OriginalType = TypeName;
                        break;

                    case countType:
                        CountType = GetAttributeTypeArgument(attribute);
                        break;
                    }
                }

                if (!IsArray)
                {
                    if (IsVarLength)
                    {
                        TypeName += "_Var";
                    }
                    if (IsAbsolute)
                    {
                        TypeName += "_Abs";
                    }
                }
            }
Example #3
0
        private ParsedType(string typeName)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException(nameof(typeName));
            }

            TypeName = typeName.Trim();
            if ((TypeName.StartsWith("[")) && (TypeName.EndsWith("]")))
            {
                TypeName = TypeName.Substring(1, TypeName.Length - 2).Trim();
            }

            int asm = TypeName.IndexOf(',');

            if (asm >= 0)
            {
                AssemblyName = TypeName.Substring(asm + 1).Trim();
                TypeName     = TypeName.Substring(0, asm).Trim();
            }
        }
Example #4
0
 private bool MatchesType(AssemblyItem item)
 {
     return(TypeName.EndsWith('*')
         ? item.Method.DeclaringType.FullName.StartsWith(TypeName.Substring(0, TypeName.Length - 1), StringComparison.Ordinal)
         : string.Equals(item.Method.DeclaringType.FullName, TypeName, StringComparison.Ordinal));
 }