コード例 #1
0
            private void GenerateProperties(IEnumerable <Method> settersToUse, bool readOnly)
            {
                foreach (var setter in settersToUse)
                {
                    var type        = (Class)setter.Namespace;
                    var firstWord   = GetFirstWord(setter.Name);
                    var nameBuilder = new StringBuilder(setter.Name.Substring(firstWord.Length));
                    if (char.IsLower(setter.Name[0]))
                    {
                        nameBuilder[0] = char.ToLowerInvariant(nameBuilder[0]);
                    }
                    string afterSet = nameBuilder.ToString();
                    var    s        = setter;
                    foreach (var getter in nonSetters.Where(m => m.Namespace == type &&
                                                            m.ExplicitInterfaceImpl == s.ExplicitInterfaceImpl))
                    {
                        var name = GetReadWritePropertyName(getter, afterSet);
                        if (name == afterSet &&
                            GetUnderlyingType(getter.OriginalReturnType).Equals(
                                GetUnderlyingType(setter.Parameters[0].QualifiedType)))
                        {
                            Method g = getter;
                            foreach (var method in type.Methods.Where(m => m != g && m.Name == name))
                            {
                                var oldName = method.Name;
                                method.Name = string.Format("get{0}{1}",
                                                            char.ToUpperInvariant(method.Name[0]), method.Name.Substring(1));
                                Diagnostics.Debug("Method {0}::{1} renamed to {2}", method.Namespace.Name, oldName, method.Name);
                            }
                            foreach (var @event in type.Events.Where(e => e.Name == name))
                            {
                                var oldName = @event.Name;
                                @event.Name = string.Format("on{0}{1}",
                                                            char.ToUpperInvariant(@event.Name[0]), @event.Name.Substring(1));
                                Diagnostics.Debug("Event {0}::{1} renamed to {2}", @event.Namespace.Name, oldName, @event.Name);
                            }
                            getter.Name = name;
                            GenerateProperty(getter.Namespace, getter, readOnly ? null : setter);
                            goto next;
                        }
                    }
                    Property baseProperty = type.GetBaseProperty(new Property {
                        Name = afterSet
                    }, getTopmost: true);
                    if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual && setter.IsVirtual)
                    {
                        bool isReadOnly = baseProperty.SetMethod == null;
                        GenerateProperty(setter.Namespace, baseProperty.GetMethod,
                                         readOnly || isReadOnly ? null : setter);
                    }
next:
                    ;
                }
                foreach (Method nonSetter in nonSetters)
                {
                    Class    type         = (Class)nonSetter.Namespace;
                    string   name         = GetPropertyName(nonSetter.Name);
                    Property baseProperty = type.GetBaseProperty(new Property {
                        Name = name
                    }, getTopmost: true);
                    if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual)
                    {
                        bool isReadOnly = baseProperty.SetMethod == null;
                        if (readOnly == isReadOnly)
                        {
                            GenerateProperty(nonSetter.Namespace, nonSetter,
                                             readOnly ? null : baseProperty.SetMethod);
                        }
                    }
                }
            }