public void SimpleProtocolProGetSetAssocTestAltSyntax () { var swiftCode = @" public protocol Simplest3 { associatedtype Item var thing: Item { get set } } public func doSetProp<T> (a: inout T, b:T.Item) where T:Simplest3 { a.thing = b } "; var altClass = new CSClass (CSVisibility.Public, "Simple3Impl"); altClass.Inheritance.Add (new CSIdentifier ("ISimplest3<SwiftString>")); var thingProp = CSProperty.PublicGetSet (new CSSimpleType ("SwiftString"), "Thing"); altClass.Properties.Add (thingProp); var ctor = new CSMethod (CSVisibility.Public, CSMethodKind.None, null, altClass.Name, new CSParameterList (), CSCodeBlock.Create ()); altClass.Methods.Add (ctor); var instID = new CSIdentifier ("inst"); var instDecl = CSVariableDeclaration.VarLine (instID, new CSFunctionCall ("Simple3Impl", true)); var doSetProp = CSFunctionCall.FunctionCallLine ("TopLevelEntities.DoSetProp<Simple3Impl, SwiftString>", false, instID, new CSFunctionCall ("SwiftString.FromString", false, CSConstant.Val ("Got here!"))); var printer = CSFunctionCall.ConsoleWriteLine (new CSIdentifier ($"{instID.Name}.Thing")); var callingCode = CSCodeBlock.Create (instDecl, doSetProp, printer); TestRunning.TestAndExecute (swiftCode, callingCode, "Got here!\n", otherClass: altClass, platform: PlatformName.macOS); }
public void PublicGetSetProp() { using (Stream stm = Utils.BasicClass("None", "AClass", null, cl => { cl.Properties.Add(CSProperty.PublicGetSet(CSSimpleType.Int, "Foo")); return(cl); })) { Utils.CompileAStream(stm); } }
void MakeHandler(CSClass cl, string name, string propName) { CSSimpleType evtType = new CSSimpleType(typeof(EventArgs)); CSProperty prop = CSProperty.PublicGetSet(evtType, propName); cl.Properties.Add(prop); CSParameterList pl = new CSParameterList(); pl.Add(new CSParameter(CSSimpleType.Object, "sender")); pl.Add(new CSParameter(evtType, "args")); CSCodeBlock body = new CSCodeBlock(); body.Add(CSAssignment.Assign(propName, CSAssignmentOperator.Assign, new CSIdentifier("args"))); CSMethod meth = new CSMethod(CSVisibility.Public, CSMethodKind.None, CSSimpleType.Void, new CSIdentifier(name), pl, body); cl.Methods.Add(meth); }