private IEnumerable <Attendance> MergeLists(IEnumerable <Attendance> atndList, IEnumerable <Attendance> stdlist) { if (atndList.Count() == stdlist.Count()) { return(atndList); } IEnumerable <Attendance> newList = null; foreach (var atd in atndList) { newList = newList.Add(atd); } foreach (var std in stdlist) { bool isExisted = false; foreach (var atd in atndList) { if (atd.StudentID == std.StudentID) { isExisted = true; } } if (!isExisted) { std.isNew = true; newList = newList.Add(std); } } return(newList); }
public static void Postfix_SpecialDisplayStats(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result, StatRequest req) { // Tool def if (req.Thing == null && __instance.IsSurvivalTool(out SurvivalToolProperties tProps)) { foreach (StatModifier modifier in tProps.baseWorkStatFactors) { __result = __result.Add(new StatDrawEntry(ST_StatCategoryDefOf.SurvivalTool, modifier.stat.LabelCap, modifier.value.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor), overrideReportText: modifier.stat.description)); } } // Stuff if (__instance.IsStuff && __instance.GetModExtension <StuffPropsTool>() is StuffPropsTool sPropsTool) { foreach (StatModifier modifier in sPropsTool.toolStatFactors) { __result = __result.Add(new StatDrawEntry(ST_StatCategoryDefOf.SurvivalToolMaterial, modifier.stat.LabelCap, modifier.value.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor), overrideReportText: modifier.stat.description)); } } }
public static IEnumerable <T> FindMissingNumbersFromSequence <T>(IEnumerable <T> arr, MinMax <T> mnmx = null) where T : struct { if (!arr.GetItemType().IsNumericType()) { Console.WriteLine("Type '{0}' can't be used as a numeric type!", typeof(T).Name); yield break; } if (mnmx != null) { arr.Add(mnmx.min); arr.Add(mnmx.max); } IOrderedEnumerable <T> list = arr.OrderBy(x => x); T n = default(T); foreach (object num in list) { T op = (T)ExpressionMath <object> .Default.Subtract(num, n); if (ExpressionMath <T> .Default.GreaterThan(op, 1.ConvertGeneric < T > ())) { int max = op.ConvertValue <int>(); for (int l = 1; l < max; ++l) { yield return(ExpressionMath <T> .Default.Add(n, l.ConvertValue <T>())); } } n = (T)num; } }
public static bool FindFirstMissingNumberFromSequenceUlong(this IEnumerable <ulong> arr, out ulong n, MinMax <ulong> mnmx = null) { //Dupe if (mnmx != null) { arr.Add(mnmx.min); arr.Add(mnmx.max); } IOrderedEnumerable <ulong> list = arr.OrderBy(x => x); //End dupe bool b = false; n = 0; foreach (ulong num in list) { b = num - n > 1; if (b) { break; } else { n = num; } } n += 1; return(b); }
public static IEnumerable <T> FindMissingNumbersFromSequence <T>(IEnumerable <T> arr, MinMax <T> mnmx = null) where T : struct { if (!arr.GetItemType().IsNumericType()) { Console.WriteLine("Type '{0}' can't be used as a numeric type!", typeof(T).Name); yield break; } if (mnmx != null) { arr.Add(mnmx.min); arr.Add(mnmx.max); } IOrderedEnumerable <T> list = arr.OrderBy(x => x); T n = default(T); foreach (T num in list) { T op = (dynamic)num - n; if ((dynamic)op > 1) { int max = op.ConvertType <int>(); for (int l = 1; l < max; ++l) { yield return((dynamic)n + l.ConvertType <T>()); } } n = (dynamic)num; } }
/// <summary> /// Adds an event handler. /// </summary> /// <remarks> /// If you add a static method or a lambda expression that does not access container class's instance member, /// it is not automatically removed even if the container class instance is garbage collected. /// </remarks> /// <param name="value">The event handler to add.</param> public void Add(EventHandler value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } #if NICENIS_UWP _weakHandlerInfos = _weakHandlerInfos.Add(value.Target, value.GetMethodInfo()); #else _weakHandlerInfos = _weakHandlerInfos.Add(value.Target, value.Method); #endif }
private static IEnumerable <RichTextNode.Types.TextNode> Join(IEnumerable <RichTextNode.Types.TextNode> list, RichTextNode.Types.TextNode separator) { return(list.Aggregate(new List <RichTextNode.Types.TextNode>(), (list, next) => { if (list.Count > 0) { list.Add(separator); } list.Add(next); return list; }, list => list.AsReadOnly())); }
public IBox <WeakGenericTypeDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack) { // uhhh it is werid that I have to do this lines.Select(x => x.TransformInner(y => y.Run(context, stack.Add(myScope)))).ToArray(); return(new Box <WeakGenericTypeDefinition>(myScope.Converter.Convert(context, myScope, stack).Is2OrThrow())); }
internal void Add_CorrectlyAddsTheDoubleToTheCollection_Test( double value, IEnumerable <Complex> complexs) { var expected = complexs.Select(x => x + value); Assert.Equal(expected, complexs.Add(value)); }
//Thanks to XeoNovaDan public static void DisplayYieldInfo(PlantProperties __instance, ref IEnumerable <StatDrawEntry> __result) { ThingDef harvestedThingDef = Traverse.Create(__instance).Field("harvestedThingDef").GetValue <ThingDef>(); float harvestYield = Traverse.Create(__instance).Field("harvestYield").GetValue <float>(); if (harvestedThingDef == null) { return; } string harvestedThingDefLabel = harvestedThingDef.label; string extendedYieldInfo = string.Format("M4_HarvestYieldThingDetailInit".Translate(), harvestedThingDefLabel) + "\n\n"; float thingMarketValue = harvestedThingDef.GetStatValueAbstract(StatDefOf.MarketValue, null); extendedYieldInfo += StatDefOf.MarketValue.label.CapitalizeFirst() + ": " + thingMarketValue.ToString(); if (harvestedThingDef.IsNutritionGivingIngestible) { float thingNutrition = harvestedThingDef.GetStatValueAbstract(StatDefOf.Nutrition, null); FoodTypeFlags thingNutritionType = harvestedThingDef.ingestible.foodType; IDictionary <FoodTypeFlags, string> nutritionTypeToReportString = new Dictionary <FoodTypeFlags, string>() { { FoodTypeFlags.VegetableOrFruit, "FoodTypeFlags_VegetableOrFruit" }, { FoodTypeFlags.Meat, "FoodTypeFlags_Meat" }, { FoodTypeFlags.Seed, "FoodTypeFlags_Seed" } }; string nutritionTypeReportString = nutritionTypeToReportString.TryGetValue(thingNutritionType, out nutritionTypeReportString) ? nutritionTypeReportString : "StatsReport_OtherStats"; extendedYieldInfo += "\n" + StatDefOf.Nutrition.label.CapitalizeFirst() + ": " + thingNutrition.ToString() + " (" + nutritionTypeReportString.Translate() + ")"; } if (harvestYield > 0) { StatDrawEntry statDrawEntry = new StatDrawEntry(StatCategoryDefOf.Basics, "M4_HarvestYieldThing".Translate(), harvestedThingDef.label.CapitalizeFirst(), 0, extendedYieldInfo); __result = __result.Add(statDrawEntry); } }
public static void GetGizmosPostfix(Pawn_EquipmentTracker __instance, ref IEnumerable <Gizmo> __result) { for (int o = 0; o < __instance.pawn.health.hediffSet.hediffs.Count; o++) { HediffComp_VerbGiverExtra _VerbGiverExtra; if ((_VerbGiverExtra = __instance.pawn.health.hediffSet.hediffs[o].TryGetComp <HediffComp_VerbGiverExtra>()) != null) { foreach (Command command in _VerbGiverExtra.GetVerbsCommands()) { if (o != 0) { if (o != 1) { if (o == 2) { command.hotKey = KeyBindingDefOf.Misc3; } } else { command.hotKey = KeyBindingDefOf.Misc2; } } else { command.hotKey = KeyBindingDefOf.Misc1; } __result.Add(command); } } } }
// Token: 0x06000002 RID: 2 RVA: 0x00002090 File Offset: 0x00000290 private static void MakeButcherProducts_PostFix(Thing __instance, ref IEnumerable <Thing> __result, Pawn butcher, float efficiency) { CompSpecialButcherChance compSpecialButcherChance; if ((compSpecialButcherChance = ThingCompUtility.TryGetComp <CompSpecialButcherChance>(__instance)) != null) { if (GenList.NullOrEmpty <ThingDefCountWithChanceClass>(compSpecialButcherChance.Props.butcherProducts)) { return; } foreach (ThingDefCountWithChanceClass thingDefCountWithChanceClass in compSpecialButcherChance.Props.butcherProducts) { if (Rand.Chance(thingDefCountWithChanceClass.chance)) { ThingDefCountWithChanceClass thingDefCountWithChanceClass2 = new ThingDefCountWithChanceClass { thingDef = thingDefCountWithChanceClass.thingDef, count = thingDefCountWithChanceClass.count }; int num = GenMath.RoundRandom((float)thingDefCountWithChanceClass2.count * efficiency); if (num > 0) { Thing thing = ThingMaker.MakeThing(thingDefCountWithChanceClass2.thingDef, null); thing.stackCount = num; __result = __result.Add(thing); } } } } }
public static void Add(this IEnumerable <string> target, params string[] source) { foreach (var item in source) { target.Add(item); } }
// do these really need to be IBox? they seeme to generally be filled... // mayble IPossibly... public IBox <WeakObjectDefinition> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack) { var finalElements = nextElements.Select(x => x.SwitchReturns <IOrType <IBox <WeakAssignOperation>, IError> >( y => { var res = y.Run(context, stack.Add(myScope)).GetValue(); if (res is WeakAssignOperation weakAssign) { return(OrType.Make <IBox <WeakAssignOperation>, IError>(new Box <WeakAssignOperation>(weakAssign))); } else { return(OrType.Make <IBox <WeakAssignOperation>, IError>(Error.Other("lines in an object must me assignments"))); } }, y => OrType.Make <IBox <WeakAssignOperation>, IError>(y))).ToArray(); box.Fill(finalElements); var objectOr = myScope.Converter.Convert(context, myScope, stack);//; context.GetObject(myScope); if (objectOr.Is1(out var v1)) { return(new Box <WeakObjectDefinition>(v1)); } throw new Exception("wrong or"); }
//private: void PostReqAsync() { Action upload = () => { var msg = new Message(++m_lastMsgID, 0, Message_t.Resume, BitConverter.GetBytes(m_clientID)); IEnumerable <Message> msgs = DialogEngin.ReadConnectionsReq(m_cxnReqFile); DialogEngin.WriteConnectionsReq(m_cxnReqFile, msgs.Add(msg)); var netEngin = new NetEngin(Program.NetworkSettings); try { netEngin.Upload(Urls.ConnectionReqURL, m_cxnReqFile, true); m_timer.Change(TIMER_INTERVALL, TIMER_INTERVALL); } catch (Exception ex) { Dbg.Log(ex.Message); m_callback(Result_t.Error); m_callback = null; } }; new Task(upload, TaskCreationOptions.LongRunning).Start(); }
/// <summary> /// Adds IEnumerable to current IEnumerable /// </summary> /// <typeparam name="T">Type of IEnumerables</typeparam> /// <param name="item">Destination IEnumerable</param> /// <param name="itemsToAdd">Source IEnumerable</param> public static void AddRange <T>(this IEnumerable <T> item, IEnumerable <T> itemsToAdd) { foreach (T itemToAdd in itemsToAdd) { item.Add(itemToAdd); } }
public static void GameLoop_DayStarted(object sender, DayStartedEventArgs e) { if (!Context.IsMainPlayer) { return; } if (!Game1.isRaining && !Game1.IsWinter && Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth).Equals("Sat")) { Farmer farmer = Game1.player; //Game1.getFarm().addSpouseOutdoorArea(Game1.player.spouse == null ? "" : Game1.player.spouse); IEnumerable <string> spouses = farmer.friendshipData.Pairs.Where(f => f.Value.IsMarried()).Select(f => f.Key); NPC ospouse = farmer.getSpouse(); if (ospouse != null) { spouses.Add(ospouse.Name); } foreach (string name in spouses) { NPC npc = Game1.getCharacterFromName(name); if (outdoorAreas.ContainsKey(name) || (farmer.spouse.Equals(npc.Name) && name != "Krobus")) { SMonitor.Log($"placing {name} outdoors"); npc.setUpForOutdoorPatioActivity(); } } } SetupSpouseAreas(); }
// do these really need to be IBox? they seeme to generally be filled... // mayble IPossibly... public IBox <WeakRootScope> Run(Tpn.TypeSolution context, IEnumerable <Tpn.ITypeProblemNode> stack) { assignmentsBox.Fill(nextElements.Select(x => x.TransformInner(y => y.Run(context, stack.Add(myScope)))).ToArray()); entryBox.Fill(nextEntry.TransformInner(x => x.Run(context, stack.Add(myScope)))); ranTypes.Select(x => x.TransformInner(y => y.Run(context, stack.Add(myScope)))).ToArray(); ranGenericTypes.Select(x => x.TransformInner(y => y.Run(context, stack.Add(myScope)))).ToArray(); var objectOr = myScope.Converter.Convert(context, myScope, stack); if (objectOr.Is2(out var v2)) { return(new Box <WeakRootScope>(v2)); } throw new Exception("wrong or"); }
public override void DoWindowContents(Rect inRect) { Listing_Standard listing = new Listing_Standard(); listing.Begin(inRect); listing.Label("Editing Command " + command.label.CapitalizeFirst()); command.command = listing.TextEntryLabeled("Command - !", command.command); listing.CheckboxLabeled("Enabled", ref command.enabled); if (command.isCustomMessage) { listing.CheckboxLabeled("Require Separate Room if Enabled", ref command.shouldBeInSeparateRoom, "Will require viewers to only use this command in secondary channel if enabled"); listing.CheckboxLabeled("Require Mod Status", ref command.requiresMod, "Will require viewers to have mod status to use this command"); listing.CheckboxLabeled("Require Admin Status", ref command.requiresAdmin, "Will only allow channel owner to run this command"); command.outputMessage = listing.TextEntry(command.outputMessage, 5); listing.Gap(); if (listing.ButtonText("View Available Tags")) { Application.OpenURL("https://github.com/hodldeeznuts/twitchtoolkit/wiki/Commands#tags"); } listing.Gap(24); if (!deleteWarning && listing.ButtonTextLabeled("Delete Custom Command", "Delete")) { deleteWarning = true; } if (deleteWarning && listing.ButtonTextLabeled("Delete Custom Command", "Are you sure?")) { if (ToolkitSettings.CustomCommandDefs.Contains(command.defName)) { ToolkitSettings.CustomCommandDefs = ToolkitSettings.CustomCommandDefs.Where(s => s != command.defName).ToList(); IEnumerable <Command> toRemove = Enumerable.Empty <Command>(); toRemove.Add(command); RemoveStuffFromDatabase(command.GetType(), toRemove.Cast <Def>()); } Close(); } if (deleteWarning) { listing.Label("(Must restart for deletions to take effect)"); } } listing.End(); }
public static void PotentialWorkThingsGlobalPatch(WorkGiver_FixBrokenDownBuilding __instance, ref IEnumerable <Thing> __result, ref Pawn pawn) { foreach (Thing t in StaticManager.Breakdowns.BrokenDownThings) { __result.Add <Thing>(t); } }
// Constructor public PC() { Processors = new List <Processor>(); for (var i = 0; i < GetProcessorCount(); i++) { Processors.Add(new Processor(i)); } }
public void Add_SingleValue_ShouldAdd() { IEnumerable <int> enumerable = Enumerable.Range(1, 3); List <int> result = enumerable.Add(4).ToList(); result.Should().BeEquivalentTo(new[] { 1, 2, 3, 4 }); }
public void Add_NewValue_ReturnEnumerableWithOneMoreItem() { IEnumerable <string> enumerable = Enumerable.Empty <string>(); enumerable = enumerable.Add("newvalue"); Assert.True(enumerable.Last() == "newvalue"); }
public Sentence(string text, Semantics semantics) { Words = new List <Word>(); foreach (var t in text.Split(semantics.WordEnding)) { Words = Words.Add(new Word(t)); } }
public Paragraph(string text, Semantics semantics) { Sentences = new List <Sentence>(); foreach (var t in text.Split(new [] { semantics.SentenceEnding }, StringSplitOptions.None)) { Sentences = Sentences.Add(new Sentence(t, semantics)); } }
public void Add_MultipleValues_ShouldAdd() { IEnumerable <int> enumerable = Enumerable.Range(1, 3); List <int> result = enumerable.Add(4, 5, 6).ToList(); result.Should().BeEquivalentTo(new[] { 1, 2, 3, 4, 5, 6 }); }
public void Add_NoValue_ShouldBeStable() { IEnumerable <int> enumerable = Enumerable.Range(1, 3); List <int> result = enumerable.Add().ToList(); result.Should().BeEquivalentTo(new[] { 1, 2, 3 }); }
private void btnViewClassresult_Click(object sender, RoutedEventArgs e) { if (SelectedClassID > 0 && SelectedSectionID > 0 && SelectedExamID > 0) { ClassResultCard = null; SubjectList = ClassSubjectRepo.GetSelectedSubjects(SelectedClassID); int count = 2; for (int i = count; i < 20; i++) { grid.Columns[i].Visibility = System.Windows.Visibility.Collapsed; grid.Columns[i].Header = ""; } foreach (var subject in SubjectList) { grid.Columns[count].Visibility = System.Windows.Visibility.Visible; grid.Columns[count].Header = subject.Description; count++; } IEnumerable <StudentSubjectMarks> results = StudentSubjectMarksRepo.GetClassResult(SelectedExamID, SessionID, SelectedSectionID, SelectedClassID); IEnumerable <Student> studentsList = StudentRepo.GetAll().Where(p => p.ClassID == SelectedClassID && p.SectionID == SelectedSectionID); foreach (var student in studentsList) { IEnumerable <StudentSubjectMarks> subjectResult = results.Where(p => p.StudentID == student.StudentID); ClassResult classResult = new ClassResult(); classResult.StudentName = student.FullName; classResult.RoleNumber = student.StudentID.ToString(); count = 1; foreach (var item in SubjectList) { StudentSubjectMarks rs = subjectResult.Where(p => p.SubjectID == item.SubjectID).FirstOrDefault(); PropertyInfo propertyInfo = classResult.GetType().GetProperty("Subject" + count); if (rs != null) { propertyInfo.SetValue(classResult, Convert.ChangeType(rs.ObtainedMarks, propertyInfo.PropertyType), null); } else { propertyInfo.SetValue(classResult, Convert.ChangeType(0, propertyInfo.PropertyType), null); } count++; } ClassResultCard = ClassResultCard.Add(classResult); } } }
/// <summary> /// Create properties collection which will be need to define model matches /// </summary> /// <typeparam name="TSource">Entity type</typeparam> /// <param name="context">Context instance</param> /// <param name="model">Entity instance</param> /// <param name="properties">Information about finded properties will be sent to each function recursively</param> /// <returns>ExtendedPropertyInfo collection which holds property information and their values</returns> internal static IEnumerable <ExtendedPropertyInfo> GetPropertiesForFiltering <TSource>( this DbContext context, TSource model, IEnumerable <ExtendedPropertyInfo> properties) where TSource : class { if (model == null) { throw new ArgumentNullException("model"); } if (context == null) { throw new ArgumentNullException("context"); } // Get primary key properties of the type alongside with the value var primaryKeyProperties = context.GetPrimaryKeys <TSource>() .MakePropertiesExtended(model); // Get unique properterties of the type alongside with the value var uniqueKeyProperties = ExtendedEntityTypeConfiguration .GetInstance() .UniqueKeys .OfReflectingType <TSource>() .MakePropertiesExtended(model); // If all primary key properties has non-default value if (primaryKeyProperties.Any() && !primaryKeyProperties.Select(prop => prop.PropertyValue).AnyDefault()) { properties = properties.Concat(primaryKeyProperties); } else if (uniqueKeyProperties.Any()) { properties = properties .Concat(uniqueKeyProperties.Where(prop => prop.PropertyInfo.PropertyType.IsBuiltInType())); // Find complex property var complexProperty = uniqueKeyProperties .Where(prop => !prop.PropertyInfo.PropertyType.IsBuiltInType()) .FirstOrDefault(prop => !prop.PropertyValue.IsDefault()); // Recursively get its properties if (complexProperty != null) { properties = properties.Add(complexProperty) .ToList(); properties = DbContextExtensions.GetPropertiesForFiltering( context, complexProperty.PropertyValue as dynamic, properties); } } return(properties); }
/// <summary> /// 添加唯一项 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="list">IList列表</param> /// <param name="item">值</param> /// <returns>IList列表</returns> public static IEnumerable <T> AddUnique <T>(this IEnumerable <T> list, T item) { lock (((ICollection)list).SyncRoot) { if (!list.Contains(item)) { list.Add(item); } } return(list); }
public void ShouldAdd(IEnumerable<double> series, IEnumerable<double> addition, int radius, IEnumerable<int> points, IEnumerable<double> expected) { var additions = new TimeSeriesExtensions.Addition(addition, radius); Assert.AreEqual(expected, series.Add(additions, points)); }
private void BuildCourses() { cmbCourse.Visible = _courseVisible; if (_courseVisible) { // Now load the filter button tables and databind. DataTable dtCourse = new DataTable(); dtCourse.Columns.Add("Course"); dtCourse.Columns.Add("CmbText", typeof(String)); //var courseList = _standardCourseList.GetCourseNames().ToList(); List<string> gradeList = null; List<string> subjectList = null; if (ViewState[_gradeFilterKey].ToString() != "All" && ViewState[_gradeFilterKey].ToString() != "" && ViewState[_gradeFilterKey].ToString() != null) { gradeList = new List<string>(); gradeList.Add(ViewState[_gradeFilterKey].ToString()); } if (ViewState[_subjectFilterKey].ToString() != "All" && ViewState[_subjectFilterKey].ToString() != "" && ViewState[_subjectFilterKey].ToString() != null) { subjectList = new List<string>(); subjectList.Add(ViewState[_subjectFilterKey].ToString()); } var courseList = _level == EntityTypes.Teacher ? CourseMasterList.GetCurrCoursesForUser(SessionObject.LoggedInUser).FilterByGradesAndSubjects(gradeList, subjectList).GetCourseNames().ToList() : CourseMasterList.CurrCourseList.FilterByGradesAndSubjects(gradeList, subjectList).GetCourseNames().ToList(); courseList.Sort(); foreach (var c in courseList) { dtCourse.Rows.Add(c, c); } DataRow newRow = dtCourse.NewRow(); newRow["Course"] = "All"; newRow["CmbText"] = "Course"; dtCourse.Rows.InsertAt(newRow, 0); // Data bind the combo box. cmbCourse.DataTextField = "CmbText"; cmbCourse.DataValueField = "Course"; cmbCourse.DataSource = dtCourse; cmbCourse.DataBind(); // Initialize the current selection. Sometimes the filter item no longer exists when changing // tabs from School, District, Classroom. RadComboBoxItem item = this.cmbCourse.Items.FindItemByValue((String)this.ViewState[_courseFilterKey], true) ?? this.cmbCourse.Items[0]; ViewState[_courseFilterKey] = item.Value; Int32 selIdx = cmbCourse.Items.IndexOf(item); cmbCourse.SelectedIndex = selIdx; SearchResources(); } }
private void btnViewClassresult_Click(object sender, RoutedEventArgs e) { if (SelectedClassID > 0 && SelectedSectionID > 0 && SelectedExamID >0 ) { ClassResultCard = null; SubjectList = ClassSubjectRepo.GetSelectedSubjects(SelectedClassID); int count = 2; for (int i = count; i < 20; i++) { grid.Columns[i].Visibility = System.Windows.Visibility.Collapsed; grid.Columns[i].Header = ""; } foreach (var subject in SubjectList) { grid.Columns[count].Visibility = System.Windows.Visibility.Visible; grid.Columns[count].Header = subject.Description; count++; } IEnumerable<StudentSubjectMarks> results = StudentSubjectMarksRepo.GetClassResult(SelectedExamID, SessionID, SelectedSectionID, SelectedClassID); IEnumerable<Student> studentsList = StudentRepo.GetAll().Where(p => p.ClassID == SelectedClassID && p.SectionID == SelectedSectionID); foreach (var student in studentsList) { IEnumerable<StudentSubjectMarks> subjectResult = results.Where(p => p.StudentID == student.StudentID); ClassResult classResult = new ClassResult(); classResult.StudentName = student.FullName; classResult.RoleNumber = student.StudentID.ToString(); count = 1; foreach (var item in SubjectList) { StudentSubjectMarks rs = subjectResult.Where(p => p.SubjectID == item.SubjectID).FirstOrDefault(); PropertyInfo propertyInfo = classResult.GetType().GetProperty("Subject" + count); if (rs != null) { propertyInfo.SetValue(classResult, Convert.ChangeType(rs.ObtainedMarks, propertyInfo.PropertyType), null); } else { propertyInfo.SetValue(classResult, Convert.ChangeType(0, propertyInfo.PropertyType), null); } count++; } ClassResultCard = ClassResultCard.Add(classResult); } } }