public override void Emit ()
{
-#if GMCS_SOURCE
- if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0)
+#if GMCS_SOURCE
+ if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0) {
FieldBuilder.SetCustomAttribute (TypeManager.compiler_generated_attr);
+ }
#endif
if (OptAttributes != null) {
Modifiers.INTERNAL |
Modifiers.PRIVATE |
Modifiers.STATIC |
- Modifiers.VOLATILE |
- Modifiers.UNSAFE |
+ Modifiers.VOLATILE |
+ Modifiers.UNSAFE |
Modifiers.READONLY;
public Field (DeclSpace parent, Expression type, int mod, string name,
//
// Check for custom access modifier
//
- if (ModFlags == 0) {
- ModFlags = method.ModFlags;
+ if ((ModFlags & Modifiers.Accessibility) == 0) {
+ ModFlags |= method.ModFlags;
flags = method.flags;
} else {
if (container.Kind == Kind.Interface)
void CheckModifiers (int modflags)
{
+ modflags &= Modifiers.Accessibility;
int flags = 0;
int mflags = method.ModFlags & Modifiers.Accessibility;
//
// Accessors modifiers check
//
- if (Get.ModFlags != 0 && Set.ModFlags != 0) {
+ if ((Get.ModFlags & Modifiers.Accessibility) != 0 &&
+ (Set.ModFlags & Modifiers.Accessibility) != 0) {
Report.Error (274, Location, "`{0}': Cannot specify accessibility modifiers for both accessors of the property or indexer",
GetSignatureForError ());
return false;
const int AllowedInterfaceModifiers =
Modifiers.NEW;
+ void CreateAutomaticProperty (Block block, Accessor get_block, Accessor set_block)
+ {
+ // Make the field
+ Field field = new Field (
+ Parent, Type,
+ Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & Modifiers.STATIC),
+ CompilerGeneratedClass.MakeName ("CompilerGeneratedField"),
+ null, Location);
+ ((TypeContainer)Parent).AddField (field);
+
+ // Make get block
+ get_block.Block = new ToplevelBlock (block, null, Location);
+ Return r = new Return (new SimpleName(field.Name, Location), Location);
+ get_block.Block.AddStatement (r);
+ get_block.ModFlags |= Modifiers.COMPILER_GENERATED;
+
+ // Make set block
+ Parameters parameters = new Parameters (new Parameter (Type, "value", Parameter.Modifier.NONE, null, Location));
+ set_block.Block = new ToplevelBlock (block, parameters, Location);
+ Assign a = new Assign (new SimpleName(field.Name, Location), new SimpleName ("value", Location));
+ set_block.Block.AddStatement (new StatementExpression(a));
+ set_block.ModFlags |= Modifiers.COMPILER_GENERATED;
+ }
+
public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
MemberName name, Attributes attrs, Accessor get_block,
Accessor set_block, bool define_set_first)
+ : this (parent, type, mod, is_iface, name, attrs, get_block, set_block,
+ define_set_first, null)
+ {
+ }
+
+ public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
+ MemberName name, Attributes attrs, Accessor get_block,
+ Accessor set_block, bool define_set_first, Block current_block)
: base (parent, type, mod,
is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
is_iface, name, attrs, define_set_first)
{
+ if (RootContext.Version >= LanguageVersion.LINQ &&
+ !is_iface &&
+ (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
+ get_block != null && get_block.Block == null &&
+ set_block != null && set_block.Block == null)
+ CreateAutomaticProperty (current_block, get_block, set_block);
+
if (get_block == null)
Get = new GetMethod (this);
else
}
}
}
+
--- /dev/null
+// Compiler options: -langversion:linq
+// Make sure that the field and accessor methods of an automatic property have the CompilerGenerated attribute
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+public class Test
+{
+ public string Foo { get; set; }
+
+ static int Main ()
+ {
+ FieldInfo [] fields = typeof (Test).GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
+ if (!(fields.Length > 0))
+ return 1;
+ object [] field_atts = fields[0].GetCustomAttributes (false);
+ if (!(field_atts.Length > 0))
+ return 2;
+ if (field_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
+ return 3;
+
+ PropertyInfo property = typeof (Test).GetProperty ("Foo");
+ MethodInfo get = property.GetGetMethod (false);
+ object [] get_atts = get.GetCustomAttributes (false);
+ if (!(get_atts.Length > 0))
+ return 4;
+ if (get_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
+ return 5;
+
+ MethodInfo set = property.GetSetMethod (false);
+ object [] set_atts = set.GetCustomAttributes (false);
+ if (!(set_atts.Length > 0))
+ return 6;
+ if (set_atts[0].GetType() != typeof (CompilerGeneratedAttribute))
+ return 7;
+
+ return 0;
+ }
+}