Esempio n. 1
0
        public bool Equals(MemberReference lhs, MemberReference rhs, ITypeInfoSource typeInfo)
        {
            if ((lhs == null) || (rhs == null))
            {
                return(lhs == rhs);
            }

            if (lhs == rhs)
            {
                return(true);
            }

            var declaringType = rhs.DeclaringType.Resolve();

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

            var rhsType = new TypeIdentifier(declaringType);

            if (!Type.Equals(rhsType))
            {
                return(false);
            }

            var rhsMember = MemberIdentifier.New(typeInfo, rhs);

            return(Member.Equals(rhsMember, typeInfo));
        }
Esempio n. 2
0
 public override bool Equals(object obj)
 {
     return(obj is NetworkPacket entity &&
            EqualityComparer <Uri> .Default.Equals(Source, entity.Source) &&
            TypeIdentifier.Equals(entity.TypeIdentifier) &&
            EqualityComparer <object> .Default.Equals(Entity, entity.Entity));
 }
        // The following method is called when any control is dropped over custom button
        // from toolbox. It checks if custombutton can take this child or not.
        // It might be called at other times too.
        public override bool CanParent(ModelItem parent, TypeIdentifier childType)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            if (childType == null)
            {
                throw new ArgumentNullException("childType");
            }

            return(childType.Equals(new TypeIdentifier("System.Windows.Controls.TextBox")));
        }
Esempio n. 4
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, (MethodReference)gp.Owner);
                    var memberIdentifier = new MemberIdentifier(typeInfo, (dynamic)member);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType = member.DeclaringType.Resolve();
                    // FIXME: Is this right?
                    if (declaringType == null)
                    {
                        return(type);
                    }

                    var ownerResolved = ((TypeReference)gp.Owner).Resolve();
                    // FIXME: Is this right?
                    if (ownerResolved == null)
                    {
                        return(type);
                    }

                    var ownerIdentifier = new TypeIdentifier(ownerResolved);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }
Esempio n. 5
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, gp.Owner as MethodReference);
                    var memberIdentifier = new MemberIdentifier(typeInfo, member as dynamic);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType   = member.DeclaringType;
                    var ownerIdentifier = new TypeIdentifier(gp.Owner as TypeReference);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }
Esempio n. 6
0
        protected TypeInfo ConstructTypeInformation(TypeIdentifier identifier, TypeDefinition type, Dictionary <TypeIdentifier, TypeDefinition> moreTypes)
        {
            var moduleInfo = GetModuleInformation(type.Module);

            TypeInfo baseType = null, declaringType = null;

            if (type.BaseType != null)
            {
                baseType = GetExisting(type.BaseType);
                if (baseType == null)
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Missing type info for base type '{0}' of type '{1}'",
                                                            type.BaseType, type
                                                            ));
                }
            }

            if (type.DeclaringType != null)
            {
                declaringType = GetExisting(type.DeclaringType);
                if (declaringType == null)
                {
                    throw new InvalidOperationException(String.Format(
                                                            "Missing type info for declaring type '{0}' of type '{1}'",
                                                            type.DeclaringType, type
                                                            ));
                }
            }

            var result = new TypeInfo(this, moduleInfo, type, declaringType, baseType, identifier);

            Action <TypeReference> addType = (tr) => {
                if (tr == null)
                {
                    return;
                }

                var td = TypeUtil.GetTypeDefinition(tr);
                if (td == null)
                {
                    return;
                }

                var _identifier = new TypeIdentifier(td);
                if (_identifier.Equals(identifier))
                {
                    return;
                }
                else if (moreTypes.ContainsKey(_identifier))
                {
                    return;
                }

                moreTypes[_identifier] = td;
            };

            foreach (var member in result.Members.Values)
            {
                addType(member.ReturnType);

                var method = member as Internal.MethodInfo;
                if (method != null)
                {
                    foreach (var p in method.Member.Parameters)
                    {
                        addType(p.ParameterType);
                    }
                }
            }

            return(result);
        }