Esempio n. 1
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);
            }
        }