internal static object GetNew(Type type) { Func <object> del; if (Ctors.TryGetValue(type, out del)) { return(del()); } if (type.HasDefaultConstructor()) { Expression @new = Expression.New(type); if (type.IsValueType) //lambda won't box by default, which is required for value types. { @new = Expression.Convert(@new, typeof(object)); } del = (Func <object>)Expression.Lambda(typeof(Func <object>), @new).Compile(); } else { del = () => null; } Ctors[type] = del; return(del()); }
//void EnsureNonNullDiscussion() //{ // if (EditedDiscussion == null) // btnAddDiscussion_Click(null,null); //} private void btnRemove_Click(object sender, RoutedEventArgs e) { if (EditedDiscussion != null && Ctors.DiscussionExists(EditedDiscussion)) { BusyWndSingleton.Show("Deleting discussion..."); try { if (SessionInfo.Get().discussion != null) { if (SessionInfo.Get().discussion.Id == EditedDiscussion.Id) { SessionInfo.Get().discussion = null; } } DaoUtils.DeleteDiscussion(EditedDiscussion); discussionSelector.Set(PublicBoardCtx.Get().Discussion, "Subject"); EditedDiscussion = null; } finally { BusyWndSingleton.Hide(); } } }
private void EnsureNonNullPerson() { Person p = DataContext as Person; if (p == null) { p = Ctors.NewPerson((string)txtBxName.Content, (string)txtBxEmail.Content); } }
private void EnsureNonNullPerson() { Person p = DataContext as Person; if (p == null) { p = Ctors.NewPerson(txtBxName.Text, txtBxEmail.Text); } }
public void SetCtorStrategy(Ctors strategy) { switch (strategy) { case Ctors.Modest: ctorStrategy = Extensions.ModestCtor; break; case Ctors.Greedy: ctorStrategy = Extensions.GreedyCtor; break; } }
public static void EnsureModerExists() { var ctx = PublicBoardCtx.Get(); var q = from p in ctx.Person where p.Name.IndexOf(MODER_SUBNAME) != -1 select p; if (q.Count() == 0) { ctx.AddToPerson(Ctors.NewPerson("moderator", "moder-mail")); ctx.SaveChanges(); } }
public XmlClassGen(XmlElement pkg, XmlElement elem) : base(new XmlGenBaseSupport(pkg, elem)) //FIXME: should not be xml specific { is_abstract = elem.XGetAttribute("abstract") == "true"; is_final = elem.XGetAttribute("final") == "true"; base_type = elem.XGetAttribute("extends"); foreach (XmlNode node in elem.ChildNodes) { XmlElement child = node as XmlElement; if (child == null) { continue; } switch (node.Name) { case "implements": string iname = child.XGetAttribute("name-generic-aware"); iname = iname.Length > 0 ? iname : child.XGetAttribute("name"); AddInterface(iname); break; case "method": var synthetic = child.GetAttribute("synthetic") == "true"; var finalizer = child.GetAttribute("name") == "finalize" && child.GetAttribute("jni-signature") == "()V"; if (!(synthetic || finalizer)) { AddMethod(new XmlMethod(this, child)); } break; case "constructor": Ctors.Add(new XmlCtor(this, child)); break; case "field": AddField(new XmlField(child)); break; case "typeParameters": break; // handled at GenBaseSupport default: Report.Warning(0, Report.WarningClassGen + 1, "unexpected class child {0}.", node.Name); break; } } }
public ManagedClassGen(TypeDefinition t) : base(new ManagedGenBaseSupport(t)) { this.t = t; foreach (var ifaceImpl in t.Interfaces) { var iface = ifaceImpl.InterfaceType; var def = ifaceImpl.InterfaceType.Resolve(); if (def != null && def.IsNotPublic) { continue; } AddInterface(iface.FullNameCorrected()); } bool implements_charsequence = t.Interfaces.Any(it => it.InterfaceType.FullName == "Java.Lang.CharSequence"); foreach (var m in t.Methods) { if (m.IsPrivate || m.IsAssembly || !m.CustomAttributes.Any(ca => ca.AttributeType.FullNameCorrected() == "Android.Runtime.RegisterAttribute")) { continue; } if (implements_charsequence && t.Methods.Any(mm => mm.Name == m.Name + "Formatted")) { continue; } if (m.IsConstructor) { Ctors.Add(new ManagedCtor(this, m)); } else { AddMethod(new ManagedMethod(this, m)); } } foreach (var f in t.Fields) { if (!f.IsPrivate && !f.CustomAttributes.Any(ca => ca.AttributeType.FullNameCorrected() == "Android.Runtime.RegisterAttribute")) { AddField(new ManagedField(f)); } } for (nominal_base_type = t.BaseType; nominal_base_type != null && (nominal_base_type.HasGenericParameters || nominal_base_type.IsGenericInstance); nominal_base_type = nominal_base_type.Resolve().BaseType) { ; // iterate up to non-generic type, at worst System.Object. } }
private void SaveDiscussion() { if (EditedDiscussion == null) { return; } SaveParticipants(); if (!Ctors.DiscussionExists(EditedDiscussion)) { PublicBoardCtx.Get().AddToDiscussion(EditedDiscussion); } background.SaveChanges(); PublicBoardCtx.Get().SaveChanges(); }
public static void SetGeneralSide(Person p, Discussion d, int side) { if (p == null || d == null) { return; } var q = from genSide in PublicBoardCtx.Get().GeneralSide where genSide.Discussion.Id == d.Id && genSide.Person.Id == p.Id select genSide; if (q.Count() > 0) { q.First().Side = side; } else { PublicBoardCtx.Get().AddToGeneralSide(Ctors.NewGenSide(p, d, side)); } }
internal static ContentMatchExpression CreateContentMatchExpression(ContentToken token) { string header = token.Content.Substring(0, token.Content.IndexOf(':') + 1); if (string.IsNullOrWhiteSpace(header)) { return(new TextMatchExpression(token)); } else { Func <ContentToken, ContentMatchExpression> ctor; if (Ctors.TryGetValue(header, out ctor)) { return(ctor(token)); } else { return(new TextMatchExpression(token)); } } }
public static void DeleteDiscussion(Discussion d) { if (!Ctors.DiscussionExists(d)) { return; } var ctx = PublicBoardCtx.Get(); //delete attachments var attachments = new List <Attachment>(); foreach (var a in d.Attachment) { attachments.Add(a); } foreach (var a in attachments) { ctx.DeleteObject(a); } //delete background if (d.Background != null) { d.Background = null; } foreach (var t in d.Topic) { t.Person.Clear(); t.ArgPoint.Clear(); } d.Topic.Clear(); d.GeneralSide.Clear(); ctx.DeleteObject(d); ctx.SaveChanges(); }
public XmlClassGen(XElement pkg, XElement elem) : base(new XmlGenBaseSupport(pkg, elem)) //FIXME: should not be xml specific { is_abstract = elem.XGetAttribute("abstract") == "true"; is_final = elem.XGetAttribute("final") == "true"; base_type = elem.XGetAttribute("extends"); foreach (var child in elem.Elements()) { switch (child.Name.LocalName) { case "implements": string iname = child.XGetAttribute("name-generic-aware"); iname = iname.Length > 0 ? iname : child.XGetAttribute("name"); AddInterface(iname); break; case "method": AddMethod(new XmlMethod(this, child)); break; case "constructor": Ctors.Add(new XmlCtor(this, child)); break; case "field": AddField(new XmlField(child)); break; case "typeParameters": break; // handled at GenBaseSupport default: Report.Warning(0, Report.WarningClassGen + 1, "unexpected class child {0}.", child.Name); break; } } }
public bool ContainsCtor(string jni_sig) => Ctors.Any(c => c.JniSignature == jni_sig);
private void btnAdd_Click(object sender, RoutedEventArgs e) { persons.Add(Ctors.NewPerson("New user", "email")); changesExist = true; }
public void CallCc() { var validateName = Func <string, Func <string, Cont <string, Unit> >, Cont <string, Unit> >((name, exit) => name == "" ? exit("You forgot to tell me your name!") : ContUnit <string>(Ctors.Unit())); var whatsYourName = Func <string, string>(name => Run(Id, from response in CallCC <string, string, Unit>(exit => from _ in validateName(name, exit) select $"Welcome, {name}!") select response)); Assert.AreEqual(whatsYourName("Mr. Callback"), "Welcome, Mr. Callback!"); Assert.AreEqual(whatsYourName(""), "You forgot to tell me your name!"); }