public void CopyAtoB(WorldMapStrategyKit.Country source, WPM.Country target, string excludedProperties, BindingFlags memberAccess) { string[] excluded = null; if (!string.IsNullOrEmpty(excludedProperties)) { excluded = excludedProperties.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); } MemberInfo[] miT = target.GetType().GetMembers(memberAccess); foreach (MemberInfo Field in miT) { string name = Field.Name; // Skip over any property exceptions if (!string.IsNullOrEmpty(excludedProperties) && excluded.Contains(name)) { continue; } if (Field.MemberType == MemberTypes.Field) { FieldInfo SourceField = source.GetType().GetField(name); if (SourceField == null) { continue; } object SourceValue = SourceField.GetValue(source); ((FieldInfo)Field).SetValue(target, SourceValue); } else if (Field.MemberType == MemberTypes.Property) { PropertyInfo piTarget = Field as PropertyInfo; PropertyInfo SourceField = source.GetType().GetProperty(name, memberAccess); if (SourceField == null) { continue; } if (piTarget.CanWrite && SourceField.CanRead) { object SourceValue = SourceField.GetValue(source, null); piTarget.SetValue(target, SourceValue, null); } } } }
public WorldMapStrategyKit.Country GenericToMapCountry(WPM.Country country) { return(_WMSK.GetCountry(_WMSK.GetCountryIndex(country.name))); }
public WorldMapStrategyKit.Country ToCountry(WPM.Country country) { CopyAtoB(country, Country, string.Empty, new BindingFlags()); return(Country); }
/// <summary> /// Deletes current region or province if this was the last region. /// </summary> public void ProvinceDeleteAndDependencies(int provinceIndex) { if (provinceIndex < 0 || provinceIndex >= provinces.Length) { return; } // Clears references from mount points if (mountPoints != null) { for (int k = 0; k < mountPoints.Count; k++) { if (mountPoints[k].provinceIndex == provinceIndex) { mountPoints[k].provinceIndex = -1; } } } List <Province> newProvinces = new List <Province>(_provinces.Length); // Clears references from cities int countryIndex = _provinces[provinceIndex].countryIndex; if (countryIndex >= 0 && countryIndex < _countries.Length) { string provinceName = _provinces[provinceIndex].name; if (cities != null) { for (int k = 0; k < _cities.Count; k++) { if (_cities[k].countryIndex == countryIndex && _cities[k].name.Equals(provinceName)) { _cities[k].name = ""; } } } // Remove it from the country array Country country = _countries[countryIndex]; if (country.provinces != null) { for (int k = 0; k < country.provinces.Length; k++) { if (!country.provinces[k].name.Equals(provinceName)) { newProvinces.Add(country.provinces[k]); } } newProvinces.Sort(ProvinceSizeComparer); country.provinces = newProvinces.ToArray(); } } // Remove from the global array newProvinces.Clear(); for (int k = 0; k < _provinces.Length; k++) { if (k != provinceIndex) { newProvinces.Add(_provinces[k]); } } provinces = newProvinces.ToArray(); }