public static string GetJoiner <E, D>() { Type firstType = typeof(E); string secondName; Type secondType = typeof(D); secondName = secondType.Name; BasicList <PropertyInfo> thisList = firstType.GetPublicPropertiesWithAttribute <ForeignKeyAttribute>().ToBasicList(); BasicList <PropertyInfo> newList = thisList.Where(items => { ForeignKeyAttribute thisKey = items.GetCustomAttribute <ForeignKeyAttribute>() !; if (thisKey.ClassName == secondName) { return(true); } return(false); }).ToBasicList(); if (newList.Count == 0) { throw new CustomBasicException($"No Key Found Linking {secondName}"); } if (newList.Count > 1) { throw new CustomBasicException($"Duplicate Key Found Linking {secondName}"); } PropertyInfo thisProp = newList.Single(); ColumnAttribute thisCol = thisProp.GetCustomAttribute <ColumnAttribute>() !; if (thisCol == null) { return(thisProp.Name); } return(thisCol.ColumnName); }
public override object Read(object value, ProtoReader source) { int fieldNumber = source.FieldNumber; BasicList list = new BasicList(); if ((this.packedWireType != WireType.None) && (source.WireType == WireType.String)) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(this.packedWireType, source)) { list.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(fieldNumber)); } int offset = this.AppendToCollection ? ((value == null) ? 0 : ((Array)value).Length) : 0; Array array = Array.CreateInstance(this.itemType, (int)(offset + list.Count)); if (offset != 0) { ((Array)value).CopyTo(array, 0); } list.CopyTo(array, offset); return(array); }
//eventually can do source generators but not yet. public static BasicList <T> DeserializeDelimitedTextList <T>(this string content, string delimiter = ",") { BasicList <T> output; Type key = typeof(T); if (key.IsSimpleType()) { var temps = content.Split(delimiter).ToBasicList(); output = temps.ToCastedList <T>(); return(output); } output = new(); BasicList <string> lines = content.Split(Constants.VBCrLf).ToBasicList(); var properties = GetProperties <T>(); foreach (var line in lines) { var items = line.Split(delimiter).ToBasicList(); if (items.Count != properties.Count) { throw new CustomBasicException("Text file corrupted because the delimiter count don't match the properties"); } int x = 0; object temp = Activator.CreateInstance(typeof(T)) !; T row = (T)temp; properties.ForEach(p => { string item = items[x]; PopulateValue(item, row, p); x++; }); output.Add(row); } return(output); }
public static string SerializeText <T>(this BasicList <T> payLoad, string delimiter = ",") { var properties = GetProperties <T>(); BasicList <string> list = new(); foreach (var item in payLoad) { StrCat cats = new(); properties.ForEach(p => { var value = p.GetValue(item); if (value != null) { cats.AddToString(value.ToString() !, delimiter); } else { cats.AddToString("", delimiter); } }); list.Add(cats.GetInfo()); } StrCat fins = new(); list.ForEach(x => fins.AddToString(x, Constants.VBCrLf)); return(fins.GetInfo()); }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList basicList = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { basicList.Add(base.Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { basicList.Add(base.Tail.Read(null, source)); }while (source.TryReadFieldHeader(field)); } int num = AppendToCollection ? ((value != null) ? ((Array)value).Length : 0) : 0; Array array = Array.CreateInstance(itemType, num + basicList.Count); if (num != 0) { ((Array)value).CopyTo(array, 0); } basicList.CopyTo(array, num); return(array); }
void ReadSInstance(ProtoReader reader, SInstance sInstance, CLS_Environment environment) { List <CLS_Content.Value> values; List <string> keywords; GetSortMembers(sInstance, out values, out keywords); int fieldNumber = 0; while ((fieldNumber = reader.ReadFieldHeader()) > 0) { Type memberT = values[fieldNumber - 1].type; CLS_Content.Value memberV = values[fieldNumber - 1]; string sClassName = keywords[fieldNumber - 1]; if (memberT == null) { memberT = typeof(SInstance); sClassName = ((SType)memberV.type).Name; } Type itemType = GetItemType(memberT); if (itemType != null) { sClassName = sInstance.type.members[sClassName].type.keyword; // 数组判断 if (memberT.IsArray) { string itemClass = sClassName.Substring(0, sClassName.Length - 2); // 从 xxx[] 中提取xxx BasicList list = new BasicList(); do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); Array result = Array.CreateInstance(itemType, list.Count); list.CopyTo(result, 0); memberV.value = result; } // 列表判断 else { string itemClass = sClassName.Substring(5, sClassName.Length - 6); // 从 List<xxx> 中提取xxx ICLS_Type iType = environment.GetTypeByKeywordQuiet(sClassName); CLS_Content content = CLS_Content.NewContent(environment); memberV.value = iType.function.New(content, m_emptyParams).value; CLS_Content.PoolContent(content); IList list = (IList)memberV.value; do { list.Add(ReadField(reader, itemType, itemClass, environment)); } while (reader.TryReadFieldHeader(fieldNumber)); } } else { memberV.value = ReadField(reader, memberT, sClassName, environment); } } }
public override object Read(object value, ProtoReader source) { int field = source.FieldNumber; BasicList list = new BasicList(); if (packedWireType != WireType.None && source.WireType == WireType.String) { SubItemToken token = ProtoReader.StartSubItem(source); while (ProtoReader.HasSubValue(packedWireType, source)) { list.Add(Tail.Read(null, source)); } ProtoReader.EndSubItem(token, source); } else { do { list.Add(Tail.Read(null, source)); } while (source.TryReadFieldHeader(field)); } int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0; Array result = Array.CreateInstance(itemType, oldLen + list.Count); if (oldLen != 0) { ((Array)value).CopyTo(result, 0); } list.CopyTo(result, oldLen); return(result); }
internal object GetKeyedObject(int key) { int num = key; key = num - 1; if (num == 0) { if (this.rootObject == null) { throw new ProtoException("No root object assigned"); } return(this.rootObject); } BasicList list = this.List; if (key < 0 || key >= list.Count) { throw new ProtoException("Internal error; a missing key occurred"); } object item = list[key]; if (item == null) { throw new ProtoException("A deferred key does not have a value yet"); } return(item); }
public BasicList <string> GetList(string strFirst, bool showErrors = true) { string tempStr; tempStr = Body; if (tempStr == "") { throw new CustomBasicException("Blank list"); } var tGetList = new BasicList <string>(); do { if (DoesExist(strFirst) == false) { if (tGetList.Count == 0) { if (showErrors == true) { throw new ParserException("There are no items on the list", EnumMethod.GetList) { OriginalBody = tempStr, RemainingHtml = Body, FirstTag = strFirst } } } ; tGetList.Add(Body); Body = tempStr; return(tGetList); } tGetList.Add(GetTopInfo(strFirst)); Body = GetBottomInfo(strFirst, true); }while (true); }
internal void SetKeyedObject(int key, object value) { if (key-- == Root) { if (value == null) { throw new ArgumentNullException("value"); } if (rootObject != null && ((object)rootObject != (object)value)) { throw new ProtoException("The root object cannot be reassigned"); } rootObject = value; } else { BasicList list = List; if (key < list.Count) { if (!ReferenceEquals(list[key], value)) { throw new ProtoException("Reference-tracked objects cannot change reference"); } } else if (key != list.Add(value)) { throw new ProtoException("Internal error; a key mismatch occurred"); } } }
internal object GetKeyedObject(int key) { if (key-- == Root) { if (rootObject == null) { throw new ProtoException("No root object assigned"); } return(rootObject); } BasicList list = List; if (key < 0 || key >= list.Count) { Helpers.DebugWriteLine("Missing key: " + key); throw new ProtoException("Internal error; a missing key occurred"); } object tmp = list[key]; if (tmp == null) { throw new ProtoException("A deferred key does not have a value yet"); } return(tmp); }
public BasicList <string> GetList(string strFirst, string strSecond, bool showErrors = true) { string tempStr; tempStr = Body; if (tempStr == "") { throw new CustomBasicException("Blank list"); } var tGetList = new BasicList <string>(); string thisItem; do { if (DoesExist(strFirst, strSecond) == false) { if (tGetList.Count == 0) { if (showErrors == true) { throw new ParserException("There are no items on the list", EnumMethod.GetList) { OriginalBody = tempStr, RemainingHtml = Body, FirstTag = strFirst, SecondTag = strSecond } } } ; Body = tempStr; return(tGetList); } thisItem = GetSomeInfo(strFirst, strSecond, true); tGetList.Add(thisItem); }while (true); }
internal object GetKeyedObject(int key) { if (key-- == 0) { if (this.rootObject == null) { throw new ProtoException("No root object assigned"); } return(this.rootObject); } else { BasicList list = this.List; if (key < 0 || key >= list.Count) { throw new ProtoException("Internal error; a missing key occurred"); } object obj = list[key]; if (obj == null) { throw new ProtoException("A deferred key does not have a value yet"); } return(obj); } }
public static BasicList <ICondition> JoinedCondition(this BasicList <ICondition> tempList, string tableCode) { AndCondition thisCon = (AndCondition)tempList.Last(); thisCon.Code = tableCode; return(tempList); }
async Task <string> ISimpleConfig.GetStringAsync(string key) { string path = await _locator.GetConfigLocationAsync(); //this is intended to get from local disk; if (ff.FileExists(path) == false) { throw new CustomBasicException($"Path at {path} does not exist."); } if (path.ToLower().EndsWith("txt") == false) { throw new CustomBasicException(@"Only text files are supported. Rethink"); } BasicList <string> firstList = await ff.ReadAllLinesAsync(path); Dictionary <string, string> output = new(); firstList.ForEach(row => { BasicList <string> nextList = row.Split(Constants.VBTab).ToBasicList(); if (nextList.Count != 2) { throw new CustomBasicException($"Needs 2 items for value pair. Value or row was {row}"); } bool rets = output.TryAdd(nextList.First(), nextList.Last()); if (rets == false) { throw new CustomBasicException($"{key} was duplicated"); } }); return(output[key]); }
public ITestPerson GetTestSinglePerson <T>(EnumAgeRanges defaultAge = EnumAgeRanges.Adult) where T : ITestPerson, new() { ITestPerson output = new T(); if (UseFullName) { FullNameClass full = NextFullName(); output.FirstName = full.FirstName; output.LastName = full.LastName; } else { output.FirstName = NextAnyName(); output.LastName = NextLastName(); } BasicList <CityStateClass> cities = _data.Cities; CityStateClass chosen = cities.GetRandomItem(); output.City = chosen.City; output.State = chosen.StateAbb; #if NET6_0_OR_GREATER output.LastDate = NextDateOnly(); #endif output.PostalCode = NextZipCode(); output.Address = NextAddress(); output.IsActive = NextBool(70); //wants to lean towards active output.CreditCardNumber = NextCreditCardNumber(); output.Age = NextAge(defaultAge); output.SSN = NextSSN(); output.EmailAddress = NextEmail(); return(output); }
public static BasicList <ICondition> AppendContains(this BasicList <ICondition> tempList, BasicList <int> containList) { SpecificListCondition thisCon = new(); thisCon.ItemList = containList; tempList.Add(thisCon); return(tempList); }
public static BasicList <SortInfo> Append(this BasicList <SortInfo> sortList, string property, EnumOrderBy orderBy) { sortList.Add(new SortInfo() { Property = property, OrderBy = orderBy }); return(sortList); }
public static BasicList <UpdateFieldInfo> Append(this BasicList <UpdateFieldInfo> tempList, BasicList <string> propList) { propList.ForEach(items => { tempList.Add(new UpdateFieldInfo(items)); }); return(tempList); }
public static BasicList <ICondition> AppendsNot(this BasicList <ICondition> tempList, BasicList <int> notList) { NotListCondition thiscon = new(); thiscon.ItemList = notList; tempList.Add(thiscon); return(tempList); }
public static string DefaultReplacements(string original) => original; //so if somebody does not specify otherwise, will be default. public static async Task CopyInitialFilesAsync(FileInfo currentFile, string templateName) { BasicList <string> fileList = await ff.FileListAsync(currentFile.OldPath); await fileList.ForEachAsync(async oldFile => { await CopyFileAsync(oldFile, templateName, currentFile); }); }
public static BasicList <string> GetHttpsLinks(string fileSource) { HtmlParser parses = new(); parses.Body = AllText(fileSource); BasicList <string> temps = parses.GetList("https", Constants.DoubleQuote, showErrors: false); BasicList <string> output = temps.Select(x => "https" + x).ToBasicList(); return(output); }
public static BasicList <ICondition> AppendCondition(this BasicList <ICondition> tempList, string property, string toperator, object value) { AndCondition thisCon = new(); thisCon.Property = property; thisCon.Operator = toperator; thisCon.Value = value; tempList.Add(thisCon); return(tempList); }
internal int AddObjectKey(object value, out bool existing) { int num; if (value == null) { throw new ArgumentNullException("value"); } if (value == this.rootObject) { existing = true; return(0); } string str = value as string; BasicList list = this.List; if (str == null) { if (this.objectKeys == null) { this.objectKeys = new Dictionary <object, int>(NetObjectCache.ReferenceComparer.Default); num = -1; } else if (!this.objectKeys.TryGetValue(value, out num)) { num = -1; } } else if (this.stringKeys == null) { this.stringKeys = new Dictionary <string, int>(); num = -1; } else if (!this.stringKeys.TryGetValue(str, out num)) { num = -1; } bool flag = num >= 0; bool flag1 = flag; existing = flag; if (!flag1) { num = list.Add(value); if (str != null) { this.stringKeys.Add(str, num); } else { this.objectKeys.Add(value, num); } } return(num + 1); }
private bool InternalsVisible(Assembly assembly) { if (Helpers.IsNullOrEmpty(this.assemblyName)) { return(false); } if (this.knownTrustedAssemblies != null && this.knownTrustedAssemblies.IndexOfReference(assembly) >= 0) { return(true); } if (this.knownUntrustedAssemblies != null && this.knownUntrustedAssemblies.IndexOfReference(assembly) >= 0) { return(false); } bool flag = false; Type type = this.MapType(typeof(InternalsVisibleToAttribute)); if (type == null) { return(false); } object[] customAttributes = assembly.GetCustomAttributes(type, false); int num = 0; while (num < (int)customAttributes.Length) { InternalsVisibleToAttribute internalsVisibleToAttribute = (InternalsVisibleToAttribute)customAttributes[num]; if (internalsVisibleToAttribute.AssemblyName == this.assemblyName || internalsVisibleToAttribute.AssemblyName.StartsWith(string.Concat(this.assemblyName, ","))) { flag = true; break; } else { num++; } } if (!flag) { if (this.knownUntrustedAssemblies == null) { this.knownUntrustedAssemblies = new BasicList(); } this.knownUntrustedAssemblies.Add(assembly); } else { if (this.knownTrustedAssemblies == null) { this.knownTrustedAssemblies = new BasicList(); } this.knownTrustedAssemblies.Add(assembly); } return(flag); }
private static BasicList <PropertyInfo> GetProperties <T>() { Type type = typeof(T); BasicList <PropertyInfo> output = type.GetProperties().ToBasicList(); if (output.Exists(x => x.IsSimpleType()) == false) { throw new CustomBasicException("There are some properties that are not simple. This only handles simple types for now"); } return(output); }
public static void DisplayListWindow <TemplateClass>(BasicListViewModel <TemplateClass> vm) where TemplateClass : class, new() { Window window = new Window(); var tmp = new BasicList(); tmp.DataContext = vm; window.Content = tmp; window.ShowDialog(); }
public static string ProgressString <T>(this BasicList <T> thisList, T thisItem, string miscText) { int index = thisList.IndexOf(thisItem); if (index == -1) { throw new CustomBasicException("Item Not Found"); } index += 1; return($"{ miscText} # {index} of {thisList.Count} on {DateTime.Now}"); }
public static int RoundToLowerNumber(this double thisDou) { string thisStr = thisDou.ToString(); if (thisStr.Contains(".") == false) { return(int.Parse(thisDou.ToString())); } BasicList <string> thisList = thisStr.Split(".").ToBasicList(); return(int.Parse(thisList.First())); }
public static int RoundToHigherNumber(this double thisDou) { string str = thisDou.ToString(); if (str.Contains(".") == false) { return(int.Parse(thisDou.ToString())); } BasicList <string> list = str.Split(".").ToBasicList(); int value = int.Parse(list.First()); return(value + 1); }