Beispiel #1
0
 /// <summary>
 /// Creates a new reference to a member in an (external) .NET assembly.
 /// </summary>
 /// <param name="parent">The declaring member that defines the referenced member.</param>
 /// <param name="name">The name of the referenced member.</param>
 /// <param name="signature">The signature of the referenced member. This dictates whether the
 /// referenced member is a field or a method.</param>
 public MemberReference(IMemberRefParent parent, string name, MemberSignature signature)
     : this(new MetadataToken(TableIndex.MemberRef, 0))
 {
     Parent    = parent;
     Name      = name;
     Signature = signature;
 }
Beispiel #2
0
 public MemberReference(IMemberRefParent parent, string name, MemberSignature signature)
     : base(null, new MetadataToken(MetadataTokenType.MemberRef), new MetadataRow <uint, uint, uint>())
 {
     _parent    = new LazyValue <IMemberRefParent>(parent);
     _name      = new LazyValue <string>(name);
     _signature = new LazyValue <MemberSignature>(signature);
 }
Beispiel #3
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            ITypeDeclaration typeDeclaration = GetTargetTypeDeclaration(_highlighting.BaseClass);

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

            MemberSignature signature = CreateTransformTextSignature(typeDeclaration);
            TypeTarget      target    = CreateTarget(typeDeclaration);

            var context = new CreateMethodDeclarationContext {
                AccessRights = AccessRights.PUBLIC,
                ExecuteTemplateOverMemberBody = false,
                ExecuteTemplateOverName       = false,
                ExecuteTemplateOverParameters = false,
                ExecuteTemplateOverReturnType = false,
                IsAbstract       = true,
                IsStatic         = false,
                MethodSignatures = new[] { signature },
                MethodName       = T4CSharpIntermediateConverterBase.TransformTextMethodName,
                SourceReferenceExpressionReference = null,
                Target = target,
            };

            IntentionResult intentionResult = MethodDeclarationBuilder.Create(context);

            intentionResult.ExecuteTemplate();
            return(null);
        }
            public override bool Equals(object obj)
            {
                MemberSignature memberSignature = obj as MemberSignature;

                if ((memberSignature == null) ||
                    (this.name != memberSignature.Name) ||
                    (this.returnType != memberSignature.ReturnType))
                {
                    return(false);
                }

                if ((this.Parameters == null) && (memberSignature.Parameters != null) ||
                    (this.Parameters != null) && (memberSignature.Parameters == null))
                {
                    return(false);
                }

                if (this.Parameters != null)
                {
                    if (this.parameters.Length != memberSignature.parameters.Length)
                    {
                        return(false);
                    }

                    for (int loop = 0; loop < this.parameters.Length; loop++)
                    {
                        if (this.parameters[loop] != memberSignature.parameters[loop])
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
        internal void AddMethod(ContractMethodInfo methodInfo)
        {
            if (methodInfo == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("methodInfo");
            }

            MemberSignature signature = new MemberSignature(methodInfo);

            if (this.GetMemberHelper <MethodInfo>(BindingFlags.Public | BindingFlags.Instance,
                                                  signature,
                                                  ref this.methods) != null)
            {
                return;
            }
            else
            {
                List <MethodInfo> localMethods = new List <MethodInfo>();
                if (this.methods != null)
                {
                    localMethods.AddRange(this.methods);
                }
                localMethods.Add(methodInfo);
                this.methods = new MethodInfo[localMethods.Count];
                localMethods.CopyTo(this.methods);
            }
        }
Beispiel #6
0
 public MemberReference(IMemberRefParent parent, string name, MemberSignature signature)
     : base(new MetadataToken(MetadataTokenType.MemberRef))
 {
     _parent          = new LazyValue <IMemberRefParent>(parent);
     _name            = new LazyValue <string>(name);
     _signature       = new LazyValue <MemberSignature>(signature);
     CustomAttributes = new CustomAttributeCollection(this);
 }
        // generic method that implements all GetXXXs methods
        private T[] GetMembersHelper <T>(BindingFlags bindingAttr, ref T[] members, bool searchBase)
            where T : MemberInfo
        {
            Dictionary <MemberSignature, T> membersDictionary = new Dictionary <MemberSignature, T>();

            if (members != null)
            {
                // get local properties
                foreach (T memberInfo in members)
                {
                    MemberSignature memberSignature = new MemberSignature(memberInfo);

                    if ((FilterMember(memberInfo, bindingAttr)) && (!membersDictionary.ContainsKey(memberSignature)))
                    {
                        membersDictionary.Add(new MemberSignature(memberInfo), memberInfo);
                    }
                }
            }

            if (searchBase && (bindingAttr & BindingFlags.DeclaredOnly) == 0)
            {
                // FlattenHierarchy is required to return static members from base classes.
                if ((bindingAttr & BindingFlags.FlattenHierarchy) == 0)
                {
                    bindingAttr &= ~BindingFlags.Static;
                }

                //    Type baseType = BaseType;
                //    if (baseType != null)
                //    {
                //        T[] baseMembers = GetBaseMembers(typeof(T), baseType, bindingAttr) as T[];

                //        foreach (T memberInfo in baseMembers)
                //        {
                //            // We should not return private members from base classes. Note: Generics requires us to use "as".
                //            if ((memberInfo is FieldInfo && (memberInfo as FieldInfo).IsPrivate) || (memberInfo is MethodBase && (memberInfo as MethodBase).IsPrivate) || (memberInfo is Type && (memberInfo as Type).IsNestedPrivate))
                //            {
                //                continue;
                //            }

                //            // verify a member with this signature was not already created
                //            MemberSignature memberSignature = new MemberSignature(memberInfo);

                //            if (!membersDictionary.ContainsKey(memberSignature))
                //            {
                //                membersDictionary.Add(memberSignature, memberInfo);
                //            }
                //        }
                //    }
            }

            List <T> memberCollection = new List <T>(membersDictionary.Values);

            return(memberCollection.ToArray());
        }
Beispiel #8
0
        private static void VerifyMatching(MemberSignature original, MemberSignature expected, params MemberSignature[] fails)
        {
            Assert.IsTrue(_comparer.MatchMemberSignatures(original, expected), "The original signature did not match the expected.");
            Assert.IsTrue(_comparer.MatchMemberSignatures(expected, original), "The expected signature did not match the original.");

            foreach (var fail in fails)
            {
                Assert.IsFalse(_comparer.MatchMemberSignatures(original, fail), original + " matched " + fail);
                Assert.IsFalse(_comparer.MatchMemberSignatures(fail, original), fail + " matched " + original);
            }
        }
        /// <inheritdoc />
        public MemberSignature ImportMemberSignature(MemberSignature signature)
        {
            switch (signature)
            {
            case FieldSignature fieldSignature:
                return(ImportFieldSignature(fieldSignature));

            case MethodSignature methodSignature:
                return(ImportMethodSignature(methodSignature));

            default:
                throw new NotSupportedException();
            }
        }
        private T[] GetMembersHelper <T>(BindingFlags bindingAttr, MemberSignature memberSignature, ref T[] members)
            where T : MemberInfo
        {
            List <T> memberCandidates = new List <T>();

            foreach (T memberInfo in this.GetMembersHelper <T>(bindingAttr, ref members, true))
            {
                MemberSignature candididateMemberSignature = new MemberSignature(memberInfo);
                if (candididateMemberSignature.FilterSignature(memberSignature))
                {
                    memberCandidates.Add(memberInfo);
                }
            }
            return(memberCandidates.ToArray());
        }
        //private MemberInfo[] GetBaseMembers(Type type, Type baseType, BindingFlags bindingAttr)
        //{
        //    MemberInfo[] members = null;
        //    if (type == typeof(PropertyInfo))
        //    {
        //        members = baseType.GetProperties(bindingAttr);
        //    }
        //    else if (type == typeof(EventInfo))
        //    {
        //        members = baseType.GetEvents(bindingAttr);
        //    }
        //    else if (type == typeof(ConstructorInfo))
        //    {
        //        members = baseType.GetConstructors(bindingAttr);
        //    }
        //    else if (type == typeof(MethodInfo))
        //    {
        //        members = baseType.GetMethods(bindingAttr);
        //    }
        //    else if (type == typeof(FieldInfo))
        //    {
        //        members = baseType.GetFields(bindingAttr);
        //    }
        //    else if (type == typeof(Type))
        //    {
        //        members = baseType.GetNestedTypes(bindingAttr);
        //    }

        //    return members;
        //}

        // generic method that implements all GetXXX methods
        private T GetMemberHelper <T>(BindingFlags bindingAttr, MemberSignature memberSignature, ref T[] members)
            where T : MemberInfo
        {
            if (members != null)
            {
                // search the local type
                foreach (T memberInfo in members)
                {
                    MemberSignature candididateMemberSignature = new MemberSignature(memberInfo);
                    if (candididateMemberSignature.FilterSignature(memberSignature) && FilterMember(memberInfo, bindingAttr))
                    {
                        return(memberInfo);
                    }
                }
            }

            return(null);
        }
Beispiel #12
0
        public MemberSignature ImportMemberSignature(MemberSignature signature)
        {
            var fieldSignature = signature as FieldSignature;

            if (fieldSignature != null)
            {
                return(ImportFieldSignature(fieldSignature));
            }

            var methodSignature = signature as MethodSignature;

            if (methodSignature != null)
            {
                return(ImportMethodSignature(methodSignature));
            }

            throw new NotSupportedException();
        }
Beispiel #13
0
        internal static void RegisterDeclaredEntity(IEntity entity, MemberSignature member)
        {
            switch (member)
            {
            case FieldSignature field:
                fieldSignatureCache.Add((IField)entity, field);
                break;

            case MethodSignature method:
                methodSignatureCache.Add((IMethod)entity, method);
                break;

            case PropertySignature property:
                propSignatureCache.Add((IProperty)entity, property);
                break;

            case TypeSignature type:
                typeSignatureCache.Add((ITypeDefinition)entity, type);
                break;

            default:
                throw new NotSupportedException($"{member.GetType()} {entity.GetType()}");
            }
        }
            // this method will filter using a mask signautre. only non-null mask members are used to filter
            // the signature, the rest are ignored
            public bool FilterSignature(MemberSignature maskSignature)
            {
                if (maskSignature == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("maskSignature");
                }

                if (((maskSignature.Name != null) && (this.name != maskSignature.name)) ||
                    ((maskSignature.returnType != null) && (this.returnType != maskSignature.returnType)))
                {
                    return(false);
                }

                if (maskSignature.parameters != null)
                {
                    if (this.parameters == null)
                    {
                        return(false);
                    }

                    if (this.parameters.Length != maskSignature.parameters.Length)
                    {
                        return(false);
                    }

                    for (int loop = 0; loop < this.parameters.Length; loop++)
                    {
                        if (!this.parameters[loop].Equals(maskSignature.parameters[loop]))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
Beispiel #15
0
 /// <summary> Gets declaring type of the specified member. It is has no declaring type (e.g. a type in namespace), `null` is returned. </summary>
 public static TypeSignature DeclaringType(this MemberSignature member) =>
 member switch
 {
Beispiel #16
0
 public static bool IsSpecial(MemberSignature m) => (m as MethodSignature)?.HasSpecialName == true || m.Name.StartsWith("<");