示例#1
0
        public static FieldReference FromReflection(R.FieldInfo field)
        {
            var s             = FieldSignature.FromReflection(field);
            var declaringType = ((TypeReference.SpecializedTypeCase)TypeReference.FromType(field.DeclaringType)).Item;

            return(new FieldReference(s, declaringType.TypeArguments));
        }
示例#2
0
        /// <summary> Creates a C# automatic property (i.e. `public bool X { get; }` or `public string Y { get; set; }`). Returns the property and its backing field. </summary>
        public static (FieldDef, PropertyDef) CreateAutoProperty(TypeSignature declType, string name, TypeReference propertyType, Accessibility accessibility = null, bool isReadOnly = true, bool isStatic = false, XmlComment doccomment = null)
        {
            accessibility = accessibility ?? Accessibility.APublic;

            var field    = new FieldSignature(declType, string.Format(AutoPropertyField, name), Accessibility.APrivate, propertyType, isStatic, isReadOnly);
            var fieldRef = field.SpecializeFromDeclaringType();
            var prop     = PropertySignature.Create(name, declType, propertyType, accessibility, isReadOnly ? null : accessibility, isStatic);

            var getter = MethodDef.CreateWithArray(prop.Getter, thisP => Expression.FieldAccess(fieldRef, thisP.SingleOrDefault()).Dereference());
            // getter.Attributes.Add(declaringType.Compilation.CompilerGeneratedAttribute());
            var setter = isReadOnly ? null :
                         MethodDef.CreateWithArray(prop.Setter, args => Expression.FieldAccess(fieldRef, args.Length == 1 ? null : args[0].Ref()).ReferenceAssign(args.Last()));

            return(new FieldDef(field),
                   new PropertyDef(prop, getter, setter).With(doccomment: doccomment));
        }
示例#3
0
        internal static string Format(FieldSignature s, TypeReference resultType)
        {
            var sb = new System.Text.StringBuilder();

            if (s.Accessibility != Accessibility.APublic)
            {
                sb.Append(s.Accessibility).Append(" ");
            }
            if (s.IsStatic)
            {
                sb.Append("static ");
            }
            if (s.IsReadonly)
            {
                sb.Append("readonly ");
            }
            sb.Append(s.Name);
            sb.Append(": ");
            sb.Append(resultType);
            return(sb.ToString());
        }
示例#4
0
 static partial void ValidateObjectExtension(ref CoreLib.ValidationErrorsBuilder e, FieldSignature f)
 {
 }
示例#5
0
 public FmtToken Format() => FieldSignature.Format(Signature, ResultType());