Beispiel #1
0
		public bool MethodSigEquals(MethodBaseSig sig, MethodBase method) {
			if (sig == null || method == null)
				return false;
			if (sig.HasThis != !method.IsStatic)
				return false;
			if (sig.Generic != method.IsGenericMethod)
				return false;
			if (sig.Generic) {
				if (sig.GenParamCount != method.GetGenericArguments().Length)
					return false;
			}
			if (method.IsMethodSpec())
				method = method.Module.ResolveMethod(method.MetadataToken) ?? method;
			var mps = method.GetParameters();
			if (sig.Params.Count != mps.Length)
				return false;

			var minfo = method as MethodInfo;
			if (minfo != null) {
				if (!Equals(sig.RetType, minfo.ReturnType))
					return false;
			}
			else {
				if (sig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void)
					return false;
			}

			for (int i = 0; i < mps.Length; i++) {
				if (!Equals(sig.Params[i], mps[i].ParameterType))
					return false;
			}

			return true;
		}
 void Add(MethodBaseSig msig)
 {
     if (msig == null)
         return;
     Add(msig.ExtraData);
     Add(msig.RetType);
     Add(msig.Params);
     Add(msig.ParamsAfterSentinel);
 }
Beispiel #3
0
 void Add(MethodBaseSig sig)
 {
     if (sig == null)
     {
         return;
     }
     Add(sig.RetType);
     Add(sig.Params);
     Add(sig.ParamsAfterSentinel);
 }
		public MethodBaseSig Create(MethodSigCreatorOptions options, MethodBaseSig origSig) {
			var data = new MethodSigCreatorVM(options);
			if (origSig is MethodSig)
				data.MethodSig = (MethodSig)origSig;
			else if (origSig is PropertySig)
				data.PropertySig = (PropertySig)origSig;
			var win = new MethodSigCreatorDlg();
			win.DataContext = data;
			win.Owner = ownerWindow ?? Application.Current.MainWindow;
			if (win.ShowDialog() != true)
				return null;

			return data.MethodBaseSig;
		}
Beispiel #5
0
        MethodSig ResolveGenericArgs(MethodBaseSig sig)
        {
            if (sig == null)
            {
                return(null);
            }
            if (!recursionCounter.Increment())
            {
                return(null);
            }

            MethodSig result = ResolveGenericArgs(new MethodSig(sig.CallingConvention), sig);

            recursionCounter.Decrement();
            return(result);
        }
Beispiel #6
0
 MethodSig ResolveGenericArgs(MethodSig sig, MethodBaseSig old)
 {
     sig.RetType = ResolveGenericArgs(old.RetType);
     foreach (var p in old.Params)
     {
         sig.Params.Add(ResolveGenericArgs(p));
     }
     sig.GenParamCount = old.GenParamCount;
     if (sig.ParamsAfterSentinel != null)
     {
         foreach (var p in old.ParamsAfterSentinel)
         {
             sig.ParamsAfterSentinel.Add(ResolveGenericArgs(p));
         }
     }
     return(sig);
 }
Beispiel #7
0
        bool ContainsGenericParameterInternal(MethodBaseSig mbs)
        {
            if (mbs == null)
            {
                return(false);
            }
            if (!recursionCounter.Increment())
            {
                return(false);
            }

            bool res = ContainsGenericParameterInternal(mbs.RetType) ||
                       ContainsGenericParameter(mbs.Params) ||
                       ContainsGenericParameter(mbs.ParamsAfterSentinel);

            recursionCounter.Decrement();
            return(res);
        }
Beispiel #8
0
        /// <summary>
        /// Resolves the method signature with the specified generic arguments.
        /// </summary>
        /// <param name="methodSig">The method signature.</param>
        /// <param name="typeGenArgs">The type generic arguments.</param>
        /// <param name="methodGenArgs">The method generic arguments.</param>
        /// <returns>Resolved method signature.</returns>
        /// <exception cref="System.ArgumentException">No generic arguments to resolve.</exception>
        public static MethodSig Resolve(MethodBaseSig methodSig, IList <TypeSig> typeGenArgs, IList <TypeSig> methodGenArgs)
        {
            if (methodSig == null)
            {
                return(null);
            }
            var resolver = new GenericArgumentResolver();

            resolver.genericArguments = new GenericArguments();
            resolver.recursionCounter = new RecursionCounter();

            if (typeGenArgs != null)
            {
                resolver.genericArguments.PushTypeArgs(typeGenArgs);
            }

            if (methodGenArgs != null)
            {
                resolver.genericArguments.PushMethodArgs(methodGenArgs);
            }

            return(resolver.ResolveGenericArgs(methodSig));
        }
 private static MethodSig Resolve(MethodBaseSig method, TypeSig typeContext)
 {
     var genericArgs = typeContext is GenericInstSig ? ((GenericInstSig)typeContext).GenericArguments : null;
     return GenericArgumentResolver.Resolve(method, genericArgs, null);
 }
Beispiel #10
0
 void Add(MethodBaseSig sig)
 {
     if (sig == null)
         return;
     Add(sig.RetType);
     Add(sig.Params);
     Add(sig.ParamsAfterSentinel);
 }
Beispiel #11
0
		bool ContainsGenericParameterInternal(MethodBaseSig mbs) {
			if (mbs == null)
				return false;
			if (!recursionCounter.Increment())
				return false;

			bool res = ContainsGenericParameterInternal(mbs.RetType) ||
				ContainsGenericParameter(mbs.Params) ||
				ContainsGenericParameter(mbs.ParamsAfterSentinel);

			recursionCounter.Decrement();
			return res;
		}
Beispiel #12
0
 /// <summary>
 /// Returns the full name of a property sig
 /// </summary>
 /// <param name="sig">Property sig</param>
 /// <param name="sb">String builder to use or null</param>
 /// <returns>Property sig full name</returns>
 public static StringBuilder MethodBaseSigFullNameSB(MethodBaseSig sig, StringBuilder sb)
 {
     var fnc = new FullNameCreator(false, null, sb);
     fnc.CreateMethodFullName(null, null, sig, null);
     return fnc.sb ?? new StringBuilder();
 }
Beispiel #13
0
 /// <summary>
 /// Gets the parameters after the sentinel
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>Parameters after sentinel or <c>null</c> if none</returns>
 public static IList <TypeSig> GetParamsAfterSentinel(this MethodBaseSig sig)
 {
     return(sig == null ? null : sig.ParamsAfterSentinel);
 }
Beispiel #14
0
 /// <summary>
 /// Gets the parameter count
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>Parameter count</returns>
 public static int GetParamCount(this MethodBaseSig sig)
 {
     return(sig == null ? 0 : sig.Params.Count);
 }
Beispiel #15
0
 /// <summary>
 /// Gets the return type
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>Return type or <c>null</c> if none</returns>
 public static TypeSig GetRetType(this MethodBaseSig sig)
 {
     return(sig == null ? null : sig.RetType);
 }
Beispiel #16
0
 /// <summary>
 /// Gets the parameters
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>The parameters</returns>
 public static IList <TypeSig> GetParams(this MethodBaseSig sig)
 {
     return(sig == null ? new List <TypeSig>() : sig.Params);
 }
Beispiel #17
0
		/// <summary>
		/// Returns the full name of a sig
		/// </summary>
		/// <param name="declType">Declaring type or null</param>
		/// <param name="name">Name or null</param>
		/// <param name="sig">Method sig</param>
		/// <param name="gppMethod">Owner method or null</param>
		/// <returns>Sig full name</returns>
		public static string MethodBaseSigFullName(string declType, string name, MethodBaseSig sig, MethodDef gppMethod) {
			var fnc = new FullNameCreator(false, null);
			fnc.CreateMethodFullName(declType, name, sig, gppMethod);
			return fnc.Result;
		}
Beispiel #18
0
		/// <summary>
		/// Returns the full name of a property sig
		/// </summary>
		/// <param name="sig">Property sig</param>
		/// <returns>Property sig full name</returns>
		public static string MethodBaseSigFullName(MethodBaseSig sig) {
			var fnc = new FullNameCreator(false, null);
			fnc.CreateMethodFullName(null, null, sig, null);
			return fnc.Result;
		}
Beispiel #19
0
 /// <summary>
 /// Returns the full name of a sig
 /// </summary>
 /// <param name="declType">Declaring type or null</param>
 /// <param name="name">Name or null</param>
 /// <param name="sig">Method sig</param>
 /// <param name="gppMethod">Owner method or null</param>
 /// <param name="sb">String builder to use or null</param>
 /// <returns>Sig full name</returns>
 public static StringBuilder MethodBaseSigFullNameSB(string declType, string name, MethodBaseSig sig, MethodDef gppMethod, StringBuilder sb)
 {
     var fnc = new FullNameCreator(false, null, sb);
     fnc.CreateMethodFullName(declType, name, sig, gppMethod);
     return fnc.sb ?? new StringBuilder();
 }
Beispiel #20
0
 /// <summary>
 /// Checks whether <paramref name="methodSig"/> contains a <see cref="GenericVar"/> or a
 /// <see cref="GenericMVar"/>.
 /// </summary>
 /// <param name="methodSig">Method or property signature</param>
 /// <returns><c>true</c> if <paramref name="methodSig"/> contains a <see cref="GenericVar"/>
 /// or a <see cref="GenericMVar"/>.</returns>
 public static bool ContainsGenericParameter(MethodBaseSig methodSig)
 {
     return(new TypeHelper().ContainsGenericParameterInternal(methodSig));
 }
Beispiel #21
0
 /// <summary>
 /// Returns the full name of a property sig
 /// </summary>
 /// <param name="sig">Property sig</param>
 /// <param name="sb">String builder to use or null</param>
 /// <returns>Property sig full name</returns>
 public static string MethodBaseSigFullName(MethodBaseSig sig, StringBuilder sb)
 {
     return MethodBaseSigFullNameSB(sig, sb).ToString();
 }
		private static MethodSig Resolve(MethodBaseSig method, TypeSig typeContext)
		{
			var args = new GenericArguments();
			if (typeContext.IsGenericInstanceType)
				args.PushTypeArgs(((GenericInstSig)typeContext).GenericArguments);
			
			var retSig = new MethodSig(method.CallingConvention);
			retSig.RetType = args.Resolve(method.RetType);
			foreach (var param in method.Params)
				retSig.Params.Add(args.Resolve(param));
			return retSig;
		}
Beispiel #23
0
 /// <summary>
 /// Gets the parameters
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>The parameters</returns>
 public static IList <TypeSig> GetParams(this MethodBaseSig sig)
 {
     return(sig == null?ThreadSafeListCreator.Create <TypeSig>() : sig.Params);
 }
Beispiel #24
0
 /// <summary>
 /// Returns the full name of a property sig
 /// </summary>
 /// <param name="sig">Property sig</param>
 /// <returns>Property sig full name</returns>
 public static string MethodBaseSigFullName(MethodBaseSig sig)
 {
     return MethodBaseSigFullNameSB(sig, null).ToString();
 }
Beispiel #25
0
 /// <summary>
 /// Gets the generic parameter count
 /// </summary>
 /// <param name="sig">this</param>
 /// <returns>Generic parameter count</returns>
 public static uint GetGenParamCount(this MethodBaseSig sig)
 {
     return(sig == null ? 0 : sig.GenParamCount);
 }
Beispiel #26
0
		/// <summary>
		/// Checks whether <paramref name="methodSig"/> contains a <see cref="GenericVar"/> or a
		/// <see cref="GenericMVar"/>.
		/// </summary>
		/// <param name="methodSig">Method or property signature</param>
		/// <returns><c>true</c> if <paramref name="methodSig"/> contains a <see cref="GenericVar"/>
		/// or a <see cref="GenericMVar"/>.</returns>
		public static bool ContainsGenericParameter(MethodBaseSig methodSig) {
			return new TypeHelper().ContainsGenericParameterInternal(methodSig);
		}
		void CreateMethodFullName(string declaringType, string name, MethodBaseSig methodSig) {
			if (methodSig == null) {
				sb.Append(NULLVALUE);
				return;
			}

			CreateFullName(methodSig.RetType);
			sb.Append(' ');
			if (declaringType != null) {
				sb.Append(declaringType);
				sb.Append("::");
			}
			if (name != null)
				sb.Append(name);

			if (methodSig.Generic) {
				sb.Append('<');
				for (int i = 0; i < methodSig.GenParamCount; i++) {
					if (i != 0)
						sb.Append(',');
					CreateFullName(new GenericMVar((uint)i));
				}
				sb.Append('>');
			}
			sb.Append('(');
			int count = PrintMethodArgList(methodSig.Params, false, false);
			PrintMethodArgList(methodSig.ParamsAfterSentinel, count > 0, true);
			sb.Append(')');
		}
Beispiel #28
0
 /// <summary>
 /// Returns the full name of a sig
 /// </summary>
 /// <param name="declType">Declaring type or null</param>
 /// <param name="name">Name or null</param>
 /// <param name="sig">Method sig</param>
 /// <param name="gppMethod">Owner method or null</param>
 /// <param name="sb">String builder to use or null</param>
 /// <returns>Sig full name</returns>
 public static string MethodBaseSigFullName(string declType, string name, MethodBaseSig sig, MethodDef gppMethod, StringBuilder sb)
 {
     return MethodBaseSigFullNameSB(declType, name, sig, gppMethod, sb).ToString();
 }