Example #1
0
        /// <summary>
        /// Check if parent type if abstract and get abstract methods that would have not been implemented if it is the case
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private HashSet <string> GetAbstractMethodsThatWouldntBeImlemented(TypeDefinition type)
        {
            HashSet <string> res = new HashSet <string>();

            if (type.BaseType != null)
            {
                AddUsing(type.BaseType.Namespace);
                TypeDefinition baseType = AnalysisUtils.GetTypeDefinitionFromTypeReference(type.BaseType, _modules);
                if (baseType != null)
                {
                    if (baseType.IsAbstract)
                    {
                        if (baseType.HasMethods)
                        {
                            foreach (MethodDefinition method in baseType.Methods)
                            {
                                if (AnalysisUtils.IsMethodAbstract(method))
                                {
                                    if (MethodAnalyzer.IsMethodUnsupported(method) ||
                                        analyzeHelpher._coreSupportedMethods.Contains(baseType.Namespace, baseType.Name, method.Name) ||
                                        analyzeHelpher.IsMethodSupported(method))
                                    {
                                        res.Add(method.Name);
                                    }
                                }
                            }
                        }
                        res.UnionWith(GetAbstractMethodsThatWouldntBeImlemented(baseType));
                    }
                }
            }
            return(res);
        }
Example #2
0
        /// <summary>
        /// Analyze the current method and return a method generated from this one.
        /// </summary>
        /// <returns></returns>
        public void Run()
        {
            if (!_isInitialized)
            {
                throw new Exception("MethodAnalyzer must be initialized. Please call Init() first.");
            }

            if (CanWorkOnElement())
            {
                _isMethodOrPropertyOrEvent = IsMethodOrPropertyOrEvent(Element);
                CheckParametersAndReturnValueType();
                string dependencyPropertyNameIfAny;
                switch (_isMethodOrPropertyOrEvent)
                {
                case MethodType.PROPERTY:
                    PropertyDefinition property = FindProperty(Element, Element.DeclaringType);
                    if (AddDependencyPropertyIfDefined(property, out dependencyPropertyNameIfAny))
                    {
                        _parentClassAnalyzer.AddProperty(new Builder.PropertyInfo(property, true, dependencyPropertyNameIfAny));
                    }
                    else
                    {
                        if (!AnalysisUtils.IsMethodAbstract(property) && _outputOptions.OutputPropertyOptions == OutputPropertyOptions.OUTPUT_PRIVATE_FIELD)
                        {
                            string fieldName = property.Name.Contains(".") ? property.Name.Substring(property.Name.LastIndexOf('.') + 1) : property.Name;
                            fieldName = "_" + fieldName.Substring(0, 1).ToLower() + fieldName.Substring(1);
                            string newFieldName;
                            _parentClassAnalyzer.AddField(fieldName, property.PropertyType, false, false, AnalysisUtils.IsMethodStatic(property), null, null, out newFieldName);
                            _parentClassAnalyzer.AddProperty(new Builder.PropertyInfo(property, false, newFieldName));
                        }
                        else
                        {
                            _parentClassAnalyzer.AddProperty(new Builder.PropertyInfo(property));
                        }
                    }
                    break;

                case MethodType.METHOD:
                    if (AddDependencyPropertyIfDefined(Element, out dependencyPropertyNameIfAny))
                    {
                        _parentClassAnalyzer.AddMethod(new Builder.MethodInfo(Element, Element.Name.StartsWith("Get"), Element.Name.StartsWith("Set"), dependencyPropertyNameIfAny));
                    }
                    else
                    {
                        _parentClassAnalyzer.AddMethod(new Builder.MethodInfo(Element));
                    }
                    break;

                case MethodType.EVENT:
                    EventDefinition @event = FindEvent(Element, Element.DeclaringType);
                    _parentClassAnalyzer.AddEvent(@event);
                    break;
                }
                AddMethodToImplementedMethodsSet(Element);
            }
        }