Exemple #1
0
        public void GenerateCode()
        {
            buildArgs = new BuildArgs();

            // load target type
            var classType = BindingEditorUtility.GetClassByName(settings.className).FirstOrDefault();

            if (classType == null)
            {
                Debug.LogErrorFormat("Invalid class name {0}", settings.className);
                return;
            }

            // set target class
            buildArgs.type = classType;

            // get bindable properties
            var outputList = CodeTool.GetBindableProperties();

            if (outputList == null)
            {
                Debug.LogError("Get bindable properties failed.");
                return;
            }

            SetupBuildArgs(outputList);

            WriteCode();
        }
Exemple #2
0
        public void LoadClass()
        {
            if (string.IsNullOrEmpty(typeName))
            {
                Debug.LogError("Type name is null");
                return;
            }

            // reset config
            buildArgs = null;

            var typeList = BindingEditorUtility.GetClassByName(typeName);

            if (typeList.Count == 0)
            {
                Debug.LogErrorFormat("Failed to get type {0}", typeName);
                return;
            }
            else if (typeList.Count > 1)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < typeList.Count; i++)
                {
                    sb.Append(typeList[i].FullName);
                    sb.Append(",\n");
                }

                Debug.LogErrorFormat("{0} types are found for name {1}, type list:\n{2}You need input more specific name.", typeList.Count, typeName, sb.ToString());
                return;
            }

            // get the only one matched
            var type = typeList.First();

            if (type == null)
            {
                Debug.LogErrorFormat("Failed to get type {0}", typeName);
                return;
            }

            // check type
            if (!IsBindableType(type))
            {
                Debug.LogErrorFormat("Class {0} is not sub class of BindableClass", type.Name);
                return;
            }

            // create new config
            buildArgs      = new BuildArgs();
            buildArgs.type = type;

            // get class info
            classInfo = GetClassInfo(type);

            UpdateMemberList();
        }
Exemple #3
0
        private void SetupBuildArgs(List <KeyValuePair <string, string> > nameList)
        {
            // add common types
            var commonTypeList  = GetCommonTypes();
            var propertyTypeSet = new HashSet <Type>(commonTypeList);

            // load type
            foreach (var item in nameList)
            {
                // convert to .net type
                var typeName = item.Key.Replace('/', '+');

                // get type
                var type = BindingEditorUtility.GetClassByName(typeName).FirstOrDefault();
                if (type == null)
                {
                    Debug.LogWarningFormat("Invalid type name {0}", typeName);
                    continue;
                }

                // get property
                var property = type.GetProperty(item.Value);
                if (property == null)
                {
                    Debug.LogWarningFormat("Invalid property name {0}", item.Value);
                    continue;
                }

                var aotType = GetAotType(property.PropertyType);
                if (!propertyTypeSet.Contains(aotType))
                {
                    // add it
                    propertyTypeSet.Add(aotType);
                }
            }

            // combine with custom properties
            Combine(propertyTypeSet, GetCustomProperties());

            // sort type set
            var sortedList = GetSortedTypeList(propertyTypeSet);

            // set property list
            foreach (var item in sortedList)
            {
                var newItem = new BuildArgs.PropertyItem()
                {
                    propertyType = item,
                };

                buildArgs.propertyList.Add(newItem);
            }

            // get implicit operators
            var types = ImplicitConverter.GetTypes();
            var operatorDictionary = BindingUtility.GetImplicitOperators(types);

            // set implicit operator list
            foreach (var item in operatorDictionary)
            {
                var newItem = new BuildArgs.ImplicitOperatorItem()
                {
                    sourceType = item.Key.Item1,
                    targetType = item.Key.Item2,
                };

                buildArgs.implicitOperatorList.Add(newItem);
            }
        }