Esempio n. 1
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                {
                    continue;
                }
                if (PropertyValueIsLeaf(property))
                {
                    IEnumerable <OverloadInfo> overloads = GetOverloadsForProperty(property);
                    OverloadInfo firstOverload           = overloads.First();

                    if (firstOverload.Parameters.Length != 1)
                    {
                        continue;
                    }

                    string firstOverloadFirstParameterType = firstOverload.Parameters[0].Type;

                    OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                    string interfaceName = "ICesiumValuePropertyWriter";
                    if (sampleOverload != null)
                    {
                        interfaceName = "ICesiumInterpolatableValuePropertyWriter";
                    }

                    WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <c>{1}</c> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                    WriteReturnsText(writer, "The wrapper.");
                    writer.WriteLine("public {0}<{1}> As{2}()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    using (writer.OpenScope())
                    {
                        writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                    }

                    writer.WriteLine();

                    string adaptorName = "CesiumWriterAdaptor";
                    if (sampleOverload != null)
                    {
                        adaptorName = "CesiumInterpolatableWriterAdaptor";
                    }

                    writer.WriteLine("private {0}<{1}> Create{2}Adaptor()", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    using (writer.OpenScope())
                    {
                        string extraParameter = "";
                        if (sampleOverload != null)
                        {
                            extraParameter = string.Format(", (me, dates, values, startIndex, length) => me.Write{0}(dates, values, startIndex, length)", property.NameWithPascalCase);
                        }

                        writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(this, (me, value) => me.Write{3}(value){4});", adaptorName, schema.NameWithPascalCase, firstOverloadFirstParameterType, property.NameWithPascalCase, extraParameter);
                    }

                    writer.WriteLine();
                }
            }
        }
Esempio n. 2
0
        private void WritePropertyLazyFields(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.AllProperties)
            {
                if (PropertyValueIsLeaf(property))
                {
                    if (property.IsValue)
                    {
                        // Does this property have an overload to write sampled data?
                        // If so, it's interpolatable.
                        OverloadInfo firstOverload = GetOverloadsForProperty(property).First();
                        if (firstOverload.Parameters.Length != 1)
                        {
                            continue;
                        }

                        string adaptorType = GetAdaptorType(schema, property);

                        writer.WriteLine("private readonly Lazy<{0}> m_as{1};", adaptorType, property.NameWithPascalCase);
                    }
                }
                else
                {
                    writer.WriteLine("private readonly Lazy<{0}> m_{1} = new Lazy<{0}>(() => new {0}({2}PropertyName), false);",
                                     GetWriterType(property.ValueType),
                                     property.Name,
                                     property.NameWithPascalCase);
                }
            }

            if (schema.AllProperties.Count > 0)
            {
                writer.WriteLine();
            }
        }
Esempio n. 3
0
        internal static void GetParameterCount(OverloadInfo /*!*/ method, SelfCallConvention callConvention, out int mandatory, out int optional)
        {
            mandatory = 0;
            optional  = 0;
            for (int i = GetHiddenParameterCount(method, callConvention); i < method.ParameterCount; i++)
            {
                var info = method.Parameters[i];

                if (method.IsParamArray(i))
                {
                    // TODO: indicate splat args separately?
                    optional++;
                }
                else if (info.IsOutParameter())
                {
                    // Python allows passing of optional "clr.Reference" to capture out parameters
                    // Ruby should allow similar
                    optional++;
                }
                else if (info.IsMandatory())
                {
                    mandatory++;
                }
                else
                {
                    optional++;
                }
            }
        }
Esempio n. 4
0
        private void WriteAsTypeLazyInitialization(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                {
                    continue;
                }
                if (PropertyValueIsLeaf(property))
                {
                    IEnumerable <OverloadInfo> overloads = GetOverloadsForProperty(property);
                    OverloadInfo firstOverload           = overloads.First();
                    if (firstOverload.Parameters.Length != 1)
                    {
                        continue;
                    }

                    OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                    string interfaceName = "ICesiumValuePropertyWriter";
                    if (sampleOverload != null)
                    {
                        interfaceName = "ICesiumInterpolatableValuePropertyWriter";
                    }

                    writer.WriteLine("m_as{0} = new Lazy<{1}<{2}>>(Create{0}Adaptor, false);",
                                     property.NameWithPascalCase,
                                     interfaceName,
                                     firstOverload.Parameters[0].Type);
                }
            }
        }
 private static bool IsSampledDataOverload(OverloadInfo overload)
 {
     return overload.Parameters.Length == 4 &&
            overload.Parameters[0].Type == "IList<JulianDate>" &&
            overload.Parameters[1].Type.StartsWith("IList<") &&
            overload.Parameters[2].Type == "int" &&
            overload.Parameters[3].Type == "int";
 }
Esempio n. 6
0
 private bool IsSampledDataOverload(OverloadInfo overload)
 {
     return(overload.Parameters.Length == 4 &&
            overload.Parameters[0].Type == "IList<JulianDate>" &&
            overload.Parameters[1].Type.StartsWith("IList<") &&
            overload.Parameters[2].Type == "int" &&
            overload.Parameters[3].Type == "int");
 }
Esempio n. 7
0
        List <OverloadInfo> GetMethodsOverloadInformation(XmlNodeList overloadNodes)
        {
            try
            {
                List <OverloadInfo> overloadInfo = new List <OverloadInfo>();

                foreach (XmlNode overload in overloadNodes)
                {
                    OverloadInfo info = new OverloadInfo();

                    foreach (XmlAttribute att in overload.Attributes)
                    {
                        if (att.Name.ToLower() == "number")
                        {
                            if (!String.IsNullOrEmpty(att.Value))
                            {
                                info.OverLoad = Convert.ToInt16(att.Value);
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    XmlNodeList       parameters    = overload.ChildNodes;
                    List <Parameters> parameterList = new List <Parameters>();
                    foreach (XmlNode parameterValue in parameters)
                    {
                        Parameters param = new Parameters();
                        foreach (XmlAttribute paramAttribute in parameterValue.Attributes)
                        {
                            if (paramAttribute.Name.ToLower() == "name")
                            {
                                param.ParameterName = paramAttribute.Value;
                            }

                            if (paramAttribute.Name.ToLower() == "type")
                            {
                                param.ParameterType = paramAttribute.Value;
                            }
                            if (paramAttribute.Name.ToLower() == "sequence-no")
                            {
                                param.ParameterSequence = Convert.ToInt16(paramAttribute.Value);
                            }
                        }
                        parameterList.Add(param);
                    }

                    info.MethodParameters = parameterList;
                    overloadInfo.Add(info);
                }
                return(overloadInfo);
            }
            catch
            {
                return(null);
            }
        }
        public static bool ShouldWarn(PythonContext/*!*/ context, OverloadInfo/*!*/ method, out WarningInfo info) {
            Assert.NotNull(method);

            ObsoleteAttribute[] os = (ObsoleteAttribute[])method.ReflectionInfo.GetCustomAttributes(typeof(ObsoleteAttribute), true);
            if (os.Length > 0) {
                info = new WarningInfo(
                    PythonExceptions.DeprecationWarning,
                    String.Format("{0}.{1} has been obsoleted.  {2}",
                        NameConverter.GetTypeName(method.DeclaringType),
                        method.Name,
                        os[0].Message
                    )
                );

                return true;
            }

            if (context.PythonOptions.WarnPython30) {
                Python3WarningAttribute[] py3kwarnings = (Python3WarningAttribute[])method.ReflectionInfo.GetCustomAttributes(typeof(Python3WarningAttribute), true);
                if (py3kwarnings.Length > 0) {
                    info = new WarningInfo(
                        PythonExceptions.DeprecationWarning,
                        py3kwarnings[0].Message
                    );

                    return true;
                }
            }

#if FEATURE_APARTMENTSTATE
            // no apartment states on Silverlight
            if (method.DeclaringType == typeof(Thread)) {
                if (method.Name == "Sleep") {
                    info = new WarningInfo(
                        PythonExceptions.RuntimeWarning,
                        "Calling Thread.Sleep on an STA thread doesn't pump messages.  Use Thread.CurrentThread.Join instead.",
                        Expression.Equal(
                            Expression.Call(
                                Expression.Property(
                                    null,
                                    typeof(Thread).GetProperty("CurrentThread")
                                ),
                                typeof(Thread).GetMethod("GetApartmentState")
                            ),
                            AstUtils.Constant(ApartmentState.STA)
                        )
                    );

                    return true;
                }
            }
#endif

            info = null;
            return false;
        }
Esempio n. 9
0
 private static bool HasBlockParameter(OverloadInfo /*!*/ method)
 {
     foreach (ParameterInfo param in method.Parameters)
     {
         if (param.ParameterType == typeof(BlockParam))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        private IEnumerable <OverloadInfo> GetOverloadsForProperty(Property property)
        {
            if (property.ValueType.IsSchemaFromType)
            {
                JsonSchemaType type = property.ValueType.JsonTypes;

                if (type.HasFlag(JsonSchemaType.Object) ||
                    type.HasFlag(JsonSchemaType.Array) ||
                    type.HasFlag(JsonSchemaType.Null) ||
                    type.HasFlag(JsonSchemaType.Any) ||
                    type == JsonSchemaType.None)
                {
                    throw new Exception(string.Format("Property '{0}' does not specify a $ref to a schema, nor is it a simple JSON type.", property.Name));
                }

                if (type.HasFlag(JsonSchemaType.String))
                {
                    yield return(s_defaultStringOverload);
                }

                if (type.HasFlag(JsonSchemaType.Float))
                {
                    yield return(s_defaultDoubleOverload);
                }

                if (type.HasFlag(JsonSchemaType.Integer))
                {
                    yield return(s_defaultIntegerOverload);
                }

                if (type.HasFlag(JsonSchemaType.Boolean))
                {
                    yield return(s_defaultBooleanOverload);
                }
            }
            else
            {
                OverloadInfo[] overloads;
                if (m_configuration.Types.TryGetValue(property.ValueType.Name, out overloads))
                {
                    foreach (OverloadInfo overload in overloads)
                    {
                        yield return(overload);
                    }
                }
                else
                {
                    yield return(OverloadInfo.CreateDefault(property.ValueType.NameWithPascalCase));
                }
            }
        }
        internal static int GetHiddenParameterCount(OverloadInfo /*!*/ method, SelfCallConvention callConvention)
        {
            int i     = 0;
            var infos = method.Parameters;

            if (callConvention == SelfCallConvention.SelfIsInstance)
            {
                if (method.IsStatic)
                {
                    Debug.Assert(RubyUtils.IsOperator(method) || method.IsExtension);
                    i++;
                }
            }

            while (i < infos.Count && infos[i].ParameterType.IsSubclassOf(typeof(RubyCallSiteStorage)))
            {
                i++;
            }

            if (i < infos.Count)
            {
                var info = infos[i];

                if (info.ParameterType == typeof(RubyScope))
                {
                    i++;
                }
                else if (info.ParameterType == typeof(RubyContext))
                {
                    i++;
                }
                else if (method.IsConstructor && info.ParameterType == typeof(RubyClass))
                {
                    i++;
                }
            }

            if (i < infos.Count && infos[i].ParameterType == typeof(BlockParam))
            {
                i++;
            }

            if (callConvention == SelfCallConvention.SelfIsParameter)
            {
                Debug.Assert(i < infos.Count);
                Debug.Assert(method.IsStatic);
                i++;
            }

            return(i);
        }
Esempio n. 12
0
        private OverloadInfo[] GetOverloadsForProperty(Property property)
        {
            OverloadInfo[] overloads;

            if (property.ValueType.IsSchemaFromType)
            {
                overloads = new OverloadInfo[4];

                int            index = 0;
                JsonSchemaType type  = property.ValueType.JsonTypes;

                if ((type & JsonSchemaType.String) == JsonSchemaType.String)
                {
                    overloads[index++] = s_defaultStringOverload;
                }
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Float)
                {
                    overloads[index++] = s_defaultDoubleOverload;
                }
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Integer)
                {
                    overloads[index++] = s_defaultIntegerOverload;
                }
                if ((type & JsonSchemaType.Boolean) == JsonSchemaType.Boolean)
                {
                    overloads[index++] = s_defaultBooleanOverload;
                }
                if ((type & JsonSchemaType.Object) == JsonSchemaType.Object ||
                    (type & JsonSchemaType.Array) == JsonSchemaType.Array ||
                    (type & JsonSchemaType.Null) == JsonSchemaType.Null ||
                    (type & JsonSchemaType.Any) == JsonSchemaType.Any ||
                    type == JsonSchemaType.None)
                {
                    throw new Exception(string.Format("Property '{0}' does not specify a $ref to a schema, nor is it a simple JSON type.", property.Name));
                }

                Array.Resize(ref overloads, index);
            }
            else
            {
                if (!m_configuration.Types.TryGetValue(property.ValueType.Name, out overloads))
                {
                    overloads = new[] { OverloadInfo.CreateDefault(property.ValueType.NameWithPascalCase) };
                    m_configuration.Types[property.ValueType.Name] = overloads;
                }
            }
            return(overloads);
        }
Esempio n. 13
0
        private string GetDefaultValueType(Schema schema)
        {
            Property firstValueProperty = schema.FindFirstValueProperty();

            if (firstValueProperty != null)
            {
                OverloadInfo[] overloads = GetOverloadsForProperty(firstValueProperty);
                OverloadInfo   firstOverloadWithOneParameter = Array.Find(overloads, overload => overload.Parameters.Length == 1);
                if (firstOverloadWithOneParameter != null)
                {
                    return(firstOverloadWithOneParameter.Parameters[0].Type);
                }
            }

            return(null);
        }
Esempio n. 14
0
        private void WritePropertyLazyFields(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.Properties)
            {
                if (PropertyValueIsLeaf(property))
                {
                    if (property.IsValue)
                    {
                        // Does this property have an overload to write sampled data?
                        // If so, it's interpolatable.
                        IEnumerable <OverloadInfo> overloads = GetOverloadsForProperty(property);

                        OverloadInfo firstOverload = overloads.First();

                        if (firstOverload.Parameters.Length != 1)
                        {
                            continue;
                        }

                        string interfaceName = "ICesiumValuePropertyWriter";
                        if (FindSampledDataOverload(overloads) != null)
                        {
                            interfaceName = "ICesiumInterpolatableValuePropertyWriter";
                        }

                        string firstOverloadFirstParameterType = firstOverload.Parameters[0].Type;
                        writer.WriteLine("private readonly Lazy<{0}<{1}>> m_as{2};", interfaceName, firstOverloadFirstParameterType, property.NameWithPascalCase);
                    }
                }
                else
                {
                    writer.WriteLine("private readonly Lazy<{0}CesiumWriter> m_{1} = new Lazy<{0}CesiumWriter>(() => new {0}CesiumWriter({2}PropertyName), false);",
                                     property.ValueType.NameWithPascalCase,
                                     property.Name,
                                     property.NameWithPascalCase);
                }
            }

            if (schema.Properties.Count > 0)
            {
                writer.WriteLine();
            }
        }
Esempio n. 15
0
        private bool IsOverloadSignature(OverloadInfo /*!*/ method, Type /*!*/[] /*!*/ parameterTypes)
        {
            int firstInfo = RubyOverloadResolver.GetHiddenParameterCount(method, CallConvention);
            var infos     = method.Parameters;

            if (infos.Count - firstInfo != parameterTypes.Length)
            {
                return(false);
            }

            for (int i = 0; i < parameterTypes.Length; i++)
            {
                if (infos[firstInfo + i].ParameterType != parameterTypes[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 16
0
        private void WriteAsTypeLazyInitialization(CodeWriter writer, Schema schema)
        {
            foreach (Property property in schema.AllProperties)
            {
                if (!property.IsValue)
                {
                    continue;
                }

                if (PropertyValueIsLeaf(property))
                {
                    OverloadInfo firstOverload = GetOverloadsForProperty(property).First();
                    if (firstOverload.Parameters.Length != 1)
                    {
                        continue;
                    }

                    writer.WriteLine("m_as{0} = CreateAs{0}();", property.NameWithPascalCase);
                }
            }
        }
Esempio n. 17
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            foreach (var property in schema.AllProperties.Where(p => p.IsValue).Where(PropertyValueIsLeaf))
            {
                OverloadInfo firstOverload = GetOverloadsForProperty(property).First();
                if (firstOverload.Parameters.Length != 1)
                {
                    continue;
                }

                WriteSummaryText(writer, "Returns a wrapper for this instance that implements <see cref=\"ICesium{0}ValuePropertyWriter\"/>. Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\"/> on either this instance or the wrapper, but you must not call it on both.", property.ValueType.NameWithPascalCase);
                WriteReturnsText(writer, "The wrapper.");

                string adaptorType = GetAdaptorType(schema, property);

                writer.WriteLine("[NotNull]");
                writer.WriteLine("public {0} As{1}()", adaptorType, property.NameWithPascalCase);
                using (writer.OpenScope())
                {
                    writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                }
                writer.WriteLine();

                writer.WriteLine("[NotNull]");
                writer.WriteLine("private Lazy<{0}> CreateAs{1}()", adaptorType, property.NameWithPascalCase);
                using (writer.OpenScope())
                {
                    writer.WriteLine("return new Lazy<{0}>(Create{1}, false);", adaptorType, property.ValueType.NameWithPascalCase);
                }
                writer.WriteLine();

                writer.WriteLine("[NotNull]");
                writer.WriteLine("private {0} Create{1}()", adaptorType, property.ValueType.NameWithPascalCase);
                using (writer.OpenScope())
                {
                    writer.WriteLine("return CesiumValuePropertyAdaptors.Create{0}(this);", property.ValueType.NameWithPascalCase);
                }
                writer.WriteLine();
            }
        }
Esempio n. 18
0
        private void WriteAsTypeMethods(CodeWriter writer, Schema schema)
        {
            if (schema.Properties == null)
            {
                return;
            }

            foreach (Property property in schema.Properties)
            {
                if (!property.IsValue)
                {
                    continue;
                }
                if (PropertyValueIsIntervals(property))
                {
                    continue;
                }

                OverloadInfo[] overloads = GetOverloadsForProperty(property);

                if (overloads[0].Parameters.Length != 1)
                {
                    continue;
                }

                OverloadInfo sampleOverload = FindSampledDataOverload(overloads);

                string interfaceName = "ICesiumValuePropertyWriter";
                if (sampleOverload != null)
                {
                    interfaceName = "ICesiumInterpolatableValuePropertyWriter";
                }

                WriteSummaryText(writer, string.Format("Returns a wrapper for this instance that implements <see cref=\"{0}{{T}}\" /> to write a value in <code>{1}</code> format.  Because the returned instance is a wrapper for this instance, you may call <see cref=\"ICesiumElementWriter.Close\" /> on either this instance or the wrapper, but you must not call it on both.", interfaceName, property.NameWithPascalCase));
                WriteReturnsText(writer, "The wrapper.");
                writer.WriteLine("public {0}<{1}> As{2}()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return m_as{0}.Value;", property.NameWithPascalCase);
                writer.CloseScope();
                writer.WriteLine();

                string adaptorName = "CesiumWriterAdaptor";
                if (sampleOverload != null)
                {
                    adaptorName = "CesiumInterpolatableWriterAdaptor";
                }

                writer.WriteLine("private {0}<{1}> Create{2}Adaptor()",
                                 interfaceName,
                                 overloads[0].Parameters[0].Type,
                                 property.NameWithPascalCase);
                writer.OpenScope();
                writer.WriteLine("return new {0}<{1}CesiumWriter, {2}>(",
                                 adaptorName,
                                 schema.NameWithPascalCase,
                                 overloads[0].Parameters[0].Type);
                if (sampleOverload != null)
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value), ({1}CesiumWriter me, IList<JulianDate> dates, IList<{2}> values, int startIndex, int length) => me.Write{0}(dates, values, startIndex, length));",
                                     property.NameWithPascalCase,
                                     schema.NameWithPascalCase,
                                     overloads[0].Parameters[0].Type);
                }
                else
                {
                    writer.WriteLine("    this, (me, value) => me.Write{0}(value));",
                                     property.NameWithPascalCase);
                }
                writer.CloseScope();
                writer.WriteLine();
            }
        }
Esempio n. 19
0
 private OverloadInfo FindSampledDataOverload(OverloadInfo[] overloads)
 {
     return Array.Find(overloads, IsSampledDataOverload);
 }
Esempio n. 20
0
 protected internal override bool AllowByKeywordArgument(OverloadInfo method, ParameterInfo parameter)
 {
     // params arrays & dictionaries don't allow assignment by keyword
     return(base.AllowByKeywordArgument(method, parameter) &&
            !parameter.IsParamArray() && !parameter.IsParamDictionary());
 }
Esempio n. 21
0
        private OverloadInfo[] GetOverloadsForProperty(Property property)
        {
            OverloadInfo[] overloads;

            if (property.ValueType.IsSchemaFromType)
            {
                overloads = new OverloadInfo[4];

                int index = 0;
                JsonSchemaType type = property.ValueType.JsonTypes;

                if ((type & JsonSchemaType.String) == JsonSchemaType.String)
                    overloads[index++] = s_defaultStringOverload;
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Float)
                    overloads[index++] = s_defaultDoubleOverload;
                if ((type & JsonSchemaType.Float) == JsonSchemaType.Integer)
                    overloads[index++] = s_defaultIntegerOverload;
                if ((type & JsonSchemaType.Boolean) == JsonSchemaType.Boolean)
                    overloads[index++] = s_defaultBooleanOverload;
                if ((type & JsonSchemaType.Object) == JsonSchemaType.Object ||
                    (type & JsonSchemaType.Array) == JsonSchemaType.Array ||
                    (type & JsonSchemaType.Null) == JsonSchemaType.Null ||
                    (type & JsonSchemaType.Any) == JsonSchemaType.Any ||
                    type == JsonSchemaType.None)
                {
                    throw new Exception(string.Format("Property '{0}' does not specify a $ref to a schema, nor is it a simple JSON type.", property.Name));
                }

                Array.Resize(ref overloads, index);
            }
            else
            {
                if (!m_configuration.Types.TryGetValue(property.ValueType.Name, out overloads))
                {
                    overloads = new[] { OverloadInfo.CreateDefault(property.ValueType.NameWithPascalCase) };
                    m_configuration.Types[property.ValueType.Name] = overloads;
                }
            }
            return overloads;
        }
 protected override bool AllowMemberInitialization(OverloadInfo method)
 {
     return(false);
 }
Esempio n. 23
0
 protected override bool AllowMemberInitialization(OverloadInfo method)
 {
     return(method.IsInstanceFactory && !method.DeclaringType.IsDefined(typeof(PythonTypeAttribute), true));
 }
Esempio n. 24
0
        internal static IList <OverloadInfo> /*!*/ GetVisibleOverloads(CallArguments /*!*/ args, IList <OverloadInfo> /*!*/ overloads, bool isSuperCall)
        {
            IList <OverloadInfo> newOverloads = null;

            Debug.Assert(overloads.Count > 0);

            // handle CLR-protected and virtual methods:

            // TODO (opt):
            // We might be able to cache the callable overloads in a MethodGroup.
            // However, the _overloadOwners of that group would need to point to the original overload owners, not the current class, in order
            // to preserve semantics of overload deletion/redefinition (deletion of the protected overload would need to imply deletion
            // of the correpsondig public overload in the cached MethodGroup).
            if (isSuperCall || !args.RubyContext.DomainManager.Configuration.PrivateBinding)
            {
                Type         underlyingType = null;
                BindingFlags bindingFlags   = 0;

                for (int i = 0; i < overloads.Count; i++)
                {
                    var overload = overloads[i];
                    if ((isSuperCall && overload.IsVirtual && !overload.IsFinal) || overload.IsProtected)
                    {
                        if (newOverloads == null)
                        {
                            newOverloads = CollectionUtils.GetRange(overloads, 0, i);

                            RubyClass cls;
                            IRubyType rt = args.Target as IRubyType;
                            if (rt != null)
                            {
                                bindingFlags   = BindingFlags.Instance;
                                underlyingType = args.Target.GetType();
                            }
                            else if ((cls = args.Target as RubyClass) != null && cls.IsRubyClass && !cls.IsSingletonClass)
                            {
                                bindingFlags   = BindingFlags.Static;
                                underlyingType = cls.GetUnderlyingSystemType();
                            }
                        }

                        if (underlyingType != null)
                        {
                            // TODO (opt): we can define a method on the emitted type that does this more efficently:
                            IList <Type> genericArguments = overload.IsGenericMethod ? overload.GenericArguments : null;

                            OverloadInfo visibleMethod = GetMethodOverload(
                                ArrayUtils.ToArray(overload.Parameters, (pi) => pi.ParameterType),
                                genericArguments,
                                underlyingType,
                                ClsTypeEmitter.BaseMethodPrefix + overload.Name,
                                BindingFlags.Public | bindingFlags | BindingFlags.InvokeMethod
                                );

                            Debug.Assert(visibleMethod != null);

                            newOverloads.Add(visibleMethod);
                        }
                    }
                    else if (newOverloads != null)
                    {
                        newOverloads.Add(overload);
                    }
                }
            }

            return(newOverloads ?? overloads);
        }