public void Test‎‎‎ReflectedTypeCreation()
        {
            var way = new ReflectedType(typeof(Way));
            Assert.AreEqual(typeof(Way), way.Reflected);
            Assert.AreEqual(4, way.Attributes.Count);    // my 3 + 1 DebuggerDisplayAttribute

            // Test properties are reflected only once
            var wayProps = way.Properties;
            var wayProps2 = way.Properties;
            Assert.AreSame(wayProps, wayProps2, "Properties don't seem to be cached");

            // Test list all properties
            var onlyMyProps = wayProps.Where(p => p.Reflected.DeclaringType == typeof(Way));
            Assert.AreEqual(1, onlyMyProps.Count());
            Assert.IsTrue(wayProps.Count > 1);

            // Test get property by name
            Assert.IsFalse(way.TryGetProperty("xxx", out var _));
            Assert.IsTrue(way.TryGetProperty("Member", out var memberProp));
            Assert.IsTrue(onlyMyProps.Contains(memberProp));
            Assert.AreEqual("Member", memberProp.Name);

            // Test getter/setter
            var wayInstance = new Way();
            memberProp.Set(wayInstance, "test");
            Assert.AreEqual("test", memberProp.Get(wayInstance));
            Assert.AreEqual("test", wayInstance.Member);
        }
    public ReflectedType ReadType(Type type)
    {
        var readObject = new ReflectedType(type);

        Builders.Add(readObject);
        return(readObject);
    }
Esempio n. 3
0
            public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
            {
                // invokeAttr, binder, and culture are ignored, similar to what runtime reflection does with the default binder.

                if (parameters == null || parameters.Length != 1)
                {
                    throw new TargetParameterCountException();
                }

                object value = parameters[0];

                if (obj == null)
                {
                    throw new TargetException(SR.Target_InstanceMethodRequiresTarget);
                }

                if (!ReflectedType.IsInstanceOfType(obj))
                {
                    throw new TargetException(SR.Target_ObjectTargetMismatch);
                }

                if (ReturnType.IsInstanceOfType(value))
                {
                    throw new ArgumentException(SR.Format(SR.Argument_ObjectArgumentMismatch, value.GetType(), ReturnType));
                }

                _setter(obj, value);

                return(null);
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="ReflectedInformation" /> class.
            /// </summary>
            /// <param name="activity">The activity.</param>
            /// <param name="reflectType">Type of the reflect.</param>
            private ReflectedInformation(Activity activity, ReflectedType reflectType)
            {
                this.parent = activity;

                // reflect over our activity and gather relevant pieces of the system so that the developer
                // doesn't need to worry about "zipping up" his model to the constructs necessary for the
                // runtime to function correctly
                foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(activity))
                {
                    if ((reflectType & ReflectedType.Argument) == ReflectedType.Argument &&
                        ActivityUtilities.TryGetArgumentDirectionAndType(propertyDescriptor.PropertyType, out var direction, out var argumentType))
                    {
                        // We only do our magic for generic argument types.  If the property is a non-generic
                        // argument type then that means the type of the RuntimeArgument should be based on
                        // the type of the argument bound to it.  The activity author is responsible for dealing
                        // with these dynamic typing cases.
                        if (propertyDescriptor.PropertyType.IsGenericType)
                        {
                            var isRequired         = this.GetIsArgumentRequired(propertyDescriptor);
                            var overloadGroupNames = this.GetOverloadGroupNames(propertyDescriptor);
                            var argument           = new RuntimeArgument(
                                propertyDescriptor.Name, argumentType, direction, isRequired, overloadGroupNames, propertyDescriptor, activity);
                            this.Add(ref this.arguments, argument);
                        }
                    }
        public sealed override bool Equals(Object obj)
        {
            NativeFormatRuntimeEventInfo other = obj as NativeFormatRuntimeEventInfo;

            if (other == null)
            {
                return(false);
            }
            if (!(_reader == other._reader))
            {
                return(false);
            }
            if (!(_eventHandle.Equals(other._eventHandle)))
            {
                return(false);
            }
            if (!(ContextTypeInfo.Equals(other.ContextTypeInfo)))
            {
                return(false);
            }
            if (!(ReflectedType.Equals(other.ReflectedType)))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
 public LinkField(Instance _In, PropertyInfo _Field, Link _LinkAttr)
 {
     In        = _In;
     Field     = new ReflectedProperty(_Field, In.Model);
     LinkAttr  = _LinkAttr;
     Comp      = In.ParentComponent();
     ProbeInfo = null;
 }
    public void ExtractPublicNonObjectMethodsFrom(ReflectedType partTranSearchFromDb)
    {
        var methodDescriptions = partTranSearchFromDb.MethodDescriptions
                                 .Where(z => z.IsPublic)
                                 .Where(z => !ConfigRealizer.BaseObjectMethods.Contains(z.Name))
                                 .ToList();

        MethodDescriptions.AddRange(methodDescriptions);
    }
Esempio n. 8
0
        protected override void GetMethods(out DmdMethodInfo addMethod, out DmdMethodInfo removeMethod, out DmdMethodInfo raiseMethod, out DmdMethodInfo[] otherMethods)
        {
            addMethod    = null;
            removeMethod = null;
            raiseMethod  = null;
            List <DmdMethodInfo> otherMethodsList = null;

            var ridList = reader.Metadata.GetMethodSemanticsRidList(Table.Event, Rid);

            for (int i = 0; i < ridList.Count; i++)
            {
                if (!reader.TablesStream.TryReadMethodSemanticsRow(ridList[i], out var row))
                {
                    continue;
                }
                var method = ReflectedType.GetMethod(Module, 0x06000000 + (int)row.Method) as DmdMethodInfo;
                if ((object)method == null)
                {
                    continue;
                }

                switch ((MethodSemanticsAttributes)row.Semantic)
                {
                case MethodSemanticsAttributes.AddOn:
                    if ((object)addMethod == null)
                    {
                        addMethod = method;
                    }
                    break;

                case MethodSemanticsAttributes.RemoveOn:
                    if ((object)removeMethod == null)
                    {
                        removeMethod = method;
                    }
                    break;

                case MethodSemanticsAttributes.Fire:
                    if ((object)raiseMethod == null)
                    {
                        raiseMethod = method;
                    }
                    break;

                case MethodSemanticsAttributes.Other:
                    if (otherMethodsList == null)
                    {
                        otherMethodsList = new List <DmdMethodInfo>();
                    }
                    otherMethodsList.Add(method);
                    break;
                }
            }

            otherMethods = otherMethodsList?.ToArray();
        }
Esempio n. 9
0
 public NameEnv(PythonModule globals, object locals)
 {
     this.globals = globals;
     if (locals == null)
     {
         locals = globals.__dict__;
     }
     this.locals  = locals;
     this.builtin = TypeCache.Builtin;
 }
Esempio n. 10
0
        public void InterfacesTest()
        {
            ReflectionModel reflect = new ReflectionModel(Path.GetFullPath(URL));

            ReflectedType a_interface = (from names in reflect.Namespaces
                                         from inter in names.Interfaces
                                         select inter).First();

            Assert.AreEqual("ISpeaking", a_interface.Name);
            Assert.IsTrue(a_interface.IsAbstract);
            Assert.AreEqual(a_interface.TypeKind.ToString(), "Interface");
        }
Esempio n. 11
0
        private static object InvokeMethod(string methodName, BindingFlags flags, object obj, object[] parameters)
        {
            var methods = ReflectedType.GetMethods(flags);

            foreach (var method in methods)
            {
                if (method.Name.Equals(methodName) && !method.ContainsGenericParameters)
                {
                    return(method.Invoke(obj, parameters));
                }
            }
            return(null);
        }
Esempio n. 12
0
        public override IParser Create(MemberInfo member, IConfig config)
        {
            if (ReflectedType == null)
            {
                throw new Exception("'Indirect' attributes must be applied to a class member");
            }
            var prop = ReflectedType.GetProperty(Property, Instance | Public | NonPublic)
                       ?? throw new ArgumentException($"Could not find `{Property}` on {ReflectedType}");

            return(prop.GetValue(Activator.CreateInstance(ReflectedType, true)) is IEnumerable <Type> options
                       ? new AlternativeParser(member.GetMemberType(), config, ParserFlags, options)
                       : throw new ArgumentNullException($"Found `{Property}` is not IEnumerable<Type>"));
        }
Esempio n. 13
0
        private static object InvokeGenericMethod(string methodName, Type[] types, BindingFlags flags, object obj, object[] parameters)
        {
            var methods = ReflectedType.GetMethods(flags);

            foreach (var method in methods)
            {
                if (method.Name.Equals(methodName) && method.ContainsGenericParameters)
                {
                    var generic = method.MakeGenericMethod(types);
                    return(generic.Invoke(obj, parameters));
                }
            }
            return(null);
        }
Esempio n. 14
0
        /// <summary>
        /// Create an extended field
        /// </summary>
        /// <param name="fieldInfo"></param>
        public ExtendedField(FieldInfo fieldInfo)
        {
            _fieldInfo = fieldInfo;
            var name = fieldInfo.Name;

            if (name.Contains("k__BackingField") || name.StartsWith("<"))
            {
                IsBackingField = true;
                var i   = name.IndexOf("<");
                var end = name.LastIndexOf(">");

                BackedPropertyName = name.Substring(i + 1, end - (i + 1));
                BackedProperty     = ReflectedType.GetExtendedProperty(BackedPropertyName, fieldInfo.DeclaringType);
            }
        }
            public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
            {
                // invokeAttr, binder, and culture are ignored, similar to what runtime reflection does with the default binder.

                if (parameters != null && parameters.Length > 0)
                {
                    throw new TargetParameterCountException();
                }

                if (!ReflectedType.IsInstanceOfType(obj))
                {
                    throw new ArgumentException();
                }

                return(_getter(obj));
            }
Esempio n. 16
0
        protected override void GetMethods(out DmdMethodInfo getMethod, out DmdMethodInfo setMethod, out DmdMethodInfo[] otherMethods)
        {
            getMethod = null;
            setMethod = null;
            List <DmdMethodInfo> otherMethodsList = null;

            var ridList = reader.Metadata.GetMethodSemanticsRidList(Table.Property, Rid);

            for (uint i = 0; i < ridList.Length; i++)
            {
                var row    = reader.TablesStream.ReadMethodSemanticsRow(ridList[i]);
                var method = ReflectedType.GetMethod(Module, 0x06000000 + (int)row.Method) as DmdMethodInfo;
                if ((object)method == null)
                {
                    continue;
                }

                switch ((MethodSemanticsAttributes)row.Semantic)
                {
                case MethodSemanticsAttributes.Setter:
                    if ((object)setMethod == null)
                    {
                        setMethod = method;
                    }
                    break;

                case MethodSemanticsAttributes.Getter:
                    if ((object)getMethod == null)
                    {
                        getMethod = method;
                    }
                    break;

                case MethodSemanticsAttributes.Other:
                    if (otherMethodsList == null)
                    {
                        otherMethodsList = new List <DmdMethodInfo>();
                    }
                    otherMethodsList.Add(method);
                    break;
                }
            }

            otherMethods = otherMethodsList?.ToArray();
        }
Esempio n. 17
0
        /// <summary>
        /// The categories that are used for this type. If the type has no
        /// categories defined, then this will be empty.
        /// </summary>
        public Dictionary <string, List <InspectedMember> > GetCategories(IInspectedMemberFilter filter)
        {
            VerifyNotCollection();

            Dictionary <string, List <InspectedMember> > categories;

            if (_categoryCache.TryGetValue(filter, out categories) == false)
            {
                var defaultCategories = (from oattribute in ReflectedType.Resolve().GetCustomAttributes(typeof(InspectorCategoryAttribute), /*inherit:*/ true)
                                         let attribute = (InspectorCategoryAttribute)oattribute
                                                         select attribute.Category).ToList();

                // Not in the cache - actually compute the result.
                // NOTE: we update the cache before actually doing the
                //       computation - if for whatever reason there is an error,
                //       we will not redo this computation and just return an
                //       empty result.
                categories             = new Dictionary <string, List <InspectedMember> >();
                _categoryCache[filter] = categories;

                foreach (var member in GetMembers(filter))
                {
                    var memberCategories =
                        (from oattribute in member.MemberInfo.GetCustomAttributes(typeof(InspectorCategoryAttribute), /*inherit:*/ true)
                         let attribute = (InspectorCategoryAttribute)oattribute
                                         select attribute.Category).ToList();
                    if (memberCategories.Count == 0)
                    {
                        memberCategories = defaultCategories;
                    }

                    foreach (string category in memberCategories)
                    {
                        if (categories.ContainsKey(category) == false)
                        {
                            categories[category] = new List <InspectedMember>();
                        }
                        categories[category].Add(member);
                    }
                }
            }

            return(categories);
        }
Esempio n. 18
0
        public void ValueTypeTest()
        {
            ReflectionModel reflecion     = new ReflectionModel(Path.GetFullPath(URL));
            ReflectedType   reflectedType = reflecion.Namespaces.Find(x => x.Name == "ExampleDLL").ValueTypes.Find(x => x.Name == "Point");

            Assert.AreEqual("Point", reflectedType.Name);
            Assert.AreEqual("ExampleDLL", reflectedType.Namespace);
            Assert.AreEqual("ValueType", reflectedType.BaseType.Name);
            Assert.AreEqual("x", reflectedType.Fields[0].Name);
            Assert.AreEqual(AccessModifier.Private, reflectedType.Fields[0].Access);
            Assert.AreEqual("Int32", reflectedType.Fields[0].Type.Name);
            Assert.AreEqual("y", reflectedType.Fields[1].Name);
            Assert.AreEqual(AccessModifier.Private, reflectedType.Fields[1].Access);
            Assert.AreEqual("Int32", reflectedType.Fields[1].Type.Name);
            Assert.AreEqual("GetX", reflectedType.Methods.Find(x => x.Name == "GetX").Name);
            Assert.AreEqual("GetY", reflectedType.Methods.Find(x => x.Name == "GetY").Name);
            Assert.AreEqual("Equals", reflectedType.Methods.Find(x => x.Name == "Equals").Name);
            Assert.AreEqual("GetHashCode", reflectedType.Methods.Find(x => x.Name == "GetHashCode").Name);
            Assert.AreEqual("ToString", reflectedType.Methods.Find(x => x.Name == "ToString").Name);
            Assert.AreEqual("GetType", reflectedType.Methods.Find(x => x.Name == "GetType").Name);
            Assert.AreEqual(6, reflectedType.Methods.Count);
        }
Esempio n. 19
0
        public void ClassTest()
        {
            ReflectionModel reflect = new ReflectionModel(Path.GetFullPath(URL));
            ReflectedType   cat     = (from names in reflect.Namespaces
                                       from classes in names.Classes
                                       where classes.Name == "Cat"
                                       select classes).First();

            Assert.AreEqual("Sound", cat.Methods.Find(x => x.Name == "Sound").Name);
            Assert.AreEqual(AccessModifier.Public, cat.Methods.Find(x => x.Name == "Sound").Access);
            Assert.AreEqual("String", cat.Methods.Find(x => x.Name == "Sound").ReturnType.Name);
            Assert.AreEqual("Int32", cat.Methods.Find(x => x.Name == "Sound").Parameters.First().ParamType.Name);
            Assert.AreEqual(AccessModifier.Public, cat.Access);
            Assert.IsFalse(cat.IsAbstract);
            Assert.IsFalse(cat.IsStatic);
            Assert.AreEqual(Kind.Class, cat.TypeKind);
            Assert.AreEqual("ISpeaking", cat.ImplementedInterfaces.First().Name);
            Assert.AreEqual(1, cat.Constructors.Count);
            Assert.AreEqual("ExampleDLL.Animals", cat.Namespace);
            Assert.IsTrue(cat.Properties.Exists(x => x.Name == "Name"));
            Assert.AreEqual("Animal", cat.BaseType.Name);
        }
 private MethodInfo getMethod(string methodName, Type[] methodParameterTypes)
 {
     return(ReflectedType.GetMethod(methodName, this.BindingFlags, null, CallingConventions.Any, methodParameterTypes, null));
 }
Esempio n. 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading PDB...");
            var dia = new DiaSourceClass();

            IDiaSession session;

            dia.loadDataFromPdb(args[0]);
            dia.openSession(out session);

            var globalScope = session.globalScope;

            var names = new HashSet<string>();
            var reflectedTypes = new List<ReflectedType>();

            Console.WriteLine("Loading types...");
            var methodCount = 0;
            var maxCount = -1;
            foreach (var typeSymbol in globalScope
                .EnumerateChildren(SymTagEnum.SymTagUDT)
                .Where(s => Filters.FilterTypeByName(s.name)))
            {
                if (!names.Contains(typeSymbol.name))
                {
                    var rType = new ReflectedType(typeSymbol);
                    reflectedTypes.Add(rType);
                    methodCount += rType.MethodCount;
                    names.Add(typeSymbol.name);
                    maxCount--;
                    if (maxCount == 0) break;
                }
            }

            const string FILE_DELEGATES = "Delegates.cs";
            const string FILE_INTERFACES = "Interfaces.cs";
            const string FILE_IMPLEMENTATIONS = "Implementations.cs";
            const string FILE_DEPENDENCIES = "NativeObject.cs Imports.cs NativePointer.cs";

            Console.WriteLine($"Loaded {reflectedTypes.Count} types with a total of {methodCount} methods.");
            Console.WriteLine("Writing bindings...");

            if (File.Exists(FILE_DELEGATES)) File.Delete(FILE_DELEGATES);
            if (File.Exists(FILE_INTERFACES)) File.Delete(FILE_INTERFACES);
            if (File.Exists(FILE_IMPLEMENTATIONS)) File.Delete(FILE_IMPLEMENTATIONS);

            FileStream delegateStream = null, interfaceStream = null, implStream = null;
            try
            {
                delegateStream = File.OpenWrite(FILE_DELEGATES);
                interfaceStream = File.OpenWrite(FILE_INTERFACES);
                implStream = File.OpenWrite(FILE_IMPLEMENTATIONS);

                using (var bindingsWriter = new BindingsWriter(delegateStream, interfaceStream, implStream))
                {
                    bindingsWriter.WriteHeaders();
                    bindingsWriter.WriteTypeBindings(reflectedTypes);
                    bindingsWriter.WriteFooters();
                }
            }
            finally
            {
                if (delegateStream != null)
                {
                    delegateStream.Close();
                    delegateStream.Dispose();
                    delegateStream = null;
                }
                if (interfaceStream != null)
                {
                    interfaceStream.Close();
                    interfaceStream.Dispose();
                    interfaceStream = null;
                }
                if (implStream != null)
                {
                    implStream.Close();
                    implStream.Dispose();
                    implStream = null;
                }
            }

            Console.WriteLine("Compiling...");
            var pStart = new ProcessStartInfo(COMPILER_PATH,
                $"/target:library /out:{OUTPUT_BINARY} {FILE_DELEGATES} {FILE_INTERFACES} {FILE_IMPLEMENTATIONS} {FILE_DEPENDENCIES}"
            );
            pStart.RedirectStandardOutput = true;
            pStart.RedirectStandardError = true;
            pStart.RedirectStandardInput = true;
            pStart.UseShellExecute = false;
            var compiler = Process.Start(pStart);
            Console.Write(compiler.StandardOutput.ReadToEnd());
            compiler.WaitForExit();
            Console.WriteLine("Done! Press Enter to continue...");
            Console.Read();
        }
 /// <summary>
 /// Gets a method on the reflected type, given the binding flags
 /// </summary>
 public MethodInfo GetMethod(string methodName)
 {
     return(ReflectedType.GetMethod(methodName, this.BindingFlags));
 }
Esempio n. 23
0
 public TypeViewModel(ReflectedType type)
 {
     _type = type;
 }
Esempio n. 24
0
        /// <summary>
        /// Creates a new instance of the type that this metadata points back to.
        /// If this type has a default constructor, then Activator.CreateInstance
        /// will be used to construct the type (or Array.CreateInstance if it an
        /// array). Otherwise, an uninitialized object created via
        /// FormatterServices.GetSafeUninitializedObject is used to construct the
        /// instance.
        /// </summary>
        public object CreateInstance()
        {
            // Unity requires special construction logic for types that derive
            // from ScriptableObject. The normal inspector reflection logic will
            // create ScriptableObject instances if
            // fiSettings.AutomaticReferenceInstantation has been set to true.
            if (typeof(ScriptableObject).IsAssignableFrom(ReflectedType))
            {
                return(ScriptableObject.CreateInstance(ReflectedType));
            }

            // HACK: Constructing components is tricky, as they require a
            //       GameObject context. We fetch a GameObject from the active
            //       selection for the context to add the component to. If that
            //       doesn't work, then we construct an unformatted instance,
            //       which will be reported to the underlying system as null.
            //
            // TODO: Can this support multi-object selection? Very, very dirty.
            if (typeof(Component).IsAssignableFrom(ReflectedType))
            {
                var activeGameObject = fiLateBindings.Selection.activeObject as GameObject;
                if (activeGameObject != null)
                {
                    // Try to fetch an existing instance
                    Component component = activeGameObject.GetComponent(ReflectedType);
                    if (component != null)
                    {
                        return(component);
                    }

                    // Failed -- add a fake "dead" instance that isn't attached
                    // to anything.
#if !(!UNITY_EDITOR && (UNITY_WP8 || UNITY_METRO))
                    return(FormatterServices.GetSafeUninitializedObject(ReflectedType));
#endif
                }

#if !UNITY_EDITOR && (UNITY_WP8 || UNITY_METRO)
                throw new InvalidOperationException("InspectedType.CreateInstance is not supported for " +
                                                    ReflectedType + " on this Unity platform. FormatterServices is required for " +
                                                    "construction. Consider adding a default constructor");
#else
                Debug.LogWarning("No selected game object; constructing an unformatted instance (which will be null) for " + ReflectedType);
                return(FormatterServices.GetSafeUninitializedObject(ReflectedType));
#endif
            }

            if (HasDefaultConstructor == false)
            {
#if !UNITY_EDITOR && (UNITY_WP8 || UNITY_METRO)
                throw new InvalidOperationException("InspectedType.CreateInstance is not supported for " +
                                                    ReflectedType + " on this Unity platform. FormatterServices is required for " +
                                                    "construction. Consider adding a default constructor");
#else
                return(FormatterServices.GetSafeUninitializedObject(ReflectedType));
#endif
            }

            if (_isArray)
            {
                // we have to start with a size zero array otherwise it will have
                // invalid data inside of it
                return(Array.CreateInstance(ReflectedType.GetElementType(), 0));
            }

            try {
                return(Activator.CreateInstance(ReflectedType, /*nonPublic:*/ true));
            }
#if (!UNITY_EDITOR && (UNITY_METRO)) == false
            catch (MissingMethodException e) {
                throw new InvalidOperationException("Unable to create instance of " + ReflectedType + "; there is no default constructor", e);
            }
#endif
            catch (TargetInvocationException e) {
                throw new InvalidOperationException("Constructor of " + ReflectedType + " threw an exception when creating an instance", e);
            }
            catch (MemberAccessException e) {
                throw new InvalidOperationException("Unable to access constructor of " + ReflectedType, e);
            }
        }
    static Reflections()
    {
        AircraftScript = new ReflectedType(gameMainAssembly, "Assets.Scripts.Parts.AircraftScript");
        AircraftScript.RegisterMethod("get_MainCockpit");

        LevelBase = new ReflectedType(gameMainAssembly, "Assets.Scripts.Levels.LevelBase");
        LevelBase.RegisterMethod("get_CurrentLevel");
        LevelBase.RegisterMethod("get_PlayerControlledAircraft");

        CameraManagerScript = new ReflectedType(gameMainAssembly, "Assets.Scripts.Levels.Camera.CameraManagerScript");
        CameraManagerScript.RegisterMethod("get_Instance");
        CameraManagerScript.RegisterMethod("get_MainCamera");
        CameraManagerScript.RegisterField("_currentCameraController", BindingFlags.NonPublic | BindingFlags.Instance);
        CameraManagerScript.RegisterField("_cameras", BindingFlags.NonPublic | BindingFlags.Instance);
        CameraManagerScript.RegisterField("_planeCamera", BindingFlags.NonPublic | BindingFlags.Instance);

        Designer = new ReflectedType(gameMainAssembly, "Assets.Game.Design.Designer");
        Designer.RegisterMethod("get_Instance");
        Designer.RegisterMethod("get_CameraController");
        Designer.RegisterField("_cameras", BindingFlags.NonPublic | BindingFlags.Instance);
        Designer.RegisterField("_planeCamera", BindingFlags.NonPublic | BindingFlags.Instance);

        DesignerCameraController = new ReflectedType(gameMainAssembly, "Assets.Game.Design.CameraController");
        DesignerCameraController.RegisterMethod("get_Camera");

        LevelCameraController = new ReflectedType(gameMainAssembly, "Assets.Scripts.Levels.Camera.CameraController");
        LevelCameraController.RegisterMethod("get_IsActive");
        LevelCameraController.RegisterMethod("set_IsActive");
        LevelCameraController.RegisterMethod("get_IsSelected");
        LevelCameraController.RegisterMethod("set_IsSelected");

        GameWorld = new ReflectedType(gameMainAssembly, "Assets.Game.GameWorld");
        GameWorld.RegisterMethod("get_Instance");
        GameWorld.RegisterMethod("get_FloatingOriginOffset");
        Helper.FloatingOriginOld = Helper.FloatingOriginNew = (Vector3)(GameWorld.InvokeMethod("get_FloatingOriginOffset", GameWorld.InvokeMethod("get_Instance", null, null), null));
        GameWorld.type
        .GetEvent("FloatingOriginChanged")
        .AddEventHandler(
            GameWorld.InvokeMethod("get_Instance", null, null),
            new EventHandler <FloatingOriginChangedEventArgs>(
                (object sender, FloatingOriginChangedEventArgs e) =>
        {
            Helper.FloatingOriginNew = e.NewFloatingOriginOffset;
            Helper.FloatingOriginOld = e.OldFloatingOriginOffset;
            Helper.InvokeOnFloatOriginChange();
        }));



        #region legacy

        /*Type lvlBase = gameAss.GetType("Assets.Scripts.Levels.LevelBase");
         * get_CurrentLevel = lvlBase.GetMethod("get_CurrentLevel");
         * get_PlayerControlledAircraft = lvlBase.GetMethod("get_PlayerControlledAircraft");
         *
         *
         * Type camMgrSpt = gameAss.GetType("Assets.Scripts.Levels.Camera.CameraManagerScript");
         * get_CameraManagerScript_Instance = camMgrSpt.GetMethod("get_Instance");
         * get_CameraManagerScript_MainCamera = camMgrSpt.GetMethod("get_MainCamera");
         * get_CameraManagerScript_cameras = camMgrSpt.GetField("_cameras", BindingFlags.NonPublic | BindingFlags.Instance);
         * get_CameraManagerScript_planeCamera = camMgrSpt.GetField("_planeCamera", BindingFlags.NonPublic | BindingFlags.Instance);
         * Type designer = gameAss.GetType("Assets.Game.Design.Designer");
         * get_Designer_Instance = designer.GetMethod("get_Instance");
         * get_Designer_CameraController = designer.GetMethod("get_CameraController");
         * get_CameraController_Camera = gameAss.GetType("Assets.Game.Design.CameraController").GetMethod("get_Camera");
         * Type gameworld = gameAss.GetType("Assets.Game.GameWorld");
         * get_GameWorld_Instance = gameworld.GetMethod("get_Instance");
         * get_GameWorld_FloatingOriginOffset = gameworld.GetMethod("get_FloatingOriginOffset");
         * Helper.FloatingOriginNew = (Vector3)get_GameWorld_FloatingOriginOffset.Invoke(get_GameWorld_Instance.Invoke(null, null), null);
         * gameworld.GetEvent("FloatingOriginChanged").AddEventHandler(get_GameWorld_Instance.Invoke(null, null), new EventHandler<FloatingOriginChangedEventArgs>(OnFloatingOriginChanged));   */
        #endregion
    }
Esempio n. 26
0
    // --------------------------------------------------------------------
    /// <summary>
    /// Constructor
    /// </summary>
    /// <param name="Property"></param>
    /// <param name="Parent"></param>
    // --------------------------------------------------------------------
    public FactoryProperty(ReflectedType Property, XmlNode Parent)
    {
        IsParam       = false;
        IsInput       = false;
        IsOutput      = false;
        IsWritable    = false;
        HaveSet       = false;
        ReadOnly      = Property.ReadOnly;
        WriteOnly     = Property.WriteOnly;
        TypeName      = Property.Typ.Name;
        Units         = "";
        Description   = "";
        this.Property = Property;
        this.Name     = Property.Name;

        FQN             = CalcParentName(Parent) + this.Name;
        this.OutputName = FQN;

        Data = GetFieldWrapper(Property.Typ);
        if (Data != null)
        {
            sDDML = Data.DDML();
        }
        else
        {
            sDDML = "<type/>";
        }

        regIndex = -1;

        foreach (Object Attr in Property.MetaData)
        {
            Param       P = null;
            Input       I = null;
            Output      O = null;
            Writable    W = null;
            Units       U = null;
            Description D = null;

            if (Attr.GetType() == typeof(Param))
            {
                P = (Param)(Attr);
            }
            else if (Attr.GetType() == typeof(Input))
            {
                I = (Input)(Attr);
            }
            else if (Attr.GetType() == typeof(Output))
            {
                O = (Output)(Attr);
            }
            else if (Attr.GetType() == typeof(Writable))
            {
                W = (Writable)(Attr);
            }
            else if (Attr.GetType() == typeof(Units))
            {
                U = (Units)(Attr);
            }
            else if (Attr.GetType() == typeof(Description))
            {
                D = (Description)(Attr);
            }

            if (P != null)
            {
                IsParam       = true;
                OptionalParam = P.IsOptional;
                ParamMinVal   = P.MinVal;
                ParamMaxVal   = P.MaxVal;
                if (P.Name != "")
                {
                    Name = P.Name;
                    FQN  = CalcParentName(Parent) + this.Name;
                }
            }
            else if (I != null)
            {
                IsInput       = true;
                OptionalInput = I.IsOptional;
            }
            else if (O != null)
            {
                IsOutput = true;
                if (O.Name != "")
                {
                    OutputName = O.Name;
                }
            }
            else if (W != null)
            {
                IsWritable = true;
                ReadOnly   = false;
            }
            else if (U != null)
            {
                Units = U.ToString();
            }
            else if (D != null)
            {
                Description = D.ToString();
            }
        }
        if (Units != "")
        {
            TDDMLValue DDMLValue = new TDDMLValue(sDDML, "");
            DDMLValue.setUnits(Units);
            sDDML = DDMLValue.asDDML();
        }
    }