Ejemplo n.º 1
0
        /// <summary>
        ///     Is true when the two SliceIdentifiers belong to the same slice
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool CompareTo(SliceIdentifier other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Ignored && other.Ignored || !Ignored && !other.Ignored && Identifier == other.Identifier);
        }
Ejemplo n.º 2
0
 private bool Equals(SliceIdentifier other)
 {
     return(Identifier == other.Identifier && Ignored == other.Ignored);
 }
Ejemplo n.º 3
0
        private static SliceIdentifier AssignFunc(IType type, string pattern)
        {
            var containsSingleAsterisk   = pattern.Contains("(*)");
            var containsDoubleAsterisk   = pattern.Contains("(**)");
            var indexOfAsteriskInPattern = pattern.IndexOf("(*", StringComparison.Ordinal);

            if (!containsSingleAsterisk && !containsDoubleAsterisk)
            {
                throw new ArgumentException("Patterns for Slices have to contain (*) or (**).");
            }

            if (indexOfAsteriskInPattern != pattern.LastIndexOf("(*", StringComparison.Ordinal))
            {
                throw new ArgumentException("Patterns for Slices can only contain (*) or (**) once.");
            }

            var namespc      = type.Namespace.FullName;
            var slicePrefix  = pattern.Remove(indexOfAsteriskInPattern);
            var slicePostfix = pattern.Substring(pattern.IndexOf("*)", StringComparison.Ordinal) + 2);

            if (slicePrefix.StartsWith("."))
            {
                slicePrefix = slicePrefix.Substring(1);
                if (!namespc.Contains(slicePrefix))
                {
                    return(SliceIdentifier.Ignore());
                }
            }
            else if (!namespc.StartsWith(slicePrefix))
            {
                return(SliceIdentifier.Ignore());
            }

            if (slicePostfix.EndsWith("."))
            {
                slicePostfix = slicePostfix.Remove(slicePostfix.Length - 1);
                if (!namespc.Substring(namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + slicePrefix.Length)
                    .Contains(slicePostfix))
                {
                    return(SliceIdentifier.Ignore());
                }
            }
            else if (!namespc.EndsWith(slicePostfix))
            {
                return(SliceIdentifier.Ignore());
            }

            var sliceString = namespc;

            if (slicePrefix != "")
            {
                sliceString = namespc
                              .Substring(namespc.IndexOf(slicePrefix, StringComparison.Ordinal) + slicePrefix.Length)
                              .TrimStart('.');
            }

            if (!sliceString.Contains(slicePostfix))
            {
                throw new ArgumentException("\"" + type.FullName +
                                            "\" is not clearly assignable to a slice with the pattern: \"" +
                                            pattern + "\"");
            }

            if (slicePostfix == "")
            {
                if (containsSingleAsterisk && sliceString.IndexOf(".", StringComparison.Ordinal) >= 0)
                {
                    sliceString = sliceString.Remove(sliceString.IndexOf(".", StringComparison.Ordinal));
                }
            }
            else
            {
                sliceString = sliceString.Remove(sliceString.IndexOf(slicePostfix, StringComparison.Ordinal));
                if (containsSingleAsterisk && sliceString.Trim('.').Contains("."))
                {
                    return(SliceIdentifier.Ignore());
                }
            }

            return(SliceIdentifier.Of(sliceString));
        }
Ejemplo n.º 4
0
 public Slice(SliceIdentifier identifier, IEnumerable <IType> types)
 {
     Identifier = identifier;
     Types      = types;
 }