本文整理汇总了C#中Conversion类的典型用法代码示例。如果您正苦于以下问题:C# Conversion类的具体用法?C# Conversion怎么用?C# Conversion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Conversion类属于命名空间,在下文中一共展示了Conversion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CustomConversionRule
/// <summary>
/// Constructs a custom conversion rule.
/// </summary>
/// <param name="conversion">The conversion operation.</param>
public CustomConversionRule(Conversion conversion)
{
if (conversion == null)
throw new ArgumentNullException("conversion");
this.conversion = conversion;
}
示例2: BinaryOperatorAnalysisResult
private BinaryOperatorAnalysisResult(OperatorAnalysisResultKind kind, BinaryOperatorSignature signature, Conversion leftConversion, Conversion rightConversion)
{
this.Kind = kind;
this.Signature = signature;
this.LeftConversion = leftConversion;
this.RightConversion = rightConversion;
}
示例3: ForEachEnumeratorInfo
private ForEachEnumeratorInfo(
TypeSymbol collectionType,
TypeSymbol elementType,
MethodSymbol getEnumeratorMethod,
MethodSymbol currentPropertyGetter,
MethodSymbol moveNextMethod,
bool needsDisposeMethod,
Conversion collectionConversion,
Conversion currentConversion,
Conversion enumeratorConversion,
BinderFlags location)
{
Debug.Assert((object)collectionType != null, "Field 'collectionType' cannot be null");
Debug.Assert((object)elementType != null, "Field 'elementType' cannot be null");
Debug.Assert((object)getEnumeratorMethod != null, "Field 'getEnumeratorMethod' cannot be null");
Debug.Assert((object)currentPropertyGetter != null, "Field 'currentPropertyGetter' cannot be null");
Debug.Assert((object)moveNextMethod != null, "Field 'moveNextMethod' cannot be null");
this.CollectionType = collectionType;
this.ElementType = elementType;
this.GetEnumeratorMethod = getEnumeratorMethod;
this.CurrentPropertyGetter = currentPropertyGetter;
this.MoveNextMethod = moveNextMethod;
this.NeedsDisposeMethod = needsDisposeMethod;
this.CollectionConversion = collectionConversion;
this.CurrentConversion = currentConversion;
this.EnumeratorConversion = enumeratorConversion;
this.Location = location;
}
示例4: ConversationWrapper
public ConversationWrapper(Conversion conv, Operand op, Type @from, Type to)
{
_conv = conv;
_op = op;
_to = to;
_from = @from;
}
示例5: ProcessConversion
public void ProcessConversion(Expression expression, ResolveResult result, Conversion conversion, IType targetType)
{
if (!nodesWithConversions.Add(expression))
throw new InvalidOperationException("Duplicate ProcessConversion() call");
if (!conversion.IsValid && !allowErrors) {
Console.WriteLine("Compiler error at " + fileName + ":" + expression.StartLocation + ": Cannot convert from " + result + " to " + targetType);
}
}
示例6: Main
static void Main()
{
Conversion conversions = new Conversion();
double fahr = 62;
double celc = 30;
Console.WriteLine("140 fahrenheit is " + conversions.FarToCel(fahr));
Console.WriteLine("30 celcius is " + conversions.CelToFar(celc));
}
示例7: ConversionResolveResult
public ConversionResolveResult(IType targetType, ResolveResult input, Conversion conversion)
: base(targetType)
{
if (input == null)
throw new ArgumentNullException("input");
this.Input = input;
this.Conversion = conversion;
}
示例8: CreateConversion
protected BoundExpression CreateConversion(
BoundExpression source,
Conversion conversion,
TypeSymbol destination,
DiagnosticBag diagnostics)
{
return CreateConversion(source.Syntax, source, conversion, isCast: false, destination: destination, diagnostics: diagnostics);
}
示例9: TestCast
void TestCast(Type targetType, ResolveResult input, Conversion expectedConversion)
{
IType type = targetType.ToTypeReference().Resolve(context);
ResolveResult rr = resolver.ResolveCast(type, input);
AssertType(targetType, rr);
Assert.AreEqual(typeof(ConversionResolveResult), rr.GetType());
var crr = (ConversionResolveResult)rr;
Assert.AreEqual(expectedConversion, crr.Conversion, "ConversionResolveResult.Conversion");
Assert.AreSame(input, crr.Input, "ConversionResolveResult.Input");
}
示例10: SelectsConversion
public void SelectsConversion()
{
var spec = new IntegerGreaterThanZero();
var converter = (Expression<Func<double, int>>)(d => Math.Sign(d));
var convertedSpec = new Conversion<double, int>(spec, converter);
Assert.That(convertedSpec.IsSatisfiedBy(1), Is.True);
Assert.That(convertedSpec.IsSatisfiedBy(0), Is.False);
Assert.That(convertedSpec.IsSatisfiedBy(-1), Is.False);
}
示例11: TestOperator
void TestOperator(ResolveResult condition, ResolveResult trueExpr, ResolveResult falseExpr,
Conversion conditionConv, Conversion trueConv, Conversion falseConv,
Type expectedResultType)
{
var corr = (ConditionalOperatorResolveResult)resolver.ResolveConditional(condition, trueExpr, falseExpr);
AssertType(expectedResultType, corr);
AssertConversion(corr.Condition, condition, conditionConv, "Condition Conversion");
AssertConversion(corr.True, trueExpr, trueConv, "True Conversion");
AssertConversion(corr.False, falseExpr, falseConv, "False Conversion");
}
示例12: TestCast
void TestCast(Type targetType, ResolveResult input, Conversion expectedConversion)
{
IType type = compilation.FindType(targetType);
ResolveResult rr = resolver.ResolveCast(type, input);
AssertType(targetType, rr);
Assert.AreEqual(typeof(ConversionResolveResult), rr.GetType());
var crr = (ConversionResolveResult)rr;
Assert.AreEqual(expectedConversion, crr.Conversion, "ConversionResolveResult.Conversion");
Assert.AreSame(input, crr.Input, "ConversionResolveResult.Input");
}
示例13: Is
public static Conversion Is(this Tuple<Measurement, Measurement> conversion, decimal absolute)
{
decimal scalar = absolute / conversion.Item1.Value;
var result = new Conversion(conversion.Item1.Unit, conversion.Item2.Unit);
result.AddStep(new ScalingConversion(scalar));
return result;
}
示例14: MakeAsOperator
private BoundExpression MakeAsOperator(
BoundAsOperator oldNode,
CSharpSyntaxNode syntax,
BoundExpression rewrittenOperand,
BoundTypeExpression rewrittenTargetType,
Conversion conversion,
TypeSymbol rewrittenType)
{
// TODO: Handle dynamic operand type and target type
Debug.Assert(rewrittenTargetType.Type.Equals(rewrittenType));
// target type cannot be a non-nullable value type
Debug.Assert(!rewrittenType.IsValueType || rewrittenType.IsNullableType());
if (!_inExpressionLambda)
{
ConstantValue constantValue = Binder.GetAsOperatorConstantResult(rewrittenOperand.Type, rewrittenType, conversion.Kind, rewrittenOperand.ConstantValue);
if (constantValue != null)
{
Debug.Assert(constantValue.IsNull);
BoundExpression result = rewrittenType.IsNullableType() ? new BoundDefaultOperator(syntax, rewrittenType) : MakeLiteral(syntax, constantValue, rewrittenType);
if (rewrittenOperand.ConstantValue != null)
{
// No need to preserve any side-effects from the operand.
// We also can keep the "constant" notion of the result, which
// enables some optimizations down the road.
return result;
}
return new BoundSequence(
syntax: syntax,
locals: ImmutableArray<LocalSymbol>.Empty,
sideEffects: ImmutableArray.Create<BoundExpression>(rewrittenOperand),
value: result,
type: rewrittenType);
}
if (conversion.IsImplicit)
{
// Operand with bound implicit conversion to target type.
// We don't need a runtime check, generate a conversion for the operand instead.
return MakeConversionNode(syntax, rewrittenOperand, conversion, rewrittenType, @checked: false);
}
}
return oldNode.Update(rewrittenOperand, rewrittenTargetType, conversion, rewrittenType);
}
示例15: UserDefinedConversionAnalysis
private UserDefinedConversionAnalysis(
UserDefinedConversionAnalysisKind kind,
MethodSymbol op,
Conversion sourceConversion,
Conversion targetConversion,
TypeSymbol fromType,
TypeSymbol toType)
{
this.Kind = kind;
this.Operator = op;
this.SourceConversion = sourceConversion;
this.TargetConversion = targetConversion;
this.FromType = fromType;
this.ToType = toType;
}