public override void OpenIfMarked() { if (Story.CastleChests[ChestArrayIndex][TheEvent.ChestID] == 1) { TheEvent.SetOpenTilesOnMap(Map); } }
public override void OpenIfMarked() { var chests = ChestArray(); if (chests[TheEvent.ChestID] != 0) { TheEvent.SetOpenTilesOnMap(Map); } }
//{ // //Note that if we declared TheEvent without the add/remove methods, the // //following would still generated internally and the underlying member // //(here m_theEvent) can be accessed via Reflection. The automatically // //generated version has a private field with the same name as the event // //(i.e. "TheEvent") // add { m_theEvent += value; } // remove { m_theEvent -= value; } //} //EventHandler m_theEvent; //"TheEvent" if we don't implement add/remove //The following shows how the event can be invoked using the underlying multicast delegate. //We use this knowledge when invoking via reflection (of course, normally we just write //if (TheEvent != null) TheEvent(this, EventArgs.Empty) public void ExampleInvokeTheEvent() { Delegate[] dels = TheEvent.GetInvocationList(); foreach (Delegate del in dels) { MethodInfo method = del.Method; //This does the same as ThisEvent(this, EventArgs.Empty) for a single registered target method.Invoke(this, new object[] { EventArgs.Empty }); } }
static void Main(string[] args) { TheEvent += Program_TheEvent; Console.WriteLine("Enter something:"); var something = Console.ReadLine(); if (something.ToLower().Contains("the")) { TheEvent?.Invoke(null, something); } }
/// <summary> /// Overridden to provide string for email reports. /// </summary> /// <returns>Description of report.</returns> public override String ToString() { StringBuilder result = new StringBuilder(); if (this.Product == null) { result.AppendLine("Full Report"); } else if (this.File == null) { result.AppendLine("Product Report for: "); result.AppendLine(m_Product.ToString()); } else if (this.TheEvent == null) { result.AppendLine("File Report for: "); result.AppendLine(Product.ToString()); result.AppendLine(File.ToString()); } else if (this.Cab == null) { result.AppendLine("Event Report for: "); result.AppendLine(Product.ToString()); result.AppendLine(File.ToString()); result.AppendLine(TheEvent.ToString()); } else if (this.ScriptName == null) { result.AppendLine("Cab Report for: "); result.AppendLine(Product.ToString()); result.AppendLine(File.ToString()); result.AppendLine(TheEvent.ToString()); result.AppendLine(Cab.ToString()); } else { result.AppendLine("Script Report for: "); result.AppendLine(Product.ToString()); result.AppendLine(File.ToString()); result.AppendLine(TheEvent.ToString()); result.AppendLine(Cab.ToString()); result.AppendLine("Script: "); result.AppendLine(ScriptName); } return(result.ToString()); }
public static void Parse(TheEvent pEvent, CodeBuilder pBuilder) { if (pEvent.IsFlashEvent) return; ImportStatementList.AddImport(@"System.EventHandler"); bool isStatic = pEvent.Modifiers.Contains("static"); pBuilder.AppendFormat(@"private {1} var _e{0}:EventHandler; {2}{1} function get {0}():EventHandler {{ if (_e{0} == null) _e{0} = new EventHandler(); return _e{0}; }}", pEvent.Name, isStatic ? "static" : string.Empty, As3Helpers.ConvertModifiers(pEvent.Modifiers, _notValidClassMod) //,isStatic ? pEvent.MyClass.Name : "this" ); pBuilder.AppendLine(); }
public static void Parse(TheEvent pEvent, CodeBuilder pBuilder) { if (pEvent.IsFlashEvent) { return; } ImportStatementList.AddImport(@"System.EventHandler"); bool isStatic = pEvent.Modifiers.Contains("static"); pBuilder.AppendFormat(@"private {1} var _e{0}:EventHandler; {2}{1} function get {0}():EventHandler {{ if (_e{0} == null) _e{0} = new EventHandler(); return _e{0}; }}" , pEvent.Name, isStatic ? "static" : string.Empty, JsHelpers.ConvertModifiers(pEvent.Modifiers, _notValidClassMod) //,isStatic ? pEvent.MyClass.Name : "this" ); pBuilder.AppendLine(); }
public override async Task <bool> Open() { await TextArea.PrintLine(); await TextArea.PrintLine(); if (TheEvent.Closed) { await TextArea.PrintLine("you see yellow guard"); await TextArea.PrintLine("armor in the bottom."); PlayOpenChestSound(); TheEvent.SetOpenTilesOnMap(GameState.Map); await GameControl.WaitAsync(GameState.GameSpeed.CastleOpenChestSoundTime); } else { await TextArea.PrintLine("box open already."); } return(true); }
public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) { CsInvocationExpression ex = (CsInvocationExpression)pStatement; List <string> indexes = new List <string>(); if (ex.argument_list != null) { foreach (CsArgument argument in ex.argument_list.list) { indexes.Add(pCreator.Parse(argument.expression).Value); } } TheClass c = TheClassFactory.Get(pStatement, pCreator); TheMethod m; CsEntityMethod method = ex.entity as CsEntityMethod; CsEntityDelegate entityDelegate = ex.entity as CsEntityDelegate; string name = pCreator.Parse(ex.expression).Value; //call es de tipo super. Necesito saber cuál es la clase heredada) if (name.EndsWith("super.", StringComparison.Ordinal)) { c = c.Base; m = c.GetMethod(method, pCreator); name = name + m.Name; } else if (method != null) { //si es una expresión de tipo xx.yy.method(), tengo que revisar la expresión //porque la invocación se da como expresión completa... c = TheClassFactory.Get(method.parent, pCreator); m = c.GetMethod(method, pCreator); if (m.IsExtensionMethod) { int fnIndex = name.IndexOf(m.Name); if (fnIndex > 0) { fnIndex--; } indexes.Insert(0, name.Substring(0, fnIndex)); if (Helpers.HasAttribute(((CsEntityClass)method.parent).attributes, "As3ExtensionAttribute")) { name = m.MyClass.FullName; name = name.Substring(0, name.LastIndexOf('.')); name = name + "." + m.Name; ImportStatementList.AddImport(name); name = m.Name; } else { name = m.FullName; } } else { name = name.Replace(m.Name, m.Name); } } else if (entityDelegate != null) { //es un evento? if (ex.expression.ec == expression_classification.ec_event_access) { TheEvent theEvent = c.GetEvent(name); name = theEvent.IsFlashEvent ? "dispatchEvent" : string.Format(@"if (_e{0}) _e{0}.fire", name); } } //patch if (name.Contains("{0}")) { string p = indexes[0]; indexes.RemoveAt(0); name = string.Format(name, p, string.Join(", ", indexes.ToArray())); } else { name = name + "(" + string.Join(", ", indexes.ToArray()) + ")"; } return(new Expression( name, ex.entity_typeref )); }
public void RaiseTheEvent(EventArgs eventArgs) { TheEvent?.Invoke(this, eventArgs); }
protected void OnTheEvent([CallerMemberName] string name = "") { TheEvent?.Invoke(this, new TestEventArgs(name)); }
public TheClass(CsClassStruct pCsClass, FactoryExpressionCreator pCreator) { CsNamespace csNamespace; _creator = pCreator; List <string> name = new List <string>(); if (pCsClass.parent is CsClass) { IsPrivate = true; csNamespace = (CsNamespace)pCsClass.parent.parent; } else { csNamespace = (CsNamespace)pCsClass.parent; } CsQualifiedIdentifier list = csNamespace.qualified_identifier; name.AddRange(list.Select(pIdentifier => pIdentifier.identifier.identifier)); if (IsPrivate) { name.Add(((CsClass)pCsClass.parent).identifier.identifier); } NameSpace = string.Join(".", name.ToArray()); //RealName = pCsClass.identifier.identifier; //Name = Helpers.GetRealName(pCsClass, RealName); Name = pCsClass.identifier.identifier; FullName = NameSpace + "." + Name; //FullRealName = NameSpace + "." + RealName; if (pCsClass.type_base != null && pCsClass.type_base.base_list.Count != 0) { foreach (CsTypeRef typeRef in pCsClass.type_base.base_list) { object u = typeRef.entity_typeref.u; if (u == null) { continue; } if (u is CsEntityClass) { Extends.Add(Helpers.GetType(typeRef.type_name)); _baseTyperef = typeRef; } else if (u is CsEntityInterface) { Implements.Add(Helpers.GetType(typeRef.type_name)); } else if (u is CsEntityInstanceSpecifier) { Implements.Add(Helpers.GetType(typeRef.type_name)); //CsEntityInstanceSpecifier specifier = (CsEntityInstanceSpecifier)typeRef.entity_typeref.u; } else { throw new NotSupportedException(); } } } Dictionary <string, int> methodNames = new Dictionary <string, int>(); bool constructorsDone = false; bool methodsDone = false; if (pCsClass.member_declarations != null) { foreach (CsNode memberDeclaration in pCsClass.member_declarations) { CsConstructor c = memberDeclaration as CsConstructor; if (c != null) { TheConstructor tm = new TheConstructor(c, this, pCreator); if (methodNames.ContainsKey(tm.Name)) { methodNames[tm.Name]++; int index = tm._index = methodNames[tm.Name]; if (!constructorsDone) { constructorsDone = true; foreach (KeyValuePair <CsConstructor, TheConstructor> constructor in _constructors) { constructor.Value._isUnique = false; constructor.Value._index = --index; } } tm._isUnique = false; } else { methodNames[tm.Name] = tm._index = 1; } _constructors.Add(c, tm); continue; } CsMethod m = memberDeclaration as CsMethod; if (m != null) { if (m.interface_type != null) { continue; } TheMethod tm = new TheMethod(m, this, pCreator); if (methodNames.ContainsKey(tm.Name)) { methodNames[tm.Name]++; int index = tm._index = methodNames[tm.Name]; if (!methodsDone) { methodsDone = true; foreach (KeyValuePair <CsMethod, TheMethod> method in _methods) { method.Value._isUnique = false; method.Value._index = --index; } } tm._isUnique = false; } else { methodNames[tm.Name] = tm._index = 1; } _methods.Add(m, tm); continue; } CsIndexer i = memberDeclaration as CsIndexer; if (i != null) { _indexers.Add(i, new TheIndexer(i, this, pCreator)); continue; } CsVariableDeclaration v = memberDeclaration as CsVariableDeclaration; if (v != null) { _variables.Add(v, new TheVariable(v, this, pCreator)); continue; } CsConstantDeclaration k = memberDeclaration as CsConstantDeclaration; if (k != null) { _constants.Add(k, new TheConstant(k, this, pCreator)); continue; } CsProperty p = memberDeclaration as CsProperty; if (p != null) { if (p.interface_type == null) { _properties.Add(p, new TheProperty(p, this, pCreator)); } continue; } CsDelegate d = memberDeclaration as CsDelegate; if (d != null) { _delegates.Add(d, new TheDelegate(d, this, pCreator)); continue; } CsEvent e = memberDeclaration as CsEvent; if (e != null) { TheEvent theEvent = new TheEvent(e, this, pCreator); _events.Add(theEvent.Name, theEvent); continue; } CsClass csClass = memberDeclaration as CsClass; if (csClass != null) { continue; } throw new NotImplementedException("Unknown type not implemented"); } } Modifiers.AddRange(Helpers.GetModifiers(pCsClass.modifiers)); }
public int GetCount() { return(TheEvent?.GetInvocationList().Length ?? 0); }
public void Fire(object sender, T data) { TheEvent?.Invoke(sender, new EventArgs <T>(data)); }
public void Raise() { TheEvent?.Invoke(); }
public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) { CsAssignmentExpression ex = (CsAssignmentExpression)pStatement; Expression left = pCreator.Parse(ex.lhs); Expression right = pCreator.Parse(ex.rhs); if (((ex.lhs is CsElementAccess) || (ex.lhs is CsPrimaryExpressionMemberAccess)) && left.InternalType) { switch (ex.oper) { case CsTokenType.tkASSIGN: return(new Expression(string.Format(left.Value, right.Value), pStatement.entity_typeref)); case CsTokenType.tkPLUS_EQ: case CsTokenType.tkMINUS_EQ: case CsTokenType.tkDIV_EQ: case CsTokenType.tkMUL_EQ: string getter = ElementAccessHelper.parseElementAccess(ex.lhs, true, false, pCreator).Value; return(new Expression(string.Format(left.Value, getter + As3Helpers.ConvertTokens(Helpers.GetTokenType(convertToken(ex.oper))) + right.Value), pStatement.entity_typeref)); } } if ((ex.lhs is CsSimpleName) && left.InternalType) { switch (ex.oper) { case CsTokenType.tkASSIGN: return(new Expression(string.Format(left.Value, right.Value), pStatement.entity_typeref)); case CsTokenType.tkPLUS_EQ: case CsTokenType.tkMINUS_EQ: case CsTokenType.tkDIV_EQ: case CsTokenType.tkMUL_EQ: string getter = SimpleNameHelper.ParseSimpleName(ex.lhs, true, false).Value; return(new Expression(string.Format(left.Value, getter + As3Helpers.ConvertTokens(Helpers.GetTokenType(convertToken(ex.oper))) + right.Value), pStatement.entity_typeref)); } } if (ex.lhs is CsPrimaryExpressionMemberAccess) { if (ex.lhs.ec == expression_classification.ec_event_access) { CsEntityEvent ev = (CsEntityEvent)ex.lhs.entity; TheClass theClass = TheClassFactory.Get(ev.parent, pCreator); string eventName; //flash event on flash.xxxx if (theClass == null) { eventName = Helpers.GetEventFromAttr(ev.attributes); return(new Expression( left.Value + (ex.oper == CsTokenType.tkPLUS_EQ ? ("addEventListener(" + eventName + ", " + right.Value + ", false, 0, true)") : ("removeEventListener(" + eventName + ", " + right.Value + ")")) , pStatement.entity_typeref )); } TheEvent theEvent = theClass.GetEvent(ev.name); if (theEvent != null && string.IsNullOrEmpty(theEvent.EventName)) //custom event on the same class { return(new Expression( //event name == left => left IS the event name. Do not add twice left.Value + (ev.name.Equals(left.Value, StringComparison.Ordinal) ? string.Empty : ev.name) + (ex.oper == CsTokenType.tkPLUS_EQ ? ".add" : ".remove") + "(" + right.Value + ")" , pStatement.entity_typeref )); } eventName = theEvent == null?Helpers.GetEventFromAttr(ev.attributes) : theEvent.EventName; //flash event on the same class. return(new Expression( //event name == left => left IS the event name. Do not add twice (ev.name.Equals(left.Value, StringComparison.Ordinal) ? string.Empty : left.Value) + (ex.oper == CsTokenType.tkPLUS_EQ ? ("addEventListener(" + eventName + ", " + right.Value + ", false, 0, true)") : ("removeEventListener(" + eventName + ", " + right.Value + ")")) , pStatement.entity_typeref)); } //else { // left = FactoryExpressionCreator.Parse(ex.lhs); // CsPrimaryExpressionMemberAccess primaryExpressionMemberAccess = (CsPrimaryExpressionMemberAccess)ex.lhs; // TheClass theClass = TheClassFactory.Get((CsEntity)primaryExpressionMemberAccess.entity); // //TheProperty theProp = theClass.GetProperty(); //} } return(new Expression(string.Format("{0} {2} {1}", left.Value, right.Value, As3Helpers.ConvertTokens(Helpers.GetTokenType(ex.oper))), pStatement.entity_typeref)); }