本文整理汇总了C#中Mono.CSharp.NewInitialize.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# NewInitialize.Resolve方法的具体用法?C# NewInitialize.Resolve怎么用?C# NewInitialize.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.NewInitialize
的用法示例。
在下文中一共展示了NewInitialize.Resolve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveStringSwitchMap
void ResolveStringSwitchMap (ResolveContext ec)
{
FullNamedExpression string_dictionary_type;
if (TypeManager.generic_ienumerable_type != null) {
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc), "Generic", loc);
string_dictionary_type = new MemberAccess (system_collections_generic, "Dictionary",
new TypeArguments (
new TypeExpression (TypeManager.string_type, loc),
new TypeExpression (TypeManager.int32_type, loc)), loc);
} else {
MemberAccess system_collections_generic = new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc);
string_dictionary_type = new MemberAccess (system_collections_generic, "Hashtable", loc);
}
var ctype = ec.CurrentMemberDefinition.Parent.PartialContainer;
Field field = new Field (ctype, string_dictionary_type,
Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED,
new MemberName (CompilerGeneratedClass.MakeName (null, "f", "switch$map", unique_counter++), loc), null);
if (!field.Define ())
return;
ctype.AddField (field);
var init = new List<Expression> ();
int counter = 0;
Elements.Clear ();
string value = null;
foreach (SwitchSection section in Sections) {
int last_count = init.Count;
foreach (SwitchLabel sl in section.Labels) {
if (sl.Label == null || sl.Converted == SwitchLabel.NullStringCase)
continue;
value = (string) sl.Converted;
var init_args = new List<Expression> (2);
init_args.Add (new StringLiteral (value, sl.Location));
init_args.Add (new IntConstant (counter, loc));
init.Add (new CollectionElementInitializer (init_args, loc));
}
//
// Don't add empty sections
//
if (last_count == init.Count)
continue;
Elements.Add (counter, section.Labels [0]);
++counter;
}
Arguments args = new Arguments (1);
args.Add (new Argument (new IntConstant (init.Count, loc)));
Expression initializer = new NewInitialize (string_dictionary_type, args,
new CollectionOrObjectInitializers (init, loc), loc);
switch_cache_field = new FieldExpr (field, loc);
string_dictionary = new SimpleAssign (switch_cache_field, initializer.Resolve (ec));
}
示例2: ResolveStringSwitchMap
void ResolveStringSwitchMap (EmitContext ec)
{
FullNamedExpression string_dictionary_type;
#if GMCS_SOURCE
MemberAccess system_collections_generic = new MemberAccess (new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc), "Generic", loc);
string_dictionary_type = new MemberAccess (system_collections_generic, "Dictionary",
new TypeArguments (
new TypeExpression (TypeManager.string_type, loc),
new TypeExpression (TypeManager.int32_type, loc)), loc);
#else
MemberAccess system_collections_generic = new MemberAccess (
new QualifiedAliasMember (QualifiedAliasMember.GlobalAlias, "System", loc), "Collections", loc);
string_dictionary_type = new MemberAccess (system_collections_generic, "Hashtable", loc);
#endif
Field field = new Field (ec.TypeContainer, string_dictionary_type,
Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED,
new MemberName (CompilerGeneratedClass.MakeName (null, "f", "switch$map", unique_counter++), loc), null);
if (!field.Define ())
return;
ec.TypeContainer.PartialContainer.AddField (field);
ArrayList init = new ArrayList ();
int counter = 0;
Elements.Clear ();
string value = null;
foreach (SwitchSection section in Sections) {
foreach (SwitchLabel sl in section.Labels) {
if (sl.Label == null || sl.Converted == SwitchLabel.NullStringCase) {
value = null;
continue;
}
value = (string) sl.Converted;
ArrayList init_args = new ArrayList (2);
init_args.Add (new StringLiteral (value, sl.Location));
init_args.Add (new IntConstant (counter, loc));
init.Add (new CollectionElementInitializer (init_args, loc));
}
if (value == null)
continue;
Elements.Add (counter, section.Labels [0]);
++counter;
}
ArrayList args = new ArrayList (1);
args.Add (new Argument (new IntConstant (Sections.Count, loc)));
Expression initializer = new NewInitialize (string_dictionary_type, args,
new CollectionOrObjectInitializers (init, loc), loc);
switch_cache_field = new FieldExpr (field.FieldBuilder, loc);
string_dictionary = new SimpleAssign (switch_cache_field, initializer.Resolve (ec));
}