本文整理汇总了C#中Mono.CSharp.Const类的典型用法代码示例。如果您正苦于以下问题:C# Const类的具体用法?C# Const怎么用?C# Const使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Const类属于Mono.CSharp命名空间,在下文中一共展示了Const类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Define
/// <summary>
/// Defines the constant in the @parent
/// </summary>
public override bool Define ()
{
if (!base.Define ())
return false;
if (!member_type.IsConstantCompatible) {
Error_InvalidConstantType (member_type, Location, Report);
}
FieldAttributes field_attr = FieldAttributes.Static | ModifiersExtensions.FieldAttr (ModFlags);
// Decimals cannot be emitted into the constant blob. So, convert to 'readonly'.
if (member_type.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
field_attr |= FieldAttributes.InitOnly;
} else {
field_attr |= FieldAttributes.Literal;
}
FieldBuilder = Parent.TypeBuilder.DefineField (Name, MemberType.GetMetaInfo (), field_attr);
spec = new ConstSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags, initializer);
Parent.MemberCache.AddMember (spec);
if ((field_attr & FieldAttributes.InitOnly) != 0)
Parent.PartialContainer.RegisterFieldForInitialization (this,
new FieldInitializer (this, initializer, Location));
if (declarators != null) {
foreach (var d in declarators) {
var t = new TypeExpression (d.Type, TypeExpression.Location);
var c = new Const (Parent, t, ModFlags & ~Modifiers.STATIC, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
c.initializer = d.Initializer;
if (d.Initializer is ConstInitializer)
((ConstInitializer)d.Initializer).Field = c;
((ConstInitializer) c.initializer).Name = d.Name.Value;
c.Define ();
Parent.PartialContainer.Members.Add (c);
}
}
return true;
}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:44,代码来源:const.cs
示例2: AddConstant
public void AddConstant (Const constant)
{
if (!AddMember (constant))
return;
if (constants == null)
constants = new List<MemberCore> ();
constants.Add (constant);
}
开发者ID:jordanbtucker,项目名称:mono,代码行数:10,代码来源:class.cs
示例3: Visit
public override void Visit (Const f)
{
var location = LocationsBag.GetMemberLocation (f);
FieldDeclaration newField = new FieldDeclaration ();
AddModifiers (newField, location);
if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[1]), "fixed".Length), FieldDeclaration.Roles.Keyword);
newField.AddChild ((INode)f.TypeName.Accept (this), FieldDeclaration.Roles.ReturnType);
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), FieldDeclaration.Roles.Identifier);
if (f.Initializer != null) {
if (location != null)
variable.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((INode)f.Initializer.Accept (this), FieldDeclaration.Roles.Initializer);
}
newField.AddChild (variable, FieldDeclaration.Roles.Initializer);
if (f.Declarators != null) {
foreach (var decl in f.Declarators) {
var declLoc = LocationsBag.GetLocations (decl);
if (declLoc != null)
newField.AddChild (new CSharpTokenNode (Convert (declLoc[declLoc.Count - 1]), 1), FieldDeclaration.Roles.Comma);
variable = new VariableInitializer ();
variable.AddChild (new Identifier (decl.Name.Value, Convert (decl.Name.Location)), FieldDeclaration.Roles.Identifier);
if (decl.Initializer != null) {
if (declLoc != null)
variable.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((INode)decl.Initializer.Accept (this), FieldDeclaration.Roles.Initializer);
}
newField.AddChild (variable, FieldDeclaration.Roles.Initializer);
}
}
if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[location.Count - 1]), 1), FieldDeclaration.Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.Roles.Member);
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:43,代码来源:CSharpParser.cs
示例4: Visit
public override void Visit(Const c)
{
var location = LocationsBag.GetMemberLocation(c);
var newField = new FieldDeclaration();
AddAttributeSection(newField, c);
AddModifiers(newField, location);
if (location != null)
newField.AddChild(new CSharpModifierToken(Convert(location [0]), Modifiers.Const), EntityDeclaration.ModifierRole);
newField.AddChild(ConvertToType(c.TypeExpression), Roles.Type);
var variable = new VariableInitializer();
variable.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
if (c.Initializer != null) {
variable.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)c.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, Roles.Variable);
if (c.Declarators != null) {
foreach (var decl in c.Declarators) {
var declLoc = LocationsBag.GetLocations(decl);
if (declLoc != null)
newField.AddChild(new CSharpTokenNode(Convert(declLoc [0]), Roles.Comma), Roles.Comma);
variable = new VariableInitializer();
variable.AddChild(Identifier.Create(decl.Name.Value, Convert(decl.Name.Location)), Roles.Identifier);
if (decl.Initializer != null) {
variable.AddChild(new CSharpTokenNode(Convert(decl.Initializer.Location), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, Roles.Variable);
}
}
if (location != null)
newField.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.Semicolon), Roles.Semicolon);
typeStack.Peek().AddChild(newField, Roles.TypeMemberRole);
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:41,代码来源:CSharpParser.cs
示例5: Visit
public override void Visit (Const f)
{
DomField field = new DomField ();
field.Name = ConvertQuoted (f.MemberName.Name);
field.Documentation = RetrieveDocumentation (f.Location.Row);
field.Location = Convert (f.MemberName.Location);
field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Const;
field.ReturnType = ConvertReturnType (f.TypeName);
AddAttributes (field, f.OptAttributes, f);
field.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (field);
if (f.Declarators != null) {
foreach (var decl in f.Declarators) {
field = new DomField ();
field.Name = ConvertQuoted (decl.Name.Value);
field.Location = Convert (decl.Name.Location);
field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Const;
field.ReturnType = ConvertReturnType (f.TypeName);
AddAttributes (field, f.OptAttributes, f);
field.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (field);
}
}
}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:24,代码来源:McsParser.cs
示例6: Visit
public virtual void Visit (Const c)
{
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:3,代码来源:visit.cs
示例7: EnumInitializer
public EnumInitializer(Const field, Expression init, EnumMember prev)
: base(field, init)
{
this.prev = prev;
}
开发者ID:speier,项目名称:shake,代码行数:5,代码来源:enum.cs
示例8: yyparse
//.........这里部分代码省略.........
var lt = (Tokenizer.LocatedToken) yyVals[-3+yyTop];
yyVal = new NamedArgument (lt.Value, lt.Location, (Expression) yyVals[0+yyTop], arg_mod);
}
break;
case 86:
#line 879 "cs-parser.jay"
{ yyVal = null; }
break;
case 87:
#line 881 "cs-parser.jay"
{
yyVal = Argument.AType.Ref;
}
break;
case 88:
#line 885 "cs-parser.jay"
{
yyVal = Argument.AType.Out;
}
break;
case 104:
#line 917 "cs-parser.jay"
{
Report.Error (1519, lexer.Location, "Unexpected symbol `{0}' in class, struct, or interface member declaration",
GetSymbolName (yyToken));
yyVal = null;
lexer.parsing_generic_declaration = false;
}
break;
case 105:
#line 930 "cs-parser.jay"
{
lexer.ConstraintsParsing = true;
}
break;
case 106:
#line 934 "cs-parser.jay"
{
MemberName name = MakeName ((MemberName) yyVals[0+yyTop]);
push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) yyVals[-4+yyTop], (Attributes) yyVals[-5+yyTop]), yyVals[-3+yyTop]);
}
break;
case 107:
#line 940 "cs-parser.jay"
{
lexer.ConstraintsParsing = false;
current_class.SetParameterInfo ((List<Constraints>) yyVals[0+yyTop]);
if (RootContext.Documentation != null)
current_container.DocComment = Lexer.consume_doc_comment ();
}
break;
case 108:
#line 949 "cs-parser.jay"
{
--lexer.parsing_declaration;
if (RootContext.Documentation != null)
Lexer.doc_state = XmlCommentState.Allowed;
}
break;
case 109:
#line 955 "cs-parser.jay"
{
yyVal = pop_current_class ();
开发者ID:speier,项目名称:shake,代码行数:67,代码来源:cs-parser.cs
示例9: AddConstant
public AdditionResult AddConstant (Const constant)
{
AdditionResult res;
string basename = constant.Name;
string fullname = Name + "." + basename;
if ((res = IsValid (fullname)) != AdditionResult.Success)
return res;
if (constants == null)
constants = new ArrayList ();
constants.Add (constant);
DefineName (fullname, constant);
return AdditionResult.Success;
}
开发者ID:emtees,项目名称:old-code,代码行数:17,代码来源:class.cs
示例10: Visit
public override void Visit (Const f)
{
var location = LocationsBag.GetMemberLocation (f);
FieldDeclaration newField = new FieldDeclaration ();
AddAttributeSection (newField, f);
AddModifiers (newField, location);
if (location != null)
newField.AddChild (new CSharpModifierToken (Convert (location[0]), Modifiers.Const), AttributedNode.ModifierRole);
newField.AddChild (ConvertToType (f.TypeName), FieldDeclaration.Roles.Type);
VariableInitializer variable = new VariableInitializer ();
variable.AddChild (new Identifier (f.MemberName.Name, Convert (f.MemberName.Location)), VariableInitializer.Roles.Identifier);
if (f.Initializer != null) {
variable.AddChild (new CSharpTokenNode (Convert (f.Initializer.Location), 1), VariableInitializer.Roles.Assign);
variable.AddChild ((Expression)f.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
if (f.Declarators != null) {
foreach (var decl in f.Declarators) {
var declLoc = LocationsBag.GetLocations (decl);
if (declLoc != null)
newField.AddChild (new CSharpTokenNode (Convert (declLoc[0]), 1), FieldDeclaration.Roles.Comma);
variable = new VariableInitializer ();
variable.AddChild (new Identifier (decl.Name.Value, Convert (decl.Name.Location)), FieldDeclaration.Roles.Identifier);
if (decl.Initializer != null) {
variable.AddChild (new CSharpTokenNode (Convert (decl.Initializer.Location), 1), FieldDeclaration.Roles.Assign);
variable.AddChild ((Expression)decl.Initializer.Accept (this), VariableInitializer.Roles.Expression);
}
newField.AddChild (variable, FieldDeclaration.Roles.Variable);
}
}
if (location != null)
newField.AddChild (new CSharpTokenNode (Convert (location[1]), 1), FieldDeclaration.Roles.Semicolon);
typeStack.Peek ().AddChild (newField, TypeDeclaration.MemberRole);
}
开发者ID:hduregger,项目名称:monodevelop,代码行数:41,代码来源:CSharpParser.cs
示例11: Visit
public override void Visit (Const f)
{
DomField field = new DomField ();
field.Name = f.MemberName.Name;
field.Documentation = RetrieveDocumentation (f.Location.Row);
field.Location = Convert (f.MemberName.Location);
field.Modifiers = ConvertModifiers (f.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.Fixed;
field.ReturnType = ConvertReturnType (f.TypeName);
AddAttributes (field, f.OptAttributes);
field.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (field);
}
开发者ID:pgoron,项目名称:monodevelop,代码行数:12,代码来源:McsParser.cs
注:本文中的Mono.CSharp.Const类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论