本文整理汇总了C#中NarrowingLevel类的典型用法代码示例。如果您正苦于以下问题:C# NarrowingLevel类的具体用法?C# NarrowingLevel怎么用?C# NarrowingLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NarrowingLevel类属于命名空间,在下文中一共展示了NarrowingLevel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BindingTarget
private readonly int _actualArgs; // gets the actual number of arguments provided
/// <summary>
/// Creates a new BindingTarget when the method binding has succeeded.
/// </summary>
internal BindingTarget(string name, int actualArgumentCount, MethodCandidate candidate, NarrowingLevel level, RestrictedArguments restrictedArgs) {
_name = name;
_candidate = candidate;
_restrictedArgs = restrictedArgs;
_level = level;
_actualArgs = actualArgumentCount;
}
开发者ID:BenHall,项目名称:ironruby,代码行数:12,代码来源:BindingTarget.cs
示例2: CanConvertFrom
public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArg, ParameterWrapper toParameter, NarrowingLevel level) {
if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List)))) {
if (toParameter.Type.IsGenericType() &&
toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>) &&
(toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false) ||
toParameter.ParameterInfo.IsDefined(typeof(BytesConversionNoStringAttribute), false))) {
return false;
}
} else if (fromType == typeof(string)) {
if (toParameter.Type == typeof(IList<byte>) &&
!Binder.Context.PythonOptions.Python30 &&
toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false)) {
// string -> byte array, we allow this in Python 2.6
return true;
}
} else if (fromType == typeof(Bytes)) {
if (toParameter.Type == typeof(string) &&
!Binder.Context.PythonOptions.Python30 &&
toParameter.ParameterInfo.IsDefined(typeof(BytesConversionAttribute), false)) {
return true;
}
}
return base.CanConvertFrom(fromType, fromArg, toParameter, level);
}
开发者ID:kotikus,项目名称:iron,代码行数:25,代码来源:PythonOverloadResolver.cs
示例3: BindingTarget
/// <summary>
/// Creates a new BindingTarget when the method binding has succeeded.
/// </summary>
internal BindingTarget(string name, int actualArgumentCount, MethodTarget target, NarrowingLevel level, RestrictionInfo restrictedArgs) {
_name = name;
_target = target;
_restrictedArgs = restrictedArgs;
_level = level;
_actualArgs = actualArgumentCount;
}
开发者ID:tnachen,项目名称:ironruby,代码行数:10,代码来源:BindingTarget.cs
示例4: CanConvertFrom
public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument, ParameterWrapper toParameter, NarrowingLevel level)
{
if (toParameter.Type == typeof(string) && (level == NarrowingLevel.Three || level == NarrowingLevel.All))
return true;
if (toParameter.IsParamsArray == true && typeof(IList<object>).IsAssignableFrom(fromType))
{
var toType = toParameter.Type.GetElementType();
var list = (IList<object>)fromArgument.Value;
for(var i = 0; i < list.Count; i++)
{
var itm = list[i];
var argExp = Expression.Call(
Expression.Convert(fromArgument.Expression, fromArgument.LimitType),
(typeof(IList<object>).GetMethod("get_Item")),
Expression.Constant(i, typeof(int))
);
var arg = new DynamicMetaObject(
argExp,
fromArgument.Restrictions,
itm
);
if(!CanConvertFrom(itm.GetType(), arg, new ParameterWrapper(null, toType, null, ParameterBindingFlags.None), level))
return false;
}
return true;
}
return base.CanConvertFrom(fromType, fromArgument, toParameter, level);
}
开发者ID:Alxandr,项目名称:IronTotem,代码行数:30,代码来源:OverloadResolver.cs
示例5: CanConvertFrom
public override bool CanConvertFrom(Type fromType, DynamicMetaObject fromArgument, ParameterWrapper toParameter, NarrowingLevel level)
{
if (level >= NarrowingLevel.Two)
{
if (toParameter.Type == typeof(string))
return true;
}
return base.CanConvertFrom(fromType, fromArgument, toParameter, level);
}
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:10,代码来源:TotemOverloadResolver.cs
示例6: CanConvertFrom
public override bool CanConvertFrom(Type fromType, ParameterWrapper toParameter, NarrowingLevel level) {
if ((fromType == typeof(List) || fromType.IsSubclassOf(typeof(List))) &&
toParameter.Type.IsGenericType &&
toParameter.Type.GetGenericTypeDefinition() == typeof(IList<>)) {
if (toParameter.ParameterInfo.IsDefined(typeof(ProhibitGenericListConversionAttribute), false)) {
return false;
}
}
return base.CanConvertFrom(fromType, toParameter, level);
}
开发者ID:m4dc4p,项目名称:ironruby,代码行数:11,代码来源:PythonOverloadResolver.cs
示例7: CallMethod
/// <summary>
/// Performs binding against a set of overloaded methods using the specified arguments. All arguments
/// are treated as positional arguments.
/// </summary>
/// <param name="parameterBinder">ParameterBinder used to map arguments to parameters.</param>
/// <param name="targets">The methods to be called</param>
/// <param name="args">The arguments for the call</param>
/// <param name="maxLevel">The maximum narrowing level for arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <param name="minLevel">The minimum narrowing level for the arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <returns>A meta object which results from the call.</returns>
public DynamicMetaObject CallMethod(ParameterBinder parameterBinder, IList<MethodBase> targets, IList<DynamicMetaObject> args, NarrowingLevel minLevel, NarrowingLevel maxLevel) {
return CallWorker(
parameterBinder,
targets,
args,
new CallSignature(args.Count),
CallTypes.None,
BindingRestrictions.Empty,
minLevel,
maxLevel,
null
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:23,代码来源:DefaultBinder.MethodCalls.cs
示例8: CanConvertFrom
public override bool CanConvertFrom(Type fromType, Type toType, NarrowingLevel level)
{
if (fromType == toType || toType.IsAssignableFrom(fromType))
{
return true;
}
if (toType == typeof(object) || toType == fromType)
{
return true;
}
if (fromType == typeof(int) && toType == typeof(double))
{
return true;
}
if (fromType == typeof(SymbolId) && toType.IsEnum)
{
return true;
}
if (fromType == typeof(object) && level == NarrowingLevel.All)
{
return true;
}
return false;
}
开发者ID:robertlj,项目名称:IronScheme,代码行数:24,代码来源:IronSchemeActionBinder.cs
示例9: CanConvertFrom
internal static bool CanConvertFrom(DynamicMetaObject fromArg, Type/*!*/ fromType, Type/*!*/ toType, bool toNotNullable,
NarrowingLevel level, bool explicitProtocolConversions, bool implicitProtocolConversions) {
ContractUtils.RequiresNotNull(fromType, "fromType");
ContractUtils.RequiresNotNull(toType, "toType");
var metaConvertible = fromArg as IConvertibleMetaObject;
//
// narrowing level 0:
//
if (toType == fromType) {
return true;
}
if (fromType == typeof(DynamicNull)) {
if (toNotNullable) {
return false;
}
if (toType.IsGenericType && toType.GetGenericTypeDefinition() == typeof(Nullable<>)) {
return true;
}
if (!toType.IsValueType) {
// null convertible to any reference type:
return true;
} else if (toType == typeof(bool)) {
return true;
} else if (!ProtocolConversionAction.HasDefaultConversion(toType)) {
// null not convertible to a value type unless a protocol conversion is allowed:
return false;
}
}
// blocks:
if (fromType == typeof(MissingBlockParam)) {
return toType == typeof(BlockParam) && !toNotNullable;
}
if (fromType == typeof(BlockParam) && toType == typeof(MissingBlockParam)) {
return true;
}
if (toType.IsAssignableFrom(fromType)) {
return true;
}
// A COM object could be cast to any interface:
if (Utils.IsComObjectType(fromType) && toType.IsInterface) {
return true;
}
if (HasImplicitNumericConversion(fromType, toType)) {
return true;
}
if (CompilerHelpers.GetImplicitConverter(fromType, toType) != null) {
return true;
}
if (metaConvertible != null) {
return metaConvertible.CanConvertTo(toType, false);
}
//
// narrowing level 1:
//
if (level < NarrowingLevel.One) {
return false;
}
if (explicitProtocolConversions && ProtocolConversionAction.HasDefaultConversion(toType)) {
return true;
}
//
// narrowing level 2:
//
if (level < NarrowingLevel.Two) {
return false;
}
if (HasExplicitNumericConversion(fromType, toType)) {
return true;
}
if (CompilerHelpers.GetExplicitConverter(fromType, toType) != null) {
return true;
}
if (CompilerHelpers.HasTypeConverter(fromType, toType)) {
return true;
}
if (fromType == typeof(char) && toType == typeof(string)) {
return true;
}
//.........这里部分代码省略.........
开发者ID:gregmalcolm,项目名称:ironruby,代码行数:101,代码来源:Converter.cs
示例10: SelectBestConversionFor
private int? SelectBestConversionFor(Type actualType, Type candidateOne, Type candidateTwo, NarrowingLevel level) {
Type ret = _binder.SelectBestConversionFor(actualType, candidateOne, candidateTwo, level);
if (ret != null) {
if (ret == candidateOne) {
return +1;
} else if (ret == candidateTwo) {
return -1;
}
}
return null;
}
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:11,代码来源:ParameterWrapper.cs
示例11: CanConvertFrom
public override bool CanConvertFrom(Type/*!*/ fromType, Type/*!*/ toType, bool toNotNullable, NarrowingLevel level) {
return Converter.CanConvertFrom(null, fromType, toType, toNotNullable, level, false, false);
}
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:RubyBinder.cs
示例12: CanConvertFrom
/// <summary>
/// Returns true if fromArg of type fromType can be assigned to toParameter with a conversion on given narrowing level.
/// </summary>
public override bool CanConvertFrom(Type/*!*/ fromType, DynamicMetaObject fromArg, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) {
return Converter.CanConvertFrom(fromArg, fromType, toParameter.Type, toParameter.ProhibitNull, level,
HasExplicitProtocolConversion(toParameter), _implicitProtocolConversions
);
}
开发者ID:andreakn,项目名称:ironruby,代码行数:8,代码来源:RubyOverloadResolver.cs
示例13: CallMethod
/// <summary>
/// Performs binding against a set of overloaded methods using the specified arguments. The arguments are
/// consumed as specified by the CallSignature object.
/// </summary>
/// <param name="minLevel">TODO.</param>
/// <param name="maxLevel">TODO.</param>
/// <param name="resolver">Overload resolver.</param>
/// <param name="targets">The methods to be called</param>
/// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
/// <param name="target">The resulting binding target which can be used for producing error information.</param>
/// <param name="name">The name of the method or null to use the name from targets.</param>
/// <returns>A meta object which results from the call.</returns>
public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, BindingRestrictions restrictions, string name,
NarrowingLevel minLevel, NarrowingLevel maxLevel, out BindingTarget target) {
ContractUtils.RequiresNotNull(resolver, "resolver");
ContractUtils.RequiresNotNullItems(targets, "targets");
ContractUtils.RequiresNotNull(restrictions, "restrictions");
// attempt to bind to an individual method
target = resolver.ResolveOverload(name ?? GetTargetName(targets), targets, minLevel, maxLevel);
if (target.Success) {
// if we succeed make the target for the rule
return new DynamicMetaObject(
target.MakeExpression(),
restrictions.Merge(
MakeSplatTests(resolver.CallType, resolver.Signature, resolver.Arguments).
Merge(target.RestrictedArguments.GetAllRestrictions())
)
);
}
// make an error rule
return MakeInvalidParametersRule(resolver, restrictions, target);
}
开发者ID:jschementi,项目名称:iron,代码行数:35,代码来源:DefaultBinder.MethodCalls.cs
示例14: GetPreferredParameter
private Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo, DynamicMetaObject arg, NarrowingLevel level) {
Assert.NotNull(candidateOne, candidateTwo);
if (ParametersEquivalent(candidateOne, candidateTwo)) {
return Candidate.Equivalent;
}
Candidate candidate = SelectBestConversionFor(arg, candidateOne, candidateTwo, level);
if (candidate.Chosen()) {
return candidate;
}
if (CanConvertFrom(candidateTwo, candidateOne)) {
if (CanConvertFrom(candidateOne, candidateTwo)) {
return Candidate.Ambiguous;
} else {
return Candidate.Two;
}
} else if (CanConvertFrom(candidateOne, candidateTwo)) {
return Candidate.One;
}
// Special additional rules to order numeric value types
Type t1 = candidateOne.Type;
Type t2 = candidateTwo.Type;
Candidate preferred = PreferConvert(t1, t2);
if (preferred.Chosen()) {
return preferred;
}
preferred = PreferConvert(t2, t1).TheOther();
if (preferred.Chosen()) {
return preferred;
}
// consider the actual argument type:
Type argType = arg.GetLimitType();
NarrowingLevel levelOne = NarrowingLevel.None;
while (levelOne < level && !CanConvertFrom(argType, arg, candidateOne, levelOne)) {
if (levelOne == NarrowingLevel.All) {
Debug.Assert(false, "Each argument should be convertible to the corresponding parameter");
break;
}
levelOne++;
}
NarrowingLevel levelTwo = NarrowingLevel.None;
while (levelTwo < level && !CanConvertFrom(argType, arg, candidateTwo, levelTwo)) {
if (levelTwo == NarrowingLevel.All) {
Debug.Assert(false, "Each argument should be convertible to the corresponding parameter");
break;
}
levelTwo++;
}
if (levelOne < levelTwo) {
return Candidate.One;
} else if (levelOne > levelTwo) {
return Candidate.Two;
} else {
return Candidate.Ambiguous;
}
}
开发者ID:apboyle,项目名称:ironruby,代码行数:64,代码来源:OverloadResolver.cs
示例15: CanConvertFrom
/// <summary>
/// Determines if a conversion exists from fromType to toType at the specified narrowing level.
/// toNotNullable is true if the target variable doesn't allow null values.
/// </summary>
public abstract bool CanConvertFrom(Type fromType, Type toType, bool toNotNullable, NarrowingLevel level);
开发者ID:Jaykul,项目名称:IronLangs,代码行数:5,代码来源:ActionBinder.cs
示例16: CanConvertFrom
/// <summary>
/// Returns true if fromArg of type fromType can be assigned to toParameter with a conversion on given narrowing level.
/// </summary>
public override bool CanConvertFrom(Type/*!*/ fromType, DynamicMetaObject fromArg, ParameterWrapper/*!*/ toParameter, NarrowingLevel level) {
var result = Converter.CanConvertFrom(fromArg, fromType, toParameter.Type, toParameter.ProhibitNull, level,
HasExplicitProtocolConversion(toParameter), _implicitProtocolConversions
);
if (result.Assumption != null) {
if (_argumentAssumptions == null) {
_argumentAssumptions = new List<Key<int, NarrowingLevel, Ast>>();
}
if (_argumentAssumptions.FindIndex((k) => k.First == toParameter.ParameterInfo.Position && k.Second == level) < 0) {
_argumentAssumptions.Add(Key.Create(toParameter.ParameterInfo.Position, level, result.Assumption));
}
}
return result.IsConvertible;
}
开发者ID:hjast,项目名称:ironruby,代码行数:20,代码来源:RubyOverloadResolver.cs
示例17: SelectBestCandidate
private ApplicableCandidate SelectBestCandidate(List<ApplicableCandidate> candidates, NarrowingLevel level) {
foreach (var candidate in candidates) {
if (IsBest(candidate, candidates, level)) {
return candidate;
}
}
return null;
}
开发者ID:apboyle,项目名称:ironruby,代码行数:8,代码来源:OverloadResolver.cs
示例18: CanConvertFrom
public override bool CanConvertFrom(Type fromType, Type toType, bool toNotNullable, NarrowingLevel level)
{
//
// NarrowLevel.Zero
//
if (fromType == toType)
return true;
// I don't want to consider boxing before numeric conversion, else I don't get the convert-int-to-long behavior required to select Numbers.lt(long,long) over Numbers.lt(long,Object)
// We also need to get the narrow-long-to-int behavior required to avoid casting in host expression calls.
// IronRuby does this here:
//if (toType.IsAssignableFrom(fromType))
//{
// return true;
//}
if ( !Util.IsPrimitiveNumeric(fromType) && toType.IsAssignableFrom(fromType))
{
return true;
}
//
// NarrowingLevel.One
//
if (level < NarrowingLevel.One)
{
return false;
}
if (WideningIntegerConversion(fromType, toType))
{
return true;
}
//
// NarrowingLevel.Two
//
if (level < NarrowingLevel.Two)
{
return false;
}
if ( SpecialClojureConversion(fromType, toType) )
{
return true;
}
//if (fromType == typeof(char) && toType == typeof(string))
//{
// return true;
//}
if (toType == typeof(bool))
{
return true;
}
//
// NarrowingLevel.Three
//
if (level < NarrowingLevel.Three)
{
return false;
}
if ( Util.IsPrimitiveNumeric(toType) && Util.IsPrimitiveNumeric(fromType) )
{
return true;
}
//
// NarrowingLevel.All
//
if (level < NarrowingLevel.All)
{
return false;
}
// pick up boxing numerics here
if (toType.IsAssignableFrom(fromType))
{
return true;
}
return false;
//if (level == NarrowingLevel.All)
//{
// if (fromType == typeof(long))
// {
// if (toType == typeof(int) || toType == typeof(uint) || toType == typeof(short) || toType == typeof(ushort) || toType == typeof(byte) || toType == typeof(sbyte))
// return true;
// }
// else if (fromType == typeof(double))
// {
// if (toType == typeof(float))
//.........这里部分代码省略.........
开发者ID:jiupai,项目名称:clojure-clr,代码行数:101,代码来源:NumericConvertBinder.cs
示例19: MakeSuccessfulBindingTarget
private BindingTarget MakeSuccessfulBindingTarget(ApplicableCandidate result, List<ApplicableCandidate> potentialCandidates,
NarrowingLevel level, CandidateSet targetSet) {
return new BindingTarget(
_methodName,
_actualArguments.VisibleCount,
result.Method,
level,
GetRestrictedArgs(result, potentialCandidates, targetSet.Arity)
);
}
开发者ID:apboyle,项目名称:ironruby,代码行数:11,代码来源:OverloadResolver.cs
示例20: SelectBestConversionFor
public override Candidate SelectBestConversionFor(DynamicMetaObject/*!*/ arg, ParameterWrapper/*!*/ candidateOne,
ParameterWrapper/*!*/ candidateTwo, NarrowingLevel level) {
Type typeOne = candidateOne.Type;
Type typeTwo = candidateTwo.Type;
Type actualType = arg.GetLimitType();
if (actualType == typeof(DynamicNull)) {
// if nil is passed as a block argument prefers BlockParam over a missing block:
if (typeOne == typeof(BlockParam) && typeTwo == typeof(MissingBlockParam)) {
Debug.Assert(!candidateOne.ProhibitNull);
return Candidate.One;
}
if (typeOne == typeof(MissingBlockParam) && typeTwo == typeof(BlockParam)) {
Debug.Assert(!candidateTwo.ProhibitNull);
return Candidate.Two;
}
} else {
if (typeOne == actualType) {
if (typeTwo == actualType) {
// prefer non-nullable reference type over nullable:
if (!actualType.IsValueType) {
if (candidateOne.ProhibitNull) {
return Candidate.One;
} else if (candidateTwo.ProhibitNull) {
return Candidate.Two;
}
}
} else {
return Candidate.One;
}
} else if (typeTwo == actualType) {
return Candidate.Two;
}
}
// prefer integer type over enum:
if (typeOne.IsEnum && Enum.GetUnderlyingType(typeOne) == typeTwo) {
return Candidate.Two;
}
if (typeTwo.IsEnum && Enum.GetUnderlyingType(typeTwo) == typeOne) {
return Candidate.One;
}
return base.SelectBestConversionFor(arg, candidateOne, candidateTwo, level);
}
开发者ID:andreakn,项目名称:ironruby,代码行数:48,代码来源:RubyOverloadResolver.cs
注:本文中的NarrowingLevel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论