Assert.Equal(1, attr.ObjectArray.Length);
Assert.Null(attr.StringArray);
}
+
+ public class StringValuedAttribute : Attribute
+ {
+ public StringValuedAttribute (string s)
+ {
+ NamedField = s;
+ }
+ public StringValuedAttribute () {}
+ public string NamedProperty
+ {
+ get => NamedField;
+ set { NamedField = value; }
+ }
+ public string NamedField;
+ }
+
+ internal class ClassWithAttrs
+ {
+ [StringValuedAttribute("")]
+ public void M1() {}
+
+ [StringValuedAttribute(NamedProperty = "")]
+ public void M2() {}
+
+ [StringValuedAttribute(NamedField = "")]
+ public void M3() {}
+ }
+
+ [Fact]
+ public void StringAttributeValueRefEqualsStringEmpty () {
+ StringValuedAttribute attr;
+ attr = typeof (ClassWithAttrs).GetMethod("M1")
+ .GetCustomAttributes(typeof(StringValuedAttribute), true)
+ .Cast<StringValuedAttribute>()
+ .Single();
+
+ Assert.Same(string.Empty, attr.NamedField);
+
+ attr = typeof (ClassWithAttrs).GetMethod("M2")
+ .GetCustomAttributes(typeof(StringValuedAttribute), true)
+ .Cast<StringValuedAttribute>()
+ .Single();
+
+ Assert.Same(string.Empty, attr.NamedField);
+
+
+ attr = typeof (ClassWithAttrs).GetMethod("M3")
+ .GetCustomAttributes(typeof(StringValuedAttribute), true)
+ .Cast<StringValuedAttribute>()
+ .Single();
+
+ Assert.Same(string.Empty, attr.NamedField);
+ }
}
}
// to decode some attributes in assemblies that Windows .NET Framework
// and CoreCLR both manage to decode.
// See https://simonsapin.github.io/wtf-8/ for a description of wtf-8.
- *out_obj = (MonoObject*)mono_string_new_wtf8_len_checked (p, slen, error);
+ // Always use string.Empty for empty strings
+ if (slen == 0)
+ *out_obj = (MonoObject*)mono_string_empty_internal (mono_domain_get ());
+ else
+ *out_obj = (MonoObject*)mono_string_new_wtf8_len_checked (p, slen, error);
return NULL;
}
case MONO_TYPE_CLASS: {