本文整理汇总了C#中ConstantValue类的典型用法代码示例。如果您正苦于以下问题:C# ConstantValue类的具体用法?C# ConstantValue怎么用?C# ConstantValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstantValue类属于命名空间,在下文中一共展示了ConstantValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SourceStrictComplexParameterSymbol
internal SourceStrictComplexParameterSymbol(
DiagnosticBag diagnostics,
Binder binder,
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
string name,
ImmutableArray<Location> locations,
SyntaxReference syntaxRef,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis)
: base(
owner: owner,
ordinal: ordinal,
parameterType: parameterType,
refKind: refKind,
name: name,
locations: locations,
syntaxRef: syntaxRef,
defaultSyntaxValue: defaultSyntaxValue,
isParams: isParams,
isExtensionMethodThis: isExtensionMethodThis)
{
_tempBinder = binder;
var unused = GetAttributesBag(diagnostics);
_lazyDefaultSyntaxValue = MakeDefaultExpression(diagnostics, binder);
_tempBinder = null; // no need to keep it around anymore, just uses up a lot of memory
}
示例2: MakeLiteral
private BoundExpression MakeLiteral(CSharpSyntaxNode syntax, ConstantValue constantValue, TypeSymbol type, BoundLiteral oldNodeOpt = null)
{
Debug.Assert(constantValue != null);
if (constantValue.IsDecimal)
{
// Rewrite decimal literal
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_Decimal);
return MakeDecimalLiteral(syntax, constantValue);
}
else if (constantValue.IsDateTime)
{
// C# does not support DateTime constants but VB does; we might have obtained a
// DateTime constant by calling a method with an optional parameter with a DateTime
// for its default value.
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_DateTime);
return MakeDateTimeLiteral(syntax, constantValue);
}
else if (oldNodeOpt != null)
{
return oldNodeOpt.Update(constantValue, type);
}
else
{
return new BoundLiteral(syntax, constantValue, type, hasErrors: constantValue.IsBad);
}
}
示例3: MultiplicationMemoryOp
public MultiplicationMemoryOp(int offset, int scalar, ConstantValue constant, ConstantValue multiplicationConstant)
{
Offset = offset;
Scalar = scalar;
Constant = constant;
MultiplicationConstant = multiplicationConstant;
}
示例4: PrepareCriteria
public CriteriaOperator PrepareCriteria(CriteriaOperator op)
{
if (op is FunctionOperator)
{
var funcOp = new FunctionOperator();
for (int i = 0; i < (op as FunctionOperator).Operands.Count; i++)
funcOp.Operands.Add(PrepareCriteria((op as FunctionOperator).Operands[i]));
return funcOp;
}
else if (op is ConstantValue)
{
var cnst = new ConstantValue((op as ConstantValue).Value);
if (String.Concat((op as ConstantValue).Value).ToLower().IndexOf("@this") > -1)
{
IMemberInfo info;
cnst.Value = ObjectFormatValues.GetValueRecursive((op as ConstantValue).Value.ToString().Replace("@This.", "").Replace("@This", "").Replace("@this.", "").Replace("@this", ""), CurrentObject, out info);
}
return cnst;
}
else if (op is BinaryOperator)
{
var binary = new BinaryOperator();
binary.LeftOperand = PrepareCriteria((op as BinaryOperator).LeftOperand);
binary.RightOperand = PrepareCriteria((op as BinaryOperator).RightOperand);
return binary;
}
else
{
return op;
}
}
示例5: RewriteConditionalOperator
private static BoundExpression RewriteConditionalOperator(
CSharpSyntaxNode syntax,
BoundExpression rewrittenCondition,
BoundExpression rewrittenConsequence,
BoundExpression rewrittenAlternative,
ConstantValue constantValueOpt,
TypeSymbol rewrittenType)
{
// NOTE: This optimization assumes that a constant has no side effects. In the future we
// might wish to represent nodes that are known to the optimizer as having constant
// values as a sequence of side effects and a constant value; in that case the result
// of this should be a sequence containing the side effect and the consequence or alternative.
ConstantValue conditionConstantValue = rewrittenCondition.ConstantValue;
if (conditionConstantValue == ConstantValue.True)
{
return rewrittenConsequence;
}
else if (conditionConstantValue == ConstantValue.False)
{
return rewrittenAlternative;
}
else
{
return new BoundConditionalOperator(
syntax,
rewrittenCondition,
rewrittenConsequence,
rewrittenAlternative,
constantValueOpt,
rewrittenType);
}
}
示例6: MakeFieldAccess
private BoundExpression MakeFieldAccess(
CSharpSyntaxNode syntax,
BoundExpression rewrittenReceiver,
FieldSymbol fieldSymbol,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type,
BoundFieldAccess oldNodeOpt = null)
{
if (fieldSymbol.IsTupleField)
{
return MakeTupleFieldAccess(syntax, fieldSymbol, rewrittenReceiver, constantValueOpt, resultKind);
}
BoundExpression result = oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type) :
new BoundFieldAccess(syntax, rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type);
if (fieldSymbol.IsFixed)
{
// a reference to a fixed buffer is translated into its address
result = new BoundConversion(syntax,
new BoundAddressOfOperator(syntax, result, syntax != null && SyntaxFacts.IsFixedStatementExpression(syntax), type, false),
new Conversion(ConversionKind.PointerToPointer), false, false, default(ConstantValue), type, false);
}
return result;
}
示例7: SourceLabelSymbol
public SourceLabelSymbol(
MethodSymbol containingMethod,
ConstantValue switchCaseLabelConstant)
{
_containingMethod = containingMethod;
_identifierNodeOrToken = default(SyntaxToken);
_switchCaseLabelConstant = switchCaseLabelConstant;
}
示例8: Update
public BoundFieldAccess Update(
BoundExpression receiver,
FieldSymbol fieldSymbol,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol typeSymbol)
{
return this.Update(receiver, fieldSymbol, constantValueOpt, resultKind, this.IsByValue, typeSymbol);
}
示例9: BoundFieldAccess
public BoundFieldAccess(
CSharpSyntaxNode syntax,
BoundExpression receiver,
FieldSymbol fieldSymbol,
ConstantValue constantValueOpt,
bool hasErrors = false)
: this(syntax, receiver, fieldSymbol, constantValueOpt, LookupResultKind.Viable, fieldSymbol.Type, hasErrors)
{
}
示例10: SourceLabelSymbol
public SourceLabelSymbol(
MethodSymbol containingMethod,
ConstantValue switchCaseLabelConstant = null)
: base(switchCaseLabelConstant.ToString())
{
this.containingMethod = containingMethod;
this.identifierNodeOrToken = default(SyntaxToken);
this.switchCaseLabelConstant = switchCaseLabelConstant;
}
示例11: SynthesizedFieldSymbol
public SynthesizedFieldSymbol(
NamedTypeSymbol containing,
TypeSymbol type,
string name,
Accessibility accessibility,
ConstantValue constant)
:this(containing, type, name, accessibility, true)
{
_const = constant;
}
示例12: EELocalConstantSymbol
public EELocalConstantSymbol(
MethodSymbol method,
string name,
TypeSymbol type,
ConstantValue value)
{
_method = method;
_name = name;
_type = type;
_value = value;
}
示例13: Create
public static ITypeRef Create(ConstantValue c)
{
Contract.ThrowIfNull(c);
switch (c.SpecialType)
{
case SpecialType.System_Int32:
case SpecialType.System_Int64: return LongTypeRef;
case SpecialType.System_String: return StringTypeRef;
case SpecialType.System_Double: return DoubleTypeRef;
case SpecialType.System_Boolean: return BoolTypeRef;
default:
throw new NotImplementedException();
}
}
示例14: MakeTupleFieldAccess
/// <summary>
/// Converts access to a tuple instance into access into the underlying ValueTuple(s).
///
/// For instance, tuple.Item8
/// produces fieldAccess(field=Item1, receiver=fieldAccess(field=Rest, receiver=ValueTuple for tuple))
/// </summary>
private BoundExpression MakeTupleFieldAccess(
CSharpSyntaxNode syntax,
FieldSymbol tupleField,
BoundExpression rewrittenReceiver,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type)
{
var tupleType = tupleField.ContainingType;
NamedTypeSymbol currentLinkType = tupleType.TupleUnderlyingType;
FieldSymbol underlyingField = tupleField.TupleUnderlyingField;
if ((object)underlyingField == null)
{
// Use-site error must have been reported elsewhere.
return new BoundFieldAccess(syntax, rewrittenReceiver, tupleField, constantValueOpt, resultKind, type, hasErrors: true);
}
if (underlyingField.ContainingType != currentLinkType)
{
WellKnownMember wellKnownTupleRest = TupleTypeSymbol.GetTupleTypeMember(TupleTypeSymbol.RestPosition, TupleTypeSymbol.RestPosition);
var tupleRestField = (FieldSymbol)TupleTypeSymbol.GetWellKnownMemberInType(currentLinkType.OriginalDefinition, wellKnownTupleRest, _diagnostics, syntax);
if ((object)tupleRestField == null)
{
// error tolerance for cases when Rest is missing
return new BoundFieldAccess(syntax, rewrittenReceiver, tupleField, constantValueOpt, resultKind, type, hasErrors: true);
}
// make nested field accesses to Rest
do
{
FieldSymbol nestedFieldSymbol = tupleRestField.AsMember(currentLinkType);
currentLinkType = currentLinkType.TypeArgumentsNoUseSiteDiagnostics[TupleTypeSymbol.RestPosition - 1].TupleUnderlyingType;
rewrittenReceiver = new BoundFieldAccess(syntax, rewrittenReceiver, nestedFieldSymbol, ConstantValue.NotAvailable, LookupResultKind.Viable, currentLinkType);
}
while (underlyingField.ContainingType != currentLinkType);
}
// make a field access for the most local access
return new BoundFieldAccess(syntax, rewrittenReceiver, underlyingField, constantValueOpt, resultKind, type);
}
示例15: SourcePrimaryConstructorParameterSymbolWithBackingField
internal SourcePrimaryConstructorParameterSymbolWithBackingField(
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
string name,
ImmutableArray<Location> locations,
ParameterSyntax syntax,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis,
DiagnosticBag diagnostics
) : base(owner, ordinal, parameterType, refKind, ImmutableArray<CustomModifier>.Empty, false, name, locations, syntax.GetReference(), defaultSyntaxValue, isParams, isExtensionMethodThis)
{
bool modifierErrors;
var modifiers = SourceMemberFieldSymbol.MakeModifiers(owner.ContainingType, syntax.Identifier, syntax.Modifiers, diagnostics, out modifierErrors, ignoreParameterModifiers: true);
backingField = new BackingField(this, modifiers, modifierErrors, diagnostics);
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:19,代码来源:SourcePrimaryConstructorParameterSymbolWithBackingField.cs