本文整理汇总了C#中Mono.CSharp.Field类的典型用法代码示例。如果您正苦于以下问题:C# Field类的具体用法?C# Field怎么用?C# Field使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Field类属于Mono.CSharp命名空间,在下文中一共展示了Field类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoResolveLValue
public override Expression DoResolveLValue(ResolveContext ec, Expression right_side)
{
Expression ret = base.DoResolveLValue (ec, right_side);
if (ret == null)
return null;
Field f = new Field (container, new TypeExpression (ret.Type, Location),
Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName (name, Location), null);
container.AddField (f);
if (f.Define ())
Evaluator.QueueField (f);
return ret;
}
示例2: Create
public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + parent.Module.CounterAnonymousTypes++;
ParametersCompiled all_parameters;
TypeParameters tparams = null;
SimpleName[] t_args;
if (parameters.Count == 0) {
all_parameters = ParametersCompiled.EmptyReadOnlyParameters;
t_args = null;
} else {
t_args = new SimpleName[parameters.Count];
tparams = new TypeParameters ();
Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i];
for (int ii = 0; ii < i; ++ii) {
if (parameters[ii].Name == p.Name) {
parent.Compiler.Report.Error (833, parameters[ii].Location,
"`{0}': An anonymous type cannot have multiple properties with the same name",
p.Name);
p = new AnonymousTypeParameter (null, "$" + i.ToString (), p.Location);
parameters[i] = p;
break;
}
}
t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
tparams.Add (new TypeParameter (i, new MemberName (t_args[i].Name, p.Location), null, null, Variance.None));
ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
}
all_parameters = new ParametersCompiled (ctor_params);
}
//
// Create generic anonymous type host with generic arguments
// named upon properties names
//
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.Module, new MemberName (name, tparams, loc), parameters, loc);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, all_parameters, loc);
c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc);
//
// Create fields and constructor body with field initialization
//
bool error = false;
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters [i];
Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("<" + p.Name + ">", p.Location), null);
if (!a_type.AddField (f)) {
error = true;
continue;
}
c.Block.AddStatement (new StatementExpression (
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (i, p.Location))));
ToplevelBlock get_block = new ToplevelBlock (parent.Module.Compiler, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block;
a_type.AddMember (prop);
}
if (error)
return null;
a_type.AddConstructor (c);
return a_type;
}
示例3: HoistedVariable
protected HoistedVariable (AnonymousMethodStorey storey, Field field)
{
this.storey = storey;
this.field = field;
}
示例4: HoistedEvaluatorVariable
public HoistedEvaluatorVariable (Field field)
: base (null, field)
{
}
示例5: Emit
public override void Emit (EmitContext ec)
{
//
// Use same anonymous method implementation for scenarios where same
// code is used from multiple blocks, e.g. field initializers
//
if (method == null) {
//
// Delay an anonymous method definition to avoid emitting unused code
// for unreachable blocks or expression trees
//
method = DoCreateMethodHost (ec);
method.Define ();
}
bool is_static = (method.ModFlags & Modifiers.STATIC) != 0;
if (is_static && am_cache == null) {
//
// Creates a field cache to store delegate instance if it's not generic
//
if (!method.MemberName.IsGeneric) {
var parent = method.Parent.PartialContainer;
int id = parent.AnonymousMethodsCounter++;
var cache_type = storey != null && storey.Mutator != null ? storey.Mutator.Mutate (type) : type;
am_cache = new Field (parent, new TypeExpression (cache_type, loc),
Modifiers.STATIC | Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED,
new MemberName (CompilerGeneratedContainer.MakeName (null, "f", "am$cache", id), loc), null);
am_cache.Define ();
parent.AddField (am_cache);
} else {
// TODO: Implement caching of generated generic static methods
//
// Idea:
//
// Some extra class is needed to capture variable generic type
// arguments. Maybe we could re-use anonymous types, with a unique
// anonymous method id, but they are quite heavy.
//
// Consider : "() => typeof(T);"
//
// We need something like
// static class Wrap<Tn, Tm, DelegateType> {
// public static DelegateType cache;
// }
//
// We then specialize local variable to capture all generic parameters
// and delegate type, e.g. "Wrap<Ta, Tb, DelegateTypeInst> cache;"
//
}
}
Label l_initialized = ec.DefineLabel ();
if (am_cache != null) {
ec.Emit (OpCodes.Ldsfld, am_cache.Spec);
ec.Emit (OpCodes.Brtrue_S, l_initialized);
}
//
// Load method delegate implementation
//
if (is_static) {
ec.EmitNull ();
} else if (storey != null) {
Expression e = storey.GetStoreyInstanceExpression (ec).Resolve (new ResolveContext (ec.MemberContext));
if (e != null) {
e.Emit (ec);
}
} else {
ec.EmitThis ();
//
// Special case for value type storey where this is not lifted but
// droped off to parent class
//
for (var b = Block.Parent; b != null; b = b.Parent) {
if (b.ParametersBlock.StateMachine != null) {
ec.Emit (OpCodes.Ldfld, b.ParametersBlock.StateMachine.HoistedThis.Field.Spec);
break;
}
}
}
var delegate_method = method.Spec;
if (storey != null && storey.MemberName.IsGeneric) {
TypeSpec t = storey.Instance.Type;
//
// Mutate anonymous method instance type if we are in nested
// hoisted generic anonymous method storey
//
if (ec.IsAnonymousStoreyMutateRequired) {
t = storey.Mutator.Mutate (t);
}
ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
} else {
if (delegate_method.IsGeneric)
//.........这里部分代码省略.........
示例6: Visit
public override void Visit(Field f)
{
var location = LocationsBag.GetMemberLocation(f);
var newField = new FieldDeclaration();
AddAttributeSection(newField, f);
AddModifiers(newField, location);
newField.AddChild(ConvertToType(f.TypeExpression), Roles.Type);
var variable = new VariableInitializer();
variable.AddChild(Identifier.Create(f.MemberName.Name, Convert(f.MemberName.Location)), Roles.Identifier);
int locationIdx = 0;
if (f.Initializer != null) {
if (location != null)
variable.AddChild(new CSharpTokenNode(Convert(location [locationIdx++]), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)f.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, 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]), Roles.Comma), Roles.Comma);
variable = new VariableInitializer();
variable.AddChild(Identifier.Create(decl.Name.Value, Convert(decl.Name.Location)), Roles.Identifier);
if (decl.Initializer != null) {
if (declLoc != null)
variable.AddChild(new CSharpTokenNode(Convert(declLoc [1]), Roles.Assign), Roles.Assign);
variable.AddChild((Expression)decl.Initializer.Accept(this), Roles.Expression);
}
newField.AddChild(variable, Roles.Variable);
}
}
if (location != null && location.Count > locationIdx)
newField.AddChild(new CSharpTokenNode(Convert(location [locationIdx++]), Roles.Semicolon), Roles.Semicolon);
typeStack.Peek().AddChild(newField, Roles.TypeMemberRole);
}
示例7: Define
public override bool Define()
{
var mod_flags_src = ModFlags;
if (!base.Define ())
return false;
if (declarators != null) {
if ((mod_flags_src & Modifiers.DEFAULT_ACCESS_MODIFER) != 0)
mod_flags_src &= ~(Modifiers.AccessibilityMask | Modifiers.DEFAULT_ACCESS_MODIFER);
var t = new TypeExpression (MemberType, TypeExpression.Location);
foreach (var d in declarators) {
var ef = new EventField (Parent, t, mod_flags_src, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
ef.initializer = d.Initializer;
ef.Define ();
Parent.PartialContainer.Members.Add (ef);
}
}
if (!HasBackingField) {
SetIsUsed ();
return true;
}
if (Add.IsInterfaceImplementation)
SetIsUsed ();
backing_field = new Field (Parent,
new TypeExpression (MemberType, Location),
Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
MemberName, null);
Parent.PartialContainer.Members.Add (backing_field);
backing_field.Initializer = Initializer;
backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
// Call define because we passed fields definition
backing_field.Define ();
// Set backing field for event fields
spec.BackingField = backing_field.Spec;
return true;
}
示例8: AddCompilerGeneratedField
protected Field AddCompilerGeneratedField (string name, FullNamedExpression type)
{
const Modifiers mod = Modifiers.INTERNAL | Modifiers.COMPILER_GENERATED;
Field f = new Field (this, type, mod, new MemberName (name, Location), null);
AddField (f);
return f;
}
示例9: AssemblyAttributesPlaceholder
public AssemblyAttributesPlaceholder (ModuleContainer parent, string outputName)
: base (parent, new MemberName (GetGeneratedName (outputName)), Modifiers.STATIC)
{
assembly = new Field (this, new TypeExpression (TypeManager.object_type, Location), Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName (AssemblyFieldName), null);
AddField (assembly);
}
示例10: Visit
public virtual void Visit (Field f)
{
}
示例11: Create
public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + types_counter++;
SimpleName [] t_args = new SimpleName [parameters.Count];
TypeParameterName [] t_params = new TypeParameterName [parameters.Count];
Parameter [] ctor_params = new Parameter [parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
t_args [i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params [i] = new TypeParameterName (t_args [i].Name, null, p.Location);
ctor_params [i] = new Parameter (t_args [i], p.Name, 0, null, p.Location);
}
//
// Create generic anonymous type host with generic arguments
// named upon properties names
//
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.NamespaceEntry.SlaveDeclSpace,
new MemberName (name, new TypeArguments (t_params), loc), parameters, loc);
if (parameters.Count > 0)
a_type.SetParameterInfo (null);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, new AnonymousParameters (ctx, ctor_params), null, loc);
c.Block = new ToplevelBlock (ctx, c.ParameterInfo, loc);
//
// Create fields and contructor body with field initialization
//
bool error = false;
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY,
new MemberName ("<" + p.Name + ">", p.Location), null);
if (!a_type.AddField (f)) {
error = true;
continue;
}
c.Block.AddStatement (new StatementExpression (
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (p.Name, p.Location))));
ToplevelBlock get_block = new ToplevelBlock (ctx, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block;
a_type.AddProperty (prop);
}
if (error)
return null;
a_type.AddConstructor (c);
return a_type;
}
示例12: 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));
}
示例13: CreateEvaluatorVariable
void CreateEvaluatorVariable (BlockContext bc, LocalVariable li)
{
var container = bc.CurrentMemberDefinition.Parent;
Field f = new Field (container, new TypeExpression (li.Type, li.Location), Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName (li.Name, li.Location), null);
container.AddField (f);
f.Define ();
Evaluator.QueueField (f);
li.HoistedVariant = new HoistedEvaluatorVariable (f);
li.SetIsUsed ();
}
示例14: Define
public override bool Define ()
{
if (!base.Define ())
return false;
try {
Type[] required_modifier = null;
if ((ModFlags & Modifiers.VOLATILE) != 0) {
if (TypeManager.isvolatile_type == null)
TypeManager.isvolatile_type = TypeManager.CoreLookupType (Compiler,
"System.Runtime.CompilerServices", "IsVolatile", MemberKind.Class, true);
if (TypeManager.isvolatile_type != null)
required_modifier = new Type[] { TypeManager.isvolatile_type.GetMetaInfo () };
}
FieldBuilder = Parent.TypeBuilder.DefineField (
Name, member_type.GetMetaInfo (), required_modifier, null, ModifiersExtensions.FieldAttr (ModFlags));
spec = new FieldSpec (Parent.Definition, this, MemberType, FieldBuilder, ModFlags);
// Don't cache inaccessible fields
if ((ModFlags & Modifiers.BACKING_FIELD) == 0) {
Parent.MemberCache.AddMember (spec);
}
if (initializer != null) {
((TypeContainer) Parent).RegisterFieldForInitialization (this,
new FieldInitializer (spec, initializer, this));
}
} catch (ArgumentException) {
Report.RuntimeMissingSupport (Location, "`void' or `void*' field type");
return false;
}
if (declarators != null) {
var t = new TypeExpression (MemberType, TypeExpression.Location);
int index = Parent.PartialContainer.Fields.IndexOf (this);
foreach (var d in declarators) {
var f = new Field (Parent, t, ModFlags, new MemberName (d.Name.Value, d.Name.Location), OptAttributes);
if (d.Initializer != null)
f.initializer = d.Initializer;
Parent.PartialContainer.Fields.Insert (++index, f);
}
}
return true;
}
示例15: DynamicFieldExpr
public DynamicFieldExpr(Field field, Location loc)
: base(loc)
{
this.field = field;
}