本文整理汇总了C#中Mono.CSharp.Const.Define方法的典型用法代码示例。如果您正苦于以下问题:C# Const.Define方法的具体用法?C# Const.Define怎么用?C# Const.Define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.Const
的用法示例。
在下文中一共展示了Const.Define方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}