Esempio n. 1
0
 /// <summary>
 /// Creates a new <see cref="CILMethodSignature"/> that captures the signature of the current method.
 /// </summary>
 /// <param name="method">The <see cref="CILMethodBase"/>.</param>
 /// <param name="callConventions">The <see cref="UnmanagedCallingConventions"/> for the resulting <see cref="CILMethodSignature"/>.</param>
 /// <returns>The new <see cref="CILMethodSignature"/> that captures the signature of the <paramref name="method"/>.</returns>
 /// <exception cref="NullReferenceException">If <paramref name="method"/> is <c>null</c>.</exception>
 /// <exception cref="ArgumentNullException">If any type of parameters is <c>null</c>.</exception>
 public static CILMethodSignature CreateMethodSignature(this CILMethodBase method, UnmanagedCallingConventions callConventions = UnmanagedCallingConventions.C)
 {
     return(new CILMethodSignatureImpl(
                method.ReflectionContext,
                method.DeclaringType.Module,
                callConventions | (UnmanagedCallingConventions)(method.CallingConvention & CallingConventions.HasThis & CallingConventions.ExplicitThis),
                MethodKind.Method == method.MethodKind ?
                ((CILReflectionContextImpl)method.ReflectionContext).CollectionsFactory.NewListProxyFromParams(((CILMethod)method).ReturnParameter.CustomModifiers.ToArray()) :
                null,
                MethodKind.Method == method.MethodKind ?
                ((CILMethod)method).ReturnParameter.ParameterType :
                method.DeclaringType.Module.AssociatedMSCorLibModule.GetTypeByName("System.Void"),
                method.Parameters.Select(param => Tuple.Create(((CILReflectionContextImpl)method.ReflectionContext).CollectionsFactory.NewListProxyFromParams(param.CustomModifiers.ToArray()), param.ParameterType)).ToList(),
                method
                ));
 }
Esempio n. 2
0
 internal CILParameterImpl(CILReflectionContextImpl ctx, Int32 anID, CILMethodBase ownerMethod, Int32 position, String name, ParameterAttributes attrs, CILTypeBase paramType)
     : this(
         ctx,
         anID,
         new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()),
         new SettableValueForEnums <ParameterAttributes>(attrs),
         position,
         new SettableValueForClasses <String>(name),
         () => ownerMethod,
         () => paramType,
         new SettableLazy <Object>(() => null),
         new LazyWithLock <ListProxy <CILCustomModifier> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomModifier>()),
         new SettableLazy <MarshalingInfo>(() => null),
         true
         )
 {
 }
Esempio n. 3
0
        internal MethodILWriter(CILReflectionContextImpl ctx, MetaDataWriter md, CILMethodBase method, EmittingAssemblyMapper mapper)
        {
            var methodIL = (MethodILImpl)method.MethodIL;

            this._method            = method;
            this._methodIL          = methodIL;
            this._metaData          = md;
            this._assemblyMapper    = mapper;
            this._ilCode            = new Byte[methodIL._opCodes.Sum(info => info.MaxSize)];
            this._ilCodeCount       = 0;
            this._methodILOffset    = 0;
            this._opCodeInfoOffsets = new Int32[methodIL._opCodes.Count];
            this._labelInfos        = new LabelEmittingInfo[methodIL._branchTargetsCount];
            this._labelInfoIndex    = 0;

            this._stackSizes   = new Dictionary <Int32, Int32>();
            this._currentStack = 0;
            this._maxStack     = 0;
        }
Esempio n. 4
0
    /// <summary>
    /// Checks whether method contains generic parameters. See <see cref="System.Reflection.MethodBase.ContainsGenericParameters"/> property for more information about when method contains generic parameters.
    /// </summary>
    /// <param name="method">The method to check.</param>
    /// <returns><c>true</c> if method is non-<c>null</c> and contains any unassigned generic type parameters; <c>false</c> otherwise.</returns>
    /// <seealso cref="System.Reflection.MethodBase.ContainsGenericParameters"/>
    public static Boolean ContainsGenericParameters(this CILMethodBase method)
    {
        var result = false;

        if (method != null)
        {
            if (MethodKind.Method == method.MethodKind)
            {
                var mmethod = (CILMethod)method;
                result = mmethod.GenericArguments.Any(gArg => gArg.ContainsGenericParameters()) ||
                         mmethod.ReturnParameter.ParameterType.ContainsGenericParameters();
            }
            if (!result)
            {
                result = method.DeclaringType.ContainsGenericParameters() || method.Parameters.Any(param => param.ParameterType.ContainsGenericParameters());
            }
        }
        return(result);
    }
Esempio n. 5
0
 private Boolean MatchMethodAttrsAndParameters(CILMethodBase original, CILMethodBase mapped)
 {
     return(original.Attributes.IsStatic() == mapped.Attributes.IsStatic() &&
            original.Parameters.Count == mapped.Parameters.Count &&
            original.Parameters.Where((p, i) => MatchParameterTypes(p.ParameterType, mapped.Parameters[i].ParameterType)).Count() == original.Parameters.Count);
 }
Esempio n. 6
0
 public CILMethodBase MapMethodBase(CILMethodBase method)
 {
     return(MethodKind.Method == method.MethodKind ? (CILMethodBase)this.MapMethod((CILMethod)method) : this.MapConstructor((CILConstructor)method));
 }
Esempio n. 7
0
 protected override CILMethodBase MakeGenericIfNeeded(CILMethodBase method)
 {
     return(this.gArgs.Value.CQ.Any() ? ((CILMethod)method).MakeGenericMethod(this.gArgs.Value.CQ.ToArray()) : method);
 }
Esempio n. 8
0
 protected override CILMethodBase MakeGenericIfNeeded(CILMethodBase method)
 {
     return(method);
 }
Esempio n. 9
0
 protected abstract CILMethodBase MakeGenericIfNeeded(CILMethodBase method);
Esempio n. 10
0
 /// <summary>
 /// Returns the name of the method. For <see cref="CILConstructor"/>s it will be either <c>.ctor</c> for instance constructors or <c>.cctor</c> for static constructors.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <returns>The name of the method.</returns>
 /// <exception cref="ArgumentNullException">If <paramref name="method"/> is <c>null</c>.</exception>
 public static String GetName(this CILMethodBase method)
 {
     ArgumentValidator.ValidateNotNull("Method", method);
     return(MethodKind.Method == method.MethodKind ? ((CILMethod)method).Name : (method.Attributes.IsStatic() ? CILConstructorImpl.STATIC_CTOR_NAME : CILConstructorImpl.INSTANCE_CTOR_NAME));
 }
Esempio n. 11
0
 /// <summary>
 /// Checks whether method is a generic method. The method is considered to be generic method if either its declaring type is generic or the method has any generic parameters. This method returns same result as <see cref="System.Reflection.MethodBase.IsGenericMethod"/> property.
 /// </summary>
 /// <param name="method">The method to check.</param>
 /// <returns><c>true</c> if the <paramref name="method"/> is non-<c>null</c> and is generic method; <c>false</c> otherwise.</returns>
 /// <seealso cref="System.Reflection.MethodBase.IsGenericMethod"/>
 public static Boolean IsGenericMethod(this CILMethodBase method)
 {
     return(method != null && method.DeclaringType.IsGenericType() || (MethodKind.Method == method.MethodKind && ((CILMethod)method).GenericArguments.Any()));
 }
Esempio n. 12
0
 /// <summary>
 /// Checks whether the method is eligible to have method body. See ECMA specification (condition 33 for MethodDef table) for exact condition of methods having method bodies. In addition to that, the <see cref="E_CIL.IsIL"/> must return <c>true</c>.
 /// </summary>
 /// <param name="method">The method to check.</param>
 /// <returns><c>true</c> if the <paramref name="method"/> is non-<c>null</c> and can have IL method body; <c>false</c> otherwise.</returns>
 /// <seealso cref="E_CIL.IsIL"/>
 /// <seealso cref="E_CIL.CanEmitIL"/>
 public static Boolean HasILMethodBody(this CILMethodBase method)
 {
     return(method != null && method.Attributes.CanEmitIL() && method.ImplementationAttributes.IsIL());
 }