private FormKindSet(string names) { if (string.IsNullOrEmpty(names)) { // Empty set if null or empty kinds = Enumerable.Empty <FormKind>(); } else { if (names.Length % 4 != 0) { throw new ArgumentException("The input length must be a multiple of four."); } if (names.Length == 4) { // Single element array if single kind kinds = new FormKind[] { FormKind.FromName(names) }; } else { // Sorted set if multiple kinds, also sort names to prevent duplicates var split = Enumerable.Range(0, names.Length / 4).Select(i => names.Substring(i * 4, 4)).OrderBy(n => n); kinds = new SortedSet <FormKind>(split.Select(s => FormKind.FromName(s))); } } }
public IFormCollection <TOther> Of <TOther>() where TOther : IForm { FormKind kind = Provider.GetFormKindOfInterface(typeof(TOther)); var items = Items.Where(i => Provider.Engine.Context.Forms[i].FormKind == kind); return(Provider.CreateFormCollectionProxy <TOther>(Mode, items)); }
internal void WriteRecord(GenericFormRecord record, uint formId) { if (header == null) { throw new InvalidOperationException("Header not yet written"); } FormKind formKind = (FormKind)InfoProvider.GetRecordInfo(record.GetType()).Signature; if (formKind != currentGroupFormKind) { // End existing group if one has begun if (currentGroupFormKind != FormKind.Any) { EndSegment(); } currentGroupFormKind = formKind; BeginGroupSegment(currentGroupFormKind); numRecords++; } // Convert global context Form ID to local relative Form ID uint localFormId = ReferenceMapper.ContexToLocal(formId); DoWriteRecord(record, localFormId); numRecords++; }
public Form CreateForm(FormKind kind) { return(new Form() { FormKind = kind, Record = CreateGenericFormRecord(kind) }); }
public virtual GenericFormRecord CreateGenericFormRecord(FormKind kind) { var recordType = GetRecordType(kind); var recinf = InfoProvider.GetRecordInfo(recordType); var record = recinf.CreateInstance(); record.Version = recinf.Version > 0 ? (ushort)recinf.Version : GetLatestFormVersion(); return(record); }
private void BeginGroupSegment(FormKind formKind) { BeginSegment(new GroupMetadata() { Signature = "GRUP", GroupType = GroupType.Top, FormKind = formKind }); }
private ProxyInfo GetFormProxyInfo(FormKind kind) { if (formKindMap.ContainsKey(kind)) { return(proxies[formKindMap[kind]]); } //throw new InvalidProgramException("Proxy not found for form type " + formType); // Form proxy not found - not supported. Return DummyProxy info return(proxies[typeof(DummyFormProxy).FullName]); }
public Type GetInterface(FormKind kind) { if (kind == FormKind.Any) { return(typeof(object)); } else { return(GetFormProxyInfo(kind).InterfaceType); } }
protected override IEnumerable <Form> GetHardcodedForms(byte pluginNumber) { if (pluginNumber > 0) { yield break; } // PlayerRef yield return(new Form() { FormId = 0x14, FormKind = FormKind.FromName(Names.REFR), Record = new DummyRecord() { EditorId = "PlayerRef" } }); }
private Type GetRecordType(FormKind kind) { return(IsSupportedFormKind(kind) ? formKindToRecordTypeMap[kind] : typeof(DummyRecord)); }
// Created by engine internal ProxyProvider(RuleEngine engine) { this.engine = engine; string[] namespaces = new string[] { engine.Context.GameTitle, "Forms", "Fields" }; var types = Assembly.GetExecutingAssembly().GetTypes().Where(t => typeof(Proxy).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericType); foreach (Type type in types) { // Skip proxies outside the allowed namespaces if (!namespaces.Where(n => type.Namespace.EndsWith(n)).Any()) { continue; } // Fetch attribute ProxyAttribute a = (ProxyAttribute)type.GetCustomAttributes(typeof(ProxyAttribute), false).FirstOrDefault(); if (a == null) { throw new InvalidProgramException("Proxy type " + type.FullName + " is missing a ProxyAttribute"); } Type backingRecordType = null; Type searchType = type.BaseType; while (searchType != null) { if (searchType.IsGenericType && searchType.GetGenericTypeDefinition() == typeof(FormProxy <>)) { backingRecordType = type.BaseType.GetGenericArguments().Single(); break; } searchType = searchType.BaseType; } Type backingFieldType = null; searchType = type.BaseType; while (searchType != null) { if (searchType.IsGenericType && searchType.GetGenericTypeDefinition() == typeof(FieldProxy <>)) { backingFieldType = type.BaseType.GetGenericArguments().Single(); break; } searchType = searchType.BaseType; } FormKind backingFormKind = backingRecordType != null?engine.Context.GetRecordFormKind(backingRecordType) : FormKind.Any; Type implementationType = type; proxies.Add(implementationType.FullName, new ProxyInfo() { ImplementationType = implementationType, InterfaceType = a.Interface, BackingFormKind = backingFormKind, BackingRecordType = backingRecordType, BackingFieldType = backingFieldType }); interfaceMap.Add(a.Interface.FullName, implementationType.FullName); if (backingRecordType != null) { formKindMap.Add(backingFormKind, implementationType.FullName); backingRecordMap.Add(backingRecordType.FullName, implementationType.FullName); } else if (backingFieldType != null) { backingFieldMap.Add(backingFieldType.FullName, implementationType.FullName); } } }
/// <summary> /// Creates a new proxy based on the specified FormType without loading a form. /// A form needs to be loaded with method WithForm() before the proxy can be used. /// </summary> /// <param name="kind"></param> /// <param name="mode"></param> /// <returns></returns> public FormProxy CreateFormProxy(FormKind kind, ProxyMode mode) { return(CreateProxy <FormProxy>(GetFormProxyInfo(kind), mode)); }
/// <summary> /// Creates a new proxy based on the specified FormType without loading a form. /// A form needs to be loaded with method WithForm() before the proxy can be used. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="kind"></param> /// <param name="mode"></param> /// <returns></returns> public T CreateFormProxy <T>(FormKind kind, ProxyMode mode) where T : IForm { var proxy = CreateProxy <T>(GetFormProxyInfo(kind), mode); return(proxy); }
private void BeginGroupSegment(FormKind formKind) { BeginSegment(new GroupMetadata() { Signature = "GRUP", GroupType = GroupType.Top, FormKind = formKind }); }
public virtual bool IsSupportedFormKind(FormKind kind) { return(formKindToRecordTypeMap.ContainsKey(kind)); }
public bool Contains(FormKind kind) { return(kinds.Contains(kind)); }
public bool Contains(FormKind kind) { return kinds.Contains(kind); }
public IEnumerable <Form> OfKind(FormKind kind) { return(formsByKind.ContainsKey(kind) ? formsByKind[kind].Select(i => i) : Enumerable.Empty <Form>()); }
internal void WriteRecord(GenericFormRecord record, uint formId) { if (header == null) throw new InvalidOperationException("Header not yet written"); FormKind formKind = (FormKind)InfoProvider.GetRecordInfo(record.GetType()).Signature; if (formKind != currentGroupFormKind) { // End existing group if one has begun if (currentGroupFormKind != FormKind.Any) { EndSegment(); } currentGroupFormKind = formKind; BeginGroupSegment(currentGroupFormKind); numRecords++; } // Convert global context Form ID to local relative Form ID uint localFormId = ReferenceMapper.ContexToLocal(formId); DoWriteRecord(record, localFormId); numRecords++; }