public void EmitNewObject(ConstructorInfo ci)
        {
            ProcessCommand(
                OpCodes.Newobj,
                ci.GetParameters().Length * -1 + 1,
                ci.ToString()
                );

            ilGenerator.Emit(OpCodes.Newobj, ci);
        }
Example #2
0
    public IEnumerable<string> GetCommentLines(ConstructorInfo constructor)
    {
      string memberName = "M:" + constructor.DeclaringType.FullName + ".#" + constructor.ToString().Substring(6);
      memberName = memberName.Replace("()", "");
      memberName = memberName.Replace(", ", ",");
      memberName = memberName.Replace("Boolean", "System.Boolean");
      memberName = memberName.Replace("Double", "System.Double");
      memberName = memberName.Replace("Int32", "System.Int32");
      if (memberName.Contains("IEnumerable"))
      {
        memberName = memberName.Replace("`1[", "{");
        memberName = memberName.Replace("])", "})");
      }

      var comment = _Comments.XPathSelectElement("/doc/members/member[@name='" + memberName + "']");
      if (comment == null)
        throw new NotImplementedException(memberName);

      foreach (var node in comment.Nodes())
      {
        foreach (string line in node.ToString().Split('\n'))
          yield return "/// " + line.Trim();
      }
    }
Example #3
0
 internal void New(ConstructorInfo constructorInfo)
 {
     if (_codeGenTrace != CodeGenTrace.None)
         EmitSourceInstruction("Newobj " + constructorInfo.ToString() + " on type " + constructorInfo.DeclaringType.ToString());
     _ilGen.Emit(OpCodes.Newobj, constructorInfo);
 }
Example #4
0
 internal void Call(ConstructorInfo ctor)
 {
     if (_codeGenTrace != CodeGenTrace.None)
         EmitSourceInstruction("Call " + ctor.ToString() + " on type " + ctor.DeclaringType.ToString());
     _ilGen.Emit(OpCodes.Call, ctor);
 }
Example #5
0
 public bool OkToUse(ConstructorInfo c, out string message)
 {
     if (c == null) throw new ArgumentNullException("c");
     string toCheckStr = c.DeclaringType.ToString() + "." + c.ToString(); //[email protected]
     return OkToUseInternal(toCheckStr, this.require_members, this.forbid_members, out message); //[email protected]
     //return OkToUseInternal(c.ToString(), this.require_members, this.forbid_members, out message); //[email protected]
 }
Example #6
0
        public bool OkToUse(ConstructorInfo c, out string message)
        {

            if (c.DeclaringType.IsAbstract)
            {
                message = "Will not use: constructor's declaring type is abstract: " + c.ToString();
                return false;
            }

            return OkToUseBase(c, out message);
        }
Example #7
0
 public static void GetSerializationInfo(SerializationInfo info, ConstructorInfo c)
 {
     GetSerializationInfo(info, c.Name, c.ReflectedType, c.ToString(), c.SerializationToString(), MemberTypes.Constructor, genericArguments: null);
 }
        protected virtual bool Match(ConstructorInfo ctor, Type type)
        {
            switch (type.Name) {
            case "MKTileOverlayRenderer":
                // NSInvalidArgumentEception Expected a MKTileOverlay
                // looks like Apple has not yet added a DI for this type, but it should be `initWithTileOverlay:`
                if (ctor.ToString () == "Void .ctor(IMKOverlay)")
                    return true;
                break;
            case "MPSImageHistogram":
                // Could not initialize an instance of the type 'MetalPerformanceShaders.MPSImageHistogram': the native 'initWithDevice:' method returned nil.
                // make sense: there's a `initWithDevice:histogramInfo:` DI
                if (ctor.ToString () == "Void .ctor(IMTLDevice)")
                    return true;
                break;
            case "NSDataDetector":
                // -[NSDataDetector initWithPattern:options:error:]: Not valid for NSDataDetector
                if (ctor.ToString () == "Void .ctor(NSString, NSRegularExpressionOptions, NSError&)")
                    return true;
                break;
            #if __TVOS__
            case "UISearchBar":
                // - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER __TVOS_PROHIBITED;
                return true;
            #endif
            }

            var expected = ctor.ToString ();
            // NonPublic to get `protected` which can be autogenerated for abstract types (subclassing a non-abstract type)
            foreach (var candidate in type.GetConstructors (BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) {
                if (candidate.ToString () == expected)
                    return true;
            }
            return false;
        }
 internal void New(ConstructorInfo constructor)
 {
     if (this.codeGenTrace != CodeGenTrace.None)
     {
         this.EmitSourceInstruction("Newobj " + constructor.ToString() + " on type " + constructor.DeclaringType.ToString());
     }
     this.ilGen.Emit(OpCodes.Newobj, constructor);
 }
Example #10
0
 void ProcessConstructor(ConstructorInfo constructorInfo)
 {
     Debug.WriteLine ("Add constructor " + constructorInfo.ToString ());
 }
Example #11
0
 public bool OkToUse(ConstructorInfo c, out string message)
 {
     if (c == null) throw new ArgumentNullException("c");
     return OkToUseInternal(c.ToString(), this.require_members, this.forbid_members, out message);
 }
 public void Emit(OpCode opCode, ConstructorInfo ci)
 {
     ProcessCommand(opCode, 0, ci.ToString());
     ilGenerator.Emit(opCode, ci);
 }
        /// <summary>
        /// Determines of the target constructor is ok to use.
        /// </summary>
        /// <param name="constructor">
        /// The constructor to test
        /// </param>
        /// <param name="message">
        /// A message for the caller.
        /// </param>
        /// <returns>
        /// True if the constructor is ok to use, false otherwise.
        /// </returns>
        public bool OkToUse(ConstructorInfo constructor, out string message)
        {
            if (constructor != null)
            {
                foreach (ForbidExpression fExp in this.forbiddenMembers)
                {
                    if (fExp.IsForbidden(constructor.ToString()))
                    {
                        message = string.Format("The Constructor {0} matches the ForbidExpression with pattern {1}. It will not be used.", constructor.ToString(), fExp.Pattern);
                        return false;
                    }
                }

                message = string.Format("The Constructor {0} will be used.", constructor.ToString());
                return true;
            }
            else
            {
                message = "The passed in Constructor argument was null";
                throw new ArgumentNullException(message);
            }
        }