public CSDelegateTypeDecl(CSVisibility vis, CSType type, CSIdentifier name, CSParameterList parms)
 {
     Visibility = vis;
     Type       = type != null ? type : CSSimpleType.Void;
     Name       = Exceptions.ThrowOnNull(name, "name");
     Parameters = parms;
 }
Пример #2
0
 public CSEnum(CSVisibility vis, CSIdentifier name, CSType optionalType)
 {
     Values       = new List <CSBinding> ();
     Name         = Exceptions.ThrowOnNull(name, "name");
     OptionalType = optionalType;
     Visibility   = vis;
 }
Пример #3
0
 public ForElement(CSType type, CSIdentifier ident, CSBaseExpression expr)
     : base()
 {
     Type  = type;
     Ident = ident;
     Expr  = expr;
 }
Пример #4
0
 public CSFixedCodeBlock(CSType type, CSIdentifier ident, CSBaseExpression expr, IEnumerable <ICodeElement> body)
     : base(body)
 {
     Type       = Exceptions.ThrowOnNull(type, "type");
     Identifier = Exceptions.ThrowOnNull(ident, "ident");
     Expr       = Exceptions.ThrowOnNull(expr, "expr");
 }
Пример #5
0
        static CSProperty PublicGetPubPrivSetBacking(CSType type, string name, bool declareField, bool setIsPublic, string backingFieldName = null)
        {
            if (!declareField && backingFieldName == null)
            {
                throw new ArgumentException("declareField must be true if there is no supplied field name", nameof(declareField));
            }
            backingFieldName = backingFieldName ?? MassageName(Exceptions.ThrowOnNull(name, nameof(name)));


            CSIdentifier backingIdent = new CSIdentifier(backingFieldName);
            LineCodeElementCollection <ICodeElement> getCode =
                new LineCodeElementCollection <ICodeElement> (new ICodeElement [] { CSReturn.ReturnLine(backingIdent) }, false, true);
            LineCodeElementCollection <ICodeElement> setCode =
                new LineCodeElementCollection <ICodeElement> (
                    new ICodeElement [] {
                CSAssignment.Assign(backingFieldName, new CSIdentifier("value"))
            }, false, true);
            CSProperty prop = new CSProperty(type, CSMethodKind.None, new CSIdentifier(name), CSVisibility.Public,
                                             new CSCodeBlock(getCode),
                                             (setIsPublic ? CSVisibility.Public : CSVisibility.Private), new CSCodeBlock(setCode));

            if (declareField)
            {
                prop.Insert(0, CSFieldDeclaration.FieldLine(type, backingFieldName));
            }
            return(prop);
        }
Пример #6
0
 public CSProperty(CSType type, CSMethodKind kind, CSIdentifier name,
                   CSVisibility getVis, IEnumerable <ICodeElement> getter,
                   CSVisibility setVis, IEnumerable <ICodeElement> setter)
     : this(type, kind, name,
            getVis, getter != null ? new CSCodeBlock(getter) : null,
            setVis, setter != null ? new CSCodeBlock(setter) : null)
 {
 }
Пример #7
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);
 }
Пример #8
0
 public CSParameter(CSType type, CSIdentifier name,
                    CSParameterKind parameterKind = CSParameterKind.None,
                    CSConstant defaultValue       = null)
 {
     CSType        = Exceptions.ThrowOnNull(type, nameof(type));
     Name          = Exceptions.ThrowOnNull(name, nameof(name));
     ParameterKind = parameterKind;
     DefaultValue  = defaultValue;
 }
 public CSGenericConstraint(CSIdentifier name, IEnumerable <CSIdentifier> multiIs)
 {
     Name = Exceptions.ThrowOnNull(name, nameof(name));
     IsA  = new CommaListElementCollection <CSIdentifier> ();
     if (multiIs != null)
     {
         IsA.AddRange(multiIs);
     }
 }
Пример #10
0
 CSConditionalCompilation(CSIdentifier tag, CSIdentifier condition)
     : base(true, false, false)
 {
     Add(tag);
     if ((object)condition != null)
     {
         Add(SimpleElememt.Spacer);
         Add(condition);
     }
 }
Пример #11
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);
            }
        }
Пример #12
0
 public CSAttribute(CSIdentifier name, CSArgumentList args, bool isSingleLine = false)
     : base(isSingleLine, false, isSingleLine)
 {
     Add(new SimpleElememt("["));
     Add(Exceptions.ThrowOnNull(name, nameof(name)));
     if (args != null)
     {
         Add(new SimpleElememt("("));
         Add(args);
         Add(new SimpleElememt(")"));
     }
     Add(new SimpleElememt("]"));
 }
Пример #13
0
 public CSInterface(CSVisibility vis, CSIdentifier name,
                    IEnumerable <CSMethod> methods = null)
 {
     Visibility         = vis;
     Name               = Exceptions.ThrowOnNull(name, "name");
     Inheritance        = new CSInheritance();
     Methods            = new List <CSMethod> ();
     Properties         = new List <CSProperty> ();
     GenericParams      = new CSGenericTypeDeclarationCollection();
     GenericConstraints = new CSGenericConstraintCollection();
     if (methods != null)
     {
         Methods.AddRange(methods);
     }
 }
Пример #14
0
        public static CSProperty PublicGetBacking(CSType type, CSIdentifier name, CSIdentifier backingFieldName,
                                                  bool includeBackingFieldDeclaration = false, CSMethodKind methodKind = CSMethodKind.None)
        {
            LineCodeElementCollection <ICodeElement> getCode =
                new LineCodeElementCollection <ICodeElement> (
                    new ICodeElement [] {
                CSReturn.ReturnLine(Exceptions.ThrowOnNull(backingFieldName, nameof(backingFieldName)))
            }, false, true);
            CSProperty prop = new CSProperty(type, methodKind, Exceptions.ThrowOnNull(name, nameof(name)),
                                             CSVisibility.Public, new CSCodeBlock(getCode),
                                             CSVisibility.Public, null);

            if (includeBackingFieldDeclaration)
            {
                prop.Insert(0, CSFieldDeclaration.FieldLine(type, backingFieldName));
            }
            return(prop);
        }
Пример #15
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);
            }
        }
Пример #16
0
 public static CSLine VarLine(CSIdentifier name, ICSExpression value)
 {
     return(new CSLine(new CSVariableDeclaration(CSSimpleType.Var, name, value)));
 }
Пример #17
0
 public static CSLine VarLine(CSType type, CSIdentifier name, ICSExpression value = null)
 {
     return(new CSLine(new CSVariableDeclaration(type, name, value)));
 }
Пример #18
0
 public CSVariableDeclaration(CSType type, CSIdentifier name, ICSExpression value = null)
     : this(type, new CSBinding [] { new CSBinding(name, value) })
 {
 }
Пример #19
0
 public CSArray1D(CSIdentifier name, CommaListElementCollection <CSBaseExpression> paramList)
 {
     Name       = Exceptions.ThrowOnNull(name, "name");
     Parameters = Exceptions.ThrowOnNull(paramList, "paramList");
 }
		public static CSLine FunctionCallLine (CSIdentifier identifier, bool isConstructor, params CSBaseExpression [] parameters)
		{
			return new CSLine (new CSFunctionCall (identifier,
				new CommaListElementCollection<CSBaseExpression> (parameters), isConstructor));
		}
Пример #21
0
 public CSGenericTypeDeclaration(CSIdentifier name)
 {
     Name = Exceptions.ThrowOnNull(name, nameof(name));
 }
		public CSFunctionCall (CSIdentifier ident, CommaListElementCollection<CSBaseExpression> paramList, bool isConstructor = false)
		{
			Name = Exceptions.ThrowOnNull (ident, "ident");
			Parameters = Exceptions.ThrowOnNull (paramList, "paramList");
			IsConstructor = isConstructor;
		}
Пример #23
0
 public CSStruct(CSVisibility vis, CSIdentifier name, IEnumerable <CSMethod> methods = null,
                 bool isStatic = false, bool isSealed = false)
     : base(vis, name, methods, isStatic, isSealed)
 {
 }
Пример #24
0
 public CSMethod(CSVisibility vis, CSMethodKind kind, CSType type, CSIdentifier name, CSParameterList parms, CSCodeBlock body)
     : this(vis, kind, type, name, parms, null, false, body)
 {
 }
Пример #25
0
 public static CSConditionalCompilation If(CSIdentifier condition)
 {
     return(new CSConditionalCompilation(new CSIdentifier("#if"), Exceptions.ThrowOnNull(condition, nameof(condition))));
 }
Пример #26
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);
        }
Пример #27
0
 public CSBinding(CSIdentifier name, ICSExpression val = null, bool onOwnLine = false)
 {
     Name      = name;
     Value     = val;
     OnOwnLine = onOwnLine;
 }
Пример #28
0
 public CSFieldDeclaration(CSType type, CSIdentifier name, ICSExpression value = null, CSVisibility vis = CSVisibility.None, bool isStatic = false, bool isReadOnly = false)
     : this(type, new CSBinding [] { new CSBinding(name, value) }, vis, isStatic, isReadOnly)
 {
 }
Пример #29
0
 public static CSLine FieldLine(CSType type, CSIdentifier name, ICSExpression value = null, CSVisibility vis = CSVisibility.None, bool isStatic = false)
 {
     return(new CSLine(new CSFieldDeclaration(type, name, value, vis, isStatic)));
 }
Пример #30
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)
 {
 }