Exemplo n.º 1
0
 public CSLambda(CSParameterList parameters, CSCodeBlock body)
 {
     body       = body ?? new CSCodeBlock();
     Parameters = parameters ?? new CSParameterList();
     Value      = null;
     Body       = body;
 }
Exemplo n.º 2
0
 public CSProperty(CSType type, CSMethodKind kind,
                   CSVisibility getVis, CSCodeBlock getter,
                   CSVisibility setVis, CSCodeBlock setter, CSParameterList parms)
     : this(type, kind, new CSIdentifier("this"), getVis, getter, setVis, setter,
            Exceptions.ThrowOnNull(parms, nameof(parms)))
 {
 }
Exemplo n.º 3
0
 public CSForEach(CSType type, CSIdentifier ident, CSBaseExpression expr, CSCodeBlock body)
 {
     Type  = type;
     Ident = Exceptions.ThrowOnNull(ident, nameof(ident));
     Expr  = Exceptions.ThrowOnNull(expr, nameof(expr));
     Body  = body ?? new CSCodeBlock();
     Add(new ForElement(type, ident, expr));
     Add(Body);
 }
Exemplo n.º 4
0
        public CSTryCatch(CSCodeBlock tryBlock, params CSCatch [] catchBlocks)
        {
            TryBlock    = tryBlock ?? new CSCodeBlock();
            CatchBlocks = new CodeElementCollection <CSCatch> ();
            CatchBlocks.AddRange(catchBlocks);

            Add(new SimpleElememt("try ", true));
            Add(TryBlock);
            Add(CatchBlocks);
        }
Exemplo n.º 5
0
        public CSMethod(CSVisibility vis, CSMethodKind kind, CSType type, CSIdentifier name,
                        CSParameterList parms, CSBaseExpression[] baseOrThisCallParms, bool callsBase, CSCodeBlock body, bool isSealed = false)
        {
            GenericParameters  = new CSGenericTypeDeclarationCollection();
            GenericConstraints = new CSGenericConstraintCollection();
            Visibility         = vis;
            Kind       = kind;
            Type       = type;       // no throw on null - could be constructor
            Name       = Exceptions.ThrowOnNull(name, nameof(name));
            Parameters = Exceptions.ThrowOnNull(parms, nameof(parms));
            CallsBase  = callsBase;
            BaseOrThisCallParameters = baseOrThisCallParms;

            Body     = body;         // can be null
            IsSealed = isSealed;

            LineCodeElementCollection <ICodeElement> lc = new LineCodeElementCollection <ICodeElement> (new ICodeElement [0], false, true);

            if (vis != CSVisibility.None)
            {
                lc.And(new SimpleElememt(VisibilityToString(vis))).And(SimpleElememt.Spacer);
            }

            if (isSealed)
            {
                lc.And(new SimpleElememt("sealed")).And(SimpleElememt.Spacer);
            }

            lc.And(new SimpleElememt(MethodKindToString(kind))).And(SimpleElememt.Spacer);

            if (type != null)
            {
                lc.And(type).And(SimpleElememt.Spacer);
            }

            lc.And(name).And(GenericParameters).And(new SimpleElememt("(")).And(parms).And(new SimpleElememt(")")).And(GenericConstraints);
            if (body == null)
            {
                if (!(kind == CSMethodKind.StaticExtern || kind == CSMethodKind.Interface))
                {
                    throw new ArgumentException("Method body is only optional when method kind kind is either StaticExtern or Interface",
                                                nameof(body));
                }
                lc.Add(new SimpleElememt(";"));
            }
            Add(lc);
            if (BaseOrThisCallParameters != null)
            {
                Add(new CSFunctionCall(CallsBase ? ": base" : ": this", false, BaseOrThisCallParameters));
            }
            if (body != null)
            {
                Add(body);
            }
        }
Exemplo n.º 6
0
        public CSIfElse(CSBaseExpression condition, CSCodeBlock ifClause, CSCodeBlock elseClause = null)
            : base()
        {
            Condition  = new CSIfElement(Exceptions.ThrowOnNull(condition, "condition"));
            IfClause   = Exceptions.ThrowOnNull(ifClause, "ifClause");
            ElseClause = elseClause;

            Add(Condition);
            Add(IfClause);
            if (ElseClause != null && ElseClause.Count > 0)
            {
                Add(new SimpleLineElement("else", false, true, false));
                Add(ElseClause);
            }
        }
Exemplo n.º 7
0
        public CSClass(CSVisibility vis, CSIdentifier name, IEnumerable <CSMethod> methods = null,
                       bool isStatic = false, bool isSealed = false)
        {
            Visibility         = vis;
            IsStatic           = isStatic;
            IsSealed           = isSealed;
            Name               = Exceptions.ThrowOnNull(name, "name");
            Inheritance        = new CSInheritance();
            Delegates          = new List <CSDelegateTypeDecl> ();
            Fields             = new List <ICodeElement> ();
            Constructors       = new List <CSMethod> ();
            Methods            = new List <CSMethod> ();
            Properties         = new List <CSProperty> ();
            InnerClasses       = new CSClasses();
            InnerEnums         = new List <CSEnum> ();
            StaticConstructor  = new CSCodeBlock();
            GenericParams      = new CSGenericTypeDeclarationCollection();
            GenericConstraints = new CSGenericConstraintCollection();

            if (methods != null)
            {
                Methods.AddRange(methods);
            }
        }
Exemplo n.º 8
0
 public static CSMethod PublicMethod(CSMethodKind kind, CSType type, string name, CSParameterList parms, CSCodeBlock body)
 {
     return(new CSMethod(CSVisibility.Public, kind, type, new CSIdentifier(name), parms, Exceptions.ThrowOnNull(body, "body")));
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public CSCatch(CSType catchType, CSIdentifier name, CSCodeBlock body)
 {
     CatchType = catchType;
     Name      = name;
     Body      = body ?? new CSCodeBlock();
 }
Exemplo n.º 11
0
 public CSProperty(CSType type, CSMethodKind kind, CSIdentifier name,
                   CSVisibility getVis, CSCodeBlock getter,
                   CSVisibility setVis, CSCodeBlock setter)
     : this(type, kind, name, getVis, getter, setVis, setter, null)
 {
 }
Exemplo n.º 12
0
 public CSLambda(CSCodeBlock body, params string [] parameters)
     : this(new CSParameterList(parameters.Select(p => new CSParameter(CSSimpleType.Void, new CSIdentifier(p)))), body)
 {
 }
Exemplo n.º 13
0
 public CSTryCatch(CSCodeBlock tryBlock, Type catchType, string name, CSCodeBlock catchBlock)
     : this(tryBlock, new CSCatch(catchType, name, catchBlock))
 {
 }
Exemplo n.º 14
0
 public static CSMethod PrivateConstructor(string name, CSParameterList parms, CSCodeBlock body, params CSBaseExpression[] baseParams)
 {
     return(new CSMethod(CSVisibility.None, CSMethodKind.None, null, new CSIdentifier(name), parms,
                         baseParams, true, Exceptions.ThrowOnNull(body, "body")));
 }
Exemplo n.º 15
0
 public CSCatch(CSCodeBlock body)
     : this((CSType)null, null, body)
 {
 }
Exemplo n.º 16
0
 public CSForEach(CSType type, string ident, CSBaseExpression expr, CSCodeBlock body)
     : this(type, new CSIdentifier(ident), expr, body)
 {
 }
Exemplo n.º 17
0
 public CSMethod(CSVisibility vis, CSMethodKind kind, CSType type, CSIdentifier name, CSParameterList parms, CSCodeBlock body)
     : this(vis, kind, type, name, parms, null, false, body)
 {
 }
Exemplo n.º 18
0
 public static CSMethod PublicConstructor(string name, CSParameterList parms, CSCodeBlock body)
 {
     return(new CSMethod(CSVisibility.Public, CSMethodKind.None, null, new CSIdentifier(name), parms, Exceptions.ThrowOnNull(body, "body")));
 }
Exemplo n.º 19
0
 public CSCatch(Type catchType, string name, CSCodeBlock body)
     : this(new CSSimpleType(catchType), name != null ? new CSIdentifier(name) : null, body)
 {
 }