public void CacheCanFindThisTestClassFromCache() { TypeCache target = new TypeCache(); target.FindType("DDD.Core.Application.Test.AccountOpened"); Type result = target.FindType("DDD.Core.Application.Test.AccountOpened"); Assert.AreEqual(typeof(AccountOpened), result); }
static ProtoBufNetSerializer() { #if PROTOBUF_USE_PRECOMPILER // If we are using a precompiler, then we want to locate the type model class that we // are using for serialization. We do this via reflection and not statically so that we // don't generate compiler errors complaining about a missing type. Type serializer = TypeCache.FindType(ProtoBufNetSettings.PrecompiledSerializerTypeName, ProtoBufNetSettings.PrecompiledSerializerTypeName); if (serializer == null) { Debug.LogError(string.Format("Unable to load precompiled protobuf-net serializer " + "(searched for type {0}); have you compiled it using " + "\"Window/Full Inspector/Compile protobuf-net Serialization DLL\"?", ProtoBufNetSettings.PrecompiledSerializerTypeName)); } else { _serializer = (TypeModel)Activator.CreateInstance(serializer); } #else var serializer = TypeModelCreator.CreateModel(); serializer.Compile(); _serializer = serializer; #endif }
public Type GetPropertyType(SerializedProperty property) { Type holderType = TypeCache.FindType(property.type); while (holderType != null && (holderType.IsGenericType == false || holderType.GetGenericTypeDefinition() != typeof(fiValue <>))) { holderType = holderType.BaseType; } if (holderType == null) { var fieldType = fieldInfo.FieldType; // Unity isn't terribly consistent. The field type can be an array/list even though the // element it sends to us is an element inside of the list. if (fieldType.IsArray) { return(fieldType.GetElementType()); } if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List <>)) { return(fieldType.GetGenericArguments()[0]); } return(fieldInfo.FieldType); } return(holderType.GetGenericArguments()[0]); }
public Project(GameDatabase gameDatabase, ProjectData projectData) { try { m_gameDatabase = gameDatabase; m_projectTemplate = projectData.ValuesDictionary.DatabaseObject; Dictionary <string, Subsystem> dictionary = new Dictionary <string, Subsystem>(); foreach (ValuesDictionary item in from x in projectData.ValuesDictionary.Values select x as ValuesDictionary into x where x != null && x.DatabaseObject != null && x.DatabaseObject.Type == gameDatabase.MemberSubsystemTemplateType select x) { bool value = item.GetValue <bool>("IsOptional"); string value2 = item.GetValue <string>("Class"); Type type = TypeCache.FindType(value2, skipSystemAssemblies: false, !value); if (type != null) { object obj; try { obj = Activator.CreateInstance(type); } catch (TargetInvocationException ex) { throw ex.InnerException; } Subsystem subsystem = obj as Subsystem; if (subsystem == null) { throw new InvalidOperationException($"Type \"{value2}\" cannot be used as a subsystem because it does not inherit from Subsystem class."); } subsystem.Initialize(this, item); dictionary.Add(item.DatabaseObject.Name, subsystem); m_subsystems.Add(subsystem); } } Dictionary <Subsystem, bool> loadedSubsystems = new Dictionary <Subsystem, bool>(); foreach (Subsystem value3 in dictionary.Values) { LoadSubsystem(value3, dictionary, loadedSubsystems, 0); } if (projectData.EntityDataList != null) { List <Entity> entities = LoadEntities(projectData.EntityDataList); AddEntities(entities); } } catch (Exception) { try { Dispose(); } catch (Exception) { } throw; } }
public void CacheCanFind_AccountOpened_InOtherAssembly() { TypeCache target = new TypeCache(); Type result = target.FindType("DDD.Core.Application.Test.AccountOpened"); Assert.AreEqual(typeof(AccountOpened), result); }
public void CacheCanOnlyFindFullNames() { TypeCache target = new TypeCache(); Type result = target.FindType("Int32"); Assert.AreEqual(null, result); }
public void CacheCanFindItsOwnType() { TypeCache target = new TypeCache(); Type result = target.FindType(target.GetType().FullName); Assert.AreEqual(target.GetType(), result); }
public void CacheCanFindString() { TypeCache target = new TypeCache(); Type result = target.FindType("System.String"); Assert.AreEqual(typeof(System.String), result); }
public static Object The(Cons args, Environment environment) { string v = "";// "//(the " + Printer.ConsToString(args) + ")" + NewLine; Type o = TypeCache.FindType(args.First().ToString()); v += Generate(args.Second(), environment); return(v + string.Format("retval = LSharp.Conversions.The(typeof({0}), retval);", o) + NewLine); }
public static Type FindTypeFromXmlName(string name, string namespaceName) { if (!string.IsNullOrEmpty(namespaceName)) { Uri uri = new Uri(namespaceName); if (uri.Scheme == "runtime-namespace") { return(TypeCache.FindType(uri.AbsolutePath + "." + name, skipSystemAssemblies: false, throwIfNotFound: true)); } throw new InvalidOperationException("Unknown uri scheme when loading widget. Scheme must be runtime-namespace."); } throw new InvalidOperationException("Namespace must be specified when creating types in XML."); }
public static ValuesDictionary FindValuesDictionaryForComponent(ValuesDictionary entityVd, Type componentType) { foreach (ValuesDictionary item in entityVd.Values.OfType <ValuesDictionary>()) { if (item.DatabaseObject.Type == GameDatabase.MemberComponentTemplateType) { Type type = TypeCache.FindType(item.GetValue <string>("Class"), skipSystemAssemblies: true, throwIfNotFound: true); if (componentType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) { return(item); } } } return(null); }
public Type GetPropertyType(SerializedProperty property) { Type holderType = TypeCache.FindType(property.type); while (holderType != null && (holderType.IsGenericType == false || holderType.GetGenericTypeDefinition() != typeof(fiValue <>))) { holderType = holderType.BaseType; } if (holderType == null) { return(fieldInfo.FieldType); } return(holderType.GetGenericArguments()[0]); }
private static DatabaseObject publicLoadDatabaseObject(XElement node, Database database, Dictionary <DatabaseObject, Guid> nestingParents, Dictionary <DatabaseObject, Guid> inheritanceParents, Dictionary <Guid, Guid> guidTranslation) { Guid guid = XmlUtils.GetAttributeValue(node, "Guid", Guid.Empty); string attributeValue = XmlUtils.GetAttributeValue(node, "Name", string.Empty); string attributeValue2 = XmlUtils.GetAttributeValue(node, "Description", string.Empty); Guid attributeValue3 = XmlUtils.GetAttributeValue(node, "NestingParent", Guid.Empty); Guid attributeValue4 = XmlUtils.GetAttributeValue(node, "InheritanceParent", Guid.Empty); string attributeValue5 = XmlUtils.GetAttributeValue(node, "Type", string.Empty); if (guid == Guid.Empty) { guid = Guid.NewGuid(); } if (guidTranslation != null) { Guid guid2 = Guid.NewGuid(); guidTranslation.Add(guid, guid2); guid = guid2; } DatabaseObjectType databaseObjectType = database.FindDatabaseObjectType(node.Name.ToString(), throwIfNotFound: true); object value = null; if (!string.IsNullOrEmpty(attributeValue5)) { Type type = TypeCache.FindType(attributeValue5, skipSystemAssemblies: false, throwIfNotFound: true); value = XmlUtils.GetAttributeValue(node, "Value", type); } DatabaseObject databaseObject = new DatabaseObject(databaseObjectType, guid, attributeValue, value); databaseObject.Description = attributeValue2; if (nestingParents != null && attributeValue3 != Guid.Empty) { nestingParents.Add(databaseObject, attributeValue3); } if (inheritanceParents != null && attributeValue4 != Guid.Empty) { inheritanceParents.Add(databaseObject, attributeValue4); } foreach (DatabaseObject item in publicLoadDatabaseObjectsList(node, database, nestingParents, inheritanceParents, guidTranslation)) { item.NestingParent = databaseObject; } return(databaseObject); }
public Entity(Project project, ValuesDictionary valuesDictionary) { if (valuesDictionary.DatabaseObject.Type != project.GameDatabase.EntityTemplateType) { throw new InvalidOperationException("ValuesDictionary was not created from EntityTemplate."); } m_project = project; m_valuesDictionary = valuesDictionary; List <KeyValuePair <int, Component> > list = new List <KeyValuePair <int, Component> >(); foreach (ValuesDictionary item in from x in valuesDictionary.Values select x as ValuesDictionary into x where x != null && x.DatabaseObject != null && x.DatabaseObject.Type == project.GameDatabase.MemberComponentTemplateType select x) { bool value = item.GetValue <bool>("IsOptional"); string value2 = item.GetValue <string>("Class"); int value3 = item.GetValue <int>("LoadOrder"); Type type = TypeCache.FindType(value2, skipSystemAssemblies: false, !value); if (type != null) { object obj; try { obj = Activator.CreateInstance(type); } catch (TargetInvocationException ex) { throw ex.InnerException; } Component component = obj as Component; if (component == null) { throw new InvalidOperationException($"Type \"{value2}\" cannot be used as a component because it does not inherit from Component class."); } component.Initialize(this, item); list.Add(new KeyValuePair <int, Component>(value3, component)); } } list.Sort((KeyValuePair <int, Component> x, KeyValuePair <int, Component> y) => x.Key - y.Key); m_components = new List <Component>(list.Select((KeyValuePair <int, Component> x) => x.Value)); }
public void ApplyOverrides(XElement overridesNode) { foreach (XElement item in overridesNode.Elements()) { if (item.Name == "Value") { string attributeValue = XmlUtils.GetAttributeValue <string>(item, "Name"); string attributeValue2 = XmlUtils.GetAttributeValue <string>(item, "Type", null); Type type; if (attributeValue2 == null) { object value = GetValue <object>(attributeValue, null); if (value == null) { throw new InvalidOperationException($"Type of override \"{attributeValue}\" cannot be determined."); } type = value.GetType(); } else { type = TypeCache.FindType(attributeValue2, skipSystemAssemblies: false, throwIfNotFound: true); } object attributeValue3 = XmlUtils.GetAttributeValue(item, "Value", type); SetValue(attributeValue, attributeValue3); } else { if (!(item.Name == "Values")) { throw new InvalidOperationException($"Unrecognized element \"{item.Name}\" in values dictionary overrides XML."); } string attributeValue4 = XmlUtils.GetAttributeValue <string>(item, "Name"); ValuesDictionary valuesDictionary = GetValue <object>(attributeValue4, null) as ValuesDictionary; if (valuesDictionary == null) { valuesDictionary = new ValuesDictionary(); SetValue(attributeValue4, valuesDictionary); } valuesDictionary.ApplyOverrides(item); } } }
static fiVersionManager() { foreach (var oldVersion in OldVersionMarkers) { Type oldType = TypeCache.FindType(oldVersion); if (oldType != null) { if (EditorUtility.DisplayDialog("Clean Import Needed", "Full Inspector has detected that you recently upgraded versions but did not do a " + "clean import. This will lead to subtle errors." + Environment.NewLine + Environment.NewLine + "Please delete the \"" + fiSettings.RootDirectory + "\" folder and reimport Full Inspector.", "Delete folder?", "I'll do it later")) { Debug.Log("Deleting \"" + fiSettings.RootDirectory + "\""); Directory.Delete(fiSettings.RootDirectory, /*recursive:*/ true); string metapath = fiSettings.RootDirectory.TrimEnd('/') + ".meta"; Debug.Log("Deleting \"" + metapath + "\""); File.Delete(metapath); } } } }
public static Object Call(Cons args, Environment environment) { string v = //"//(call " + Printer.ConsToString(args) + ")" + NewLine + "{" + NewLine; ArrayList argtypes = new ArrayList(); ArrayList argz = new ArrayList(); if (args.Length() > 2) { foreach (object arg in (args.Cddr() as Cons)) { if (Primitives.IsAtom(arg)) { argz.Add(Printer.WriteToString(arg)); } else { string argn = MakeUnique("arg"); string sv = Generate(arg, environment); sv += string.Format(@"{0} {1} = ({0}) retval; ", typeof(object), argn); argz.Add(argn); v += sv; } argtypes.Add(typeof(object)); } } string typemethname = args.Car().ToString(); string methname = typemethname; string typename = string.Empty; Type type = typeof(object); int i = methname.LastIndexOf("."); if (i >= 0) { methname = methname.Substring(i + 1); typename = typemethname.Substring(0, i); type = TypeCache.FindType(typename); } MethodInfo mi = null; mi = type.GetMethod(methname, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance, binder, argtypes.ToArray(typeof(Type)) as Type[], null); string objn = string.Empty; if (mi == null) { type = TypeCache.FindType(args.Second().ToString()); mi = type.GetMethod(methname, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Static, binder, argtypes.ToArray(typeof(Type)) as Type[], null); if (mi == null) { // use reflection v += Generate(args.Second(), environment); v += string.Format(@"retval = retval.GetType().InvokeMember(""{0}"", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance, null, retval, new object[]{{", methname) + string.Join(", ", argz.ToArray(typeof(string)) as string[]) + @"}); } "; return(v); } else { objn = type.ToString(); } } else { objn = MakeUnique("obj"); v += Generate(args.Second(), environment); v += string.Format(@"{0} {1} = ({0}) retval; ", type, objn); } v += "retval = " + (mi.ReturnType == typeof(void) ? @"null; " : "") + objn + "." + mi.Name + "(" + string.Join(", ", argz.ToArray(typeof(string)) as string[]); return(v + @"); } "); }
public void OnGUI() { EditorGUILayout.LabelField("Manually Locate Type", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); _customTypeName = EditorGUILayout.TextField("Qualified Type Name", _customTypeName, GUILayout.ExpandWidth(true)); Type foundType = TypeCache.FindType(_customTypeName); GUILayout.BeginVertical(GUILayout.Width(100)); EditorGUI.BeginDisabledGroup(foundType == null); if (foundType != null) { GUI.color = Color.green; } if (GUILayout.Button("Select type \u2713")) { SelectedType = fiOption.Just(foundType); Close(); } GUI.color = Color.white; EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); fiEditorGUILayout.Splitter(2); EditorGUILayout.LabelField("Search for Type", EditorStyles.boldLabel); // For the custom search bar, see: // http://answers.unity3d.com/questions/464708/custom-editor-search-bar.html GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar")); GUILayout.Label("Filter", GUILayout.ExpandWidth(false)); _searchString = GUILayout.TextField(_searchString, GUI.skin.FindStyle("ToolbarSeachTextField")); if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton"))) { // Remove focus if cleared _searchString = ""; GUI.FocusControl(null); } GUILayout.EndHorizontal(); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition); string lastNamespace = string.Empty; if (PassesSearchFilter(null)) { GUILayout.BeginHorizontal(); GUILayout.Space(35); if (GUILayout.Button("null")) { SelectedType = fiOption.Just <Type>(null); Close(); } GUILayout.EndHorizontal(); } foreach (Type type in _allTypesWithStatics) { if (PassesSearchFilter(type)) { if (lastNamespace != type.Namespace) { lastNamespace = type.Namespace; GUILayout.Label(type.Namespace ?? "<no namespace>", EditorStyles.boldLabel); } GUILayout.BeginHorizontal(); GUILayout.Space(35); if (InitialType == type) { GUI.color = Color.green; } EditorGUI.BeginDisabledGroup(type.IsGenericTypeDefinition); string buttonLabel = type.CSharpName(); if (type.IsGenericTypeDefinition) { buttonLabel += " (generic type definition)"; } if (GUILayout.Button(buttonLabel)) { SelectedType = fiOption.Just(type); Close(); } GUI.color = Color.white; EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } } GUILayout.EndScrollView(); }
public override Type BindToType(string assemblyName, string typeName) { return(TypeCache.FindType(typeName, assemblyName)); }