Example #1
0
        static LineCodeElementCollection <ICodeElement> MakeEtter(CSVisibility vis, string getset,
                                                                  bool unifiedVis, bool moreRestrictiveVis)
        {
            LineCodeElementCollection <ICodeElement> getLine = new LineCodeElementCollection <ICodeElement> (null, false, true);

            if (!unifiedVis && vis != CSVisibility.None && moreRestrictiveVis)
            {
                getLine.And(new SimpleElememt(CSMethod.VisibilityToString(vis))).And(SimpleElememt.Spacer);
            }
            return(getLine.And(new SimpleElememt(getset, false)));
        }
 protected override void LLWrite(ICodeWriter writer, object o)
 {
     writer.BeginNewLine(true);
     writer.Write(CSMethod.VisibilityToString(Visibility), false);
     writer.Write(" delegate ", true);
     Type.WriteAll(writer);
     writer.Write(' ', true);
     Name.WriteAll(writer);
     writer.Write('(', true);
     Parameters.WriteAll(writer);
     writer.Write(')', true);
     writer.Write(';', false);
     writer.EndLine();
 }
Example #3
0
 public CSFieldDeclaration(CSType type, IEnumerable <CSBinding> bindings, CSVisibility vis = CSVisibility.None, bool isStatic = false, bool isReadonly = false)
     : base(type, bindings)
 {
     Visibilty = vis;
     IsStatic  = isStatic;
     if (isReadonly)
     {
         this.Insert(0, new SimpleElememt("readonly"));
         this.Insert(1, SimpleElememt.Spacer);
     }
     if (isStatic)
     {
         this.Insert(0, new SimpleElememt("static"));
         this.Insert(1, SimpleElememt.Spacer);
     }
     if (vis != CSVisibility.None)
     {
         this.Insert(0, new SimpleElememt(CSMethod.VisibilityToString(vis)));
         this.Insert(1, SimpleElememt.Spacer);
     }
 }
Example #4
0
        CSProperty(CSType type, CSMethodKind kind, CSIdentifier name,
                   CSVisibility getVis, CSCodeBlock getter,
                   CSVisibility setVis, CSCodeBlock setter, CSParameterList parms)
        {
            bool unifiedVis = getVis == setVis;

            IndexerParameters = parms;

            LineCodeElementCollection <ICodeElement> decl = new LineCodeElementCollection <ICodeElement> (null, false, true);

            GetterVisibility = getVis;
            SetterVisibility = setVis;
            CSVisibility bestVis = (CSVisibility)Math.Min((int)getVis, (int)setVis);

            decl.And(new SimpleElememt(CSMethod.VisibilityToString(bestVis))).And(SimpleElememt.Spacer);
            if (kind != CSMethodKind.None)
            {
                decl.And(new SimpleElememt(CSMethod.MethodKindToString(kind))).And(SimpleElememt.Spacer);
            }

            PropType = type;
            Name     = name;

            decl.And(Exceptions.ThrowOnNull(type, "type")).And(SimpleElememt.Spacer)
            .And(Exceptions.ThrowOnNull(name, nameof(name)));
            if (parms != null)
            {
                decl.And(new SimpleElememt("[", true)).And(parms).And(new SimpleElememt("]"));
            }
            Add(decl);


            CSCodeBlock cb = new CSCodeBlock(null);

            if (getter != null)
            {
                Getter = getter;
                LineCodeElementCollection <ICodeElement> getLine = MakeEtter(getVis, "get", unifiedVis, getVis > setVis);
                cb.Add(getLine);
                if (getter.Count() == 0)
                {
                    getLine.Add(new SimpleElememt(";"));
                }
                else
                {
                    cb.Add(getter);
                }
            }
            if (setter != null)
            {
                Setter = setter;
                LineCodeElementCollection <ICodeElement> setLine = MakeEtter(setVis, "set", unifiedVis, setVis > getVis);
                cb.Add(setLine);
                if (setter.Count() == 0)
                {
                    setLine.Add(new SimpleElememt(";"));
                }
                else
                {
                    cb.Add(setter);
                }
            }

            Add(cb);
        }