Пример #1
0
        /// <inheritdoc/>
        internal override bool IsEquivalentToNewMember(MemberDataBase newMember, AssemblyFamily newAssemblyFamily)
        {
            if (base.IsEquivalentToNewMember(newMember, newAssemblyFamily) == false)
            {
                return(false);
            }

            var other = newMember as ConstructedGenericTypeData;

            if (other == null)
            {
                return(false);
            }

            if (GenericTypeDefinition.IsEquivalentToNew(other.GenericTypeDefinition, newAssemblyFamily) == false)
            {
                return(false);
            }

            if (GenericArguments.Count != other.GenericArguments.Count)
            {
                return(false);
            }

            for (int i = 0; i < GenericArguments.Count; i++)
            {
                if (GenericArguments[i].IsEquivalentToNewMember(other.GenericArguments[i], newAssemblyFamily) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
 private void ValidateProps()
 {
     if (GenericTypeDefinition == null)
     {
         throw new InvalidOperationException(
                   $"ProtoCMS: generic type definition required.");
     }
     if (!GenericTypeDefinition.IsGenericTypeDefinition)
     {
         throw new InvalidOperationException(
                   $"ProtoCMS: provided type is not a generic type definition.");
     }
     if (GenericTypeArgumentsMatcher == null)
     {
         throw new InvalidOperationException(
                   $"ProtoCMS: generic type arguments matcher is required.");
     }
     if (GenericTypeDefinition.GetGenericArguments().Length != GenericTypeArgumentsMatcher.Length)
     {
         throw new InvalidOperationException(
                   $"ProtoCMS: generic type arguments matcher length is different than expected arguments length of " +
                   $"the generic type definition.");
     }
     if (GenericTypeArgumentsMatcher.Any(x => x == null))
     {
         throw new InvalidOperationException(
                   $"ProtoCMS: generic type arguments matcher must not have null item.");
     }
 }
Пример #3
0
        internal void FinalizeDefiniton()
        {
            var genericParameters = GenericTypeDefinition.GenericParameters;

            if (GenericTypeDefinition.BaseType != null)
            {
                BaseType = (DeclaringTypeData)GenericTypeDefinition.BaseType.ReplaceGenericTypeParameters(genericParameters, GenericArguments);
            }

            ImplementedInterfaces = new ImplementedInterfacesCollection(
                GenericTypeDefinition.ImplementedInterfaces.Select(i => (DeclaringTypeData)i.ReplaceGenericTypeParameters(genericParameters, GenericArguments))
                );

            if (TypeKind == Microsoft.CodeAnalysis.TypeKind.Delegate)
            {
                var invokeMethod = (MethodData)GenericTypeDefinition.GetMethod("Invoke").ReplaceGenericTypeParameters(genericParameters, GenericArguments);
                DelegateParameters          = invokeMethod.Parameters;
                DelegateReturnType          = invokeMethod.Type;
                DelegateReturnTypeIsDynamic = invokeMethod.IsTypeDynamic;
            }
            else
            {
                foreach (var member in GenericTypeDefinition.GetMembers().Where(m => m.MetadataItemKind != MetadataItemKinds.TypeDefinition))
                {
                    AddMember(member.ReplaceGenericTypeParameters(genericParameters, GenericArguments));
                }
            }
        }
Пример #4
0
        public TypeDeclaration GetType(string typeName, TypeDeclaration[] genericParameters)
        {
            TypeDeclaration type = null;

            if (_types.TryGetValue(typeName, out type))
            {
                if (genericParameters != null && type.IsGenericTypeDefinition)
                {
                    GenericTypeDefinition genTypeDef = (GenericTypeDefinition)type;
                    type = genTypeDef.ResolveGenerics(genericParameters);
                }
                type.IsUsed = true;
                if (!type.IsBuildIn && !type.IsChecked)
                {
                    type.CheckSemantic(this, Log);
                    type.IsChecked = true;
                }
            }
            else if (_parent != null)
            {
                type = _parent.GetType(typeName, genericParameters);
            }

            return(type);
        }
Пример #5
0
        /// <inheritdoc/>
        internal override MemberDataBase ReplaceGenericTypeParameters(GenericTypeParameterCollection genericParameters, GenericTypeArgumentCollection genericArguments)
        {
            List <TypeData> replacedGenericArguments = null;

            for (int i = 0; i < GenericArguments.Count; i++)
            {
                var currentArgument  = GenericArguments[i];
                var replacedArgument = (TypeData)currentArgument.ReplaceGenericTypeParameters(genericParameters, genericArguments);
                if (replacedArgument == currentArgument)
                {
                    continue;
                }

                if (replacedGenericArguments == null)
                {
                    replacedGenericArguments = new List <TypeData>(GenericArguments);
                }

                replacedGenericArguments[i] = replacedArgument;
            }

            if (replacedGenericArguments != null)
            {
                return(GenericTypeDefinition.GetConstructedGenericTypeData(replacedGenericArguments));
            }

            return(this);
        }
Пример #6
0
        /// <inheritdoc/>
        internal override string GetNamespaceName()
        {
            // For nullable types, we want to get the namespace of the underlying type, not the System.Nullable<T> type, because it will be displayed as T?.
            if (IsNullable(out TypeData underlyingType))
            {
                return(underlyingType.GetNamespaceName());
            }

            return(GenericTypeDefinition.GetNamespaceName());
        }
            public override int GetHashCode()
            {
                int hashCode = GenericTypeDefinition.GetHashCode();

                for (int i = 0; i < GenericTypeArguments.Length; i++)
                {
                    hashCode ^= GenericTypeArguments[i].GetHashCode();
                }
                return(hashCode);
            }
Пример #8
0
        public void finding_generic_arguments_should_add_error_when_multiple_matching_types_are_found()
        {
            var typeDefinition = new GenericTypeDefinition {
                OpenTypeName = "FubuMVC.Spark.Tests.SparkModel.Binding.Generic`1", ArgumentTypeNames = new[] { "FubuMVC.Spark.Tests.SparkModel.Binding.Duplicated" }
            };

            var result = ClassUnderTest.findGenericArgumentTypes(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("More than one generic argument types matching");
        }
Пример #9
0
        public void finding_generic_arguments_should_add_error_when_no_matching_type_is_found()
        {
            var typeDefinition = new GenericTypeDefinition {
                OpenTypeName = "FubuMVC.Spark.Tests.SparkModel.Binding.Generic`1", ArgumentTypeNames = new[] { "NOTFOUND" }
            };

            var result = ClassUnderTest.findGenericArgumentTypes(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("No generic argument type matching");
        }
Пример #10
0
        public void finding_open_type_should_add_error_when_no_matching_type_is_found()
        {
            var typeDefinition = new GenericTypeDefinition {
                OpenTypeName = "NotFound", ArgumentTypeNames = new[] { "System.String" }
            };

            var result = ClassUnderTest.findOpenType(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("No generic type matching");
        }
Пример #11
0
        public void finding_open_type_should_add_error_when_multiple_matching_types_are_found()
        {
            var typeDefinition = new GenericTypeDefinition {
                OpenTypeName = "FubuMVC.Tests.View.Registration.DuplicatedGeneric`1", ArgumentTypeNames = new[] { "System.String" }
            };

            var result = ClassUnderTest.findOpenType(typeDefinition);

            result.ShouldBeNull();
            ClassUnderTest.ParseErrors.First().ShouldContain("More than one generic types matching");
        }
Пример #12
0
        /// <summary>
        /// Indicates whether the type is an IList&lt;T&gt; constructed generic type.
        /// </summary>
        private bool IsIListGenericType(out TypeData elementType)
        {
            if (GenericArguments.Count == 1 &&
                GenericTypeDefinition.IsType(typeof(IList <>)))
            {
                elementType = GenericArguments[0];
                return(true);
            }

            elementType = null;
            return(false);
        }
Пример #13
0
        /// <inheritdoc/>
        internal override string GetDisplayName(bool fullyQualify, bool includeGenericInfo, GenericTypeArgumentCollection genericArguments)
        {
            if (IsNullable(out TypeData underlyingType))
            {
                return(underlyingType.GetDisplayName(fullyQualify: false, includeGenericInfo: includeGenericInfo) + '?');
            }

            var genericArgumentsResolved = genericArguments ?? GenericArguments;

            var rootName = GenericTypeDefinition.GetDisplayName(fullyQualify: false, includeGenericInfo: false);

            if (includeGenericInfo)
            {
                var parentGenericArgumentCount = ContainingType == null ? 0 : ContainingType.GenericArity;
                rootName += genericArgumentsResolved.GetGenericArgumentListDisplayText(includeGenericInfo, parentGenericArgumentCount, GenericArguments.Count - parentGenericArgumentCount);
            }

            return(PostProcessUnqualifiedName(rootName, fullyQualify, includeGenericInfo, genericArgumentsResolved));
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = BooleanFalse.GetHashCode();
         hashCode = (hashCode * 397) ^ BooleanTrue.GetHashCode();
         hashCode = (hashCode * 397) ^ Char.GetHashCode();
         hashCode = (hashCode * 397) ^ SByte.GetHashCode();
         hashCode = (hashCode * 397) ^ Byte.GetHashCode();
         hashCode = (hashCode * 397) ^ Int16.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt16.GetHashCode();
         hashCode = (hashCode * 397) ^ Int32;
         hashCode = (hashCode * 397) ^ (int)UInt32;
         hashCode = (hashCode * 397) ^ Int64.GetHashCode();
         hashCode = (hashCode * 397) ^ UInt64.GetHashCode();
         hashCode = (hashCode * 397) ^ Single.GetHashCode();
         hashCode = (hashCode * 397) ^ Double.GetHashCode();
         hashCode = (hashCode * 397) ^ Decimal.GetHashCode();
         hashCode = (hashCode * 397) ^ String.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTime.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeOffset.GetHashCode();
         hashCode = (hashCode * 397) ^ Guid.GetHashCode();
         hashCode = (hashCode * 397) ^ NonGenericType.GetHashCode();
         hashCode = (hashCode * 397) ^ GenericTypeDefinition.GetHashCode();
         hashCode = (hashCode * 397) ^ ClosedConstructedGenericType.GetHashCode();
         hashCode = (hashCode * 397) ^ (NullReference != null ? NullReference.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Enum_S8.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_U8.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_S16.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_U16.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_S32.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_U32.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_S64.GetHashCode();
         hashCode = (hashCode * 397) ^ Enum_U64.GetHashCode();
         hashCode = (hashCode * 397) ^ SerializableObject.GetHashCode();
         hashCode = (hashCode * 397) ^ ByteArrayEqualityComparer.GetHashCode(Buffer1);
         hashCode = (hashCode * 397) ^ ByteArrayEqualityComparer.GetHashCode(Buffer2);
         return(hashCode);
     }
 }
            public bool Equals(UnificationKey other)
            {
                if (!GenericTypeDefinition.Equals(other.GenericTypeDefinition))
                {
                    return(false);
                }
                if (GenericTypeArguments.Length != other.GenericTypeArguments.Length)
                {
                    return(false);
                }
                for (int i = 0; i < GenericTypeArguments.Length; i++)
                {
                    if (!(GenericTypeArguments[i].Equals(other.GenericTypeArguments[i])))
                    {
                        return(false);
                    }
                }

                // The TypeHandle is not actually part of the key but riding along for convenience (see commment at head of class.)
                // If the other parts of the key matched, this must too.
                Debug.Assert(TypeHandle.Equals(other.TypeHandle));
                return(true);
            }
Пример #16
0
        /// <inheritdoc/>
        internal override TypeData GetEquivalentNewType(AssemblyFamily newAssemblyFamily)
        {
            var newGenericTypeDefinition = (TypeDefinitionData)GenericTypeDefinition.GetEquivalentNewType(newAssemblyFamily);

            if (newGenericTypeDefinition == null)
            {
                return(null);
            }

            var newGenericArguments = new TypeData[GenericArguments.Count];

            for (int i = 0; i < GenericArguments.Count; i++)
            {
                var newGenericArgument = GenericArguments[i].GetEquivalentNewType(newAssemblyFamily);
                if (newGenericArgument == null)
                {
                    return(null);
                }

                newGenericArguments[i] = newGenericArgument;
            }

            return(newGenericTypeDefinition.GetConstructedGenericTypeData(newGenericArguments));
        }
Пример #17
0
 public override Type?GetChildDataContextType(Type dataContext, DataContextStack controlContextStack, DotvvmBindableObject control, DotvvmProperty?property = null)
 {
     return(GenericTypeDefinition.MakeGenericType(dataContext));
 }
Пример #18
0
 /// <inherit />
 public override int GetHashCode() => GenericTypeDefinition.GetHashCode();