Ejemplo n.º 1
0
        public static bool IsNameClash(NetTypeDefinition typeDef, NetPropertyDefinition prop)
        {
            if ((prop.Getter ?? prop.Setter).InterfaceType != null)
                return false;

            var name = prop.Name;
            return prop.Name == typeDef.Name
                             || typeDef.NestedTypes.Any(x => x.Name == name)
                             || typeDef.Methods.Any(x => (x != prop.Getter && x != prop.Setter) && (x.Name == name));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Do prop1 and prop2 have the same name and signature?
 /// </summary>
 internal static bool AreSame(this NetPropertyDefinition prop1, NetPropertyDefinition prop2)
 {
     if (prop1.Name != prop2.Name)
         return false;
     if (!prop1.PropertyType.AreSame(prop2.PropertyType))
         return false;
     var count = prop1.Parameters.Count;
     if (count != prop2.Parameters.Count)
         return false;
     for (var i = 0; i < count; i++ )
     {
         if (!prop1.Parameters[i].ParameterType.AreSame(prop2.Parameters[i].ParameterType))
             return false;
     }
     return true;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Build properties for the given type
        /// </summary>
        internal void BuildProperties(TargetFramework target, MethodRenamer methodRenamer)
        {
            var getters = typeDef.Methods.Where(IsGetter).ToList();
            var setters = typeDef.Methods.Where(IsSetter).ToList();

            foreach (var getMethod in getters)
            {
                // Get the name of the property
                var name = GetPropertyName(getMethod);

                // other clashes must be handled later.
                if(getMethod.InterfaceType == null)
                    typeDef.Fields.Where(x => x.Name == name).ForEach(RenameClashingField);

                // Create property
                var prop = new NetPropertyDefinition
                {
                    Name = name,
                    Getter = getMethod,
                    Description = getMethod.Description,
                };

                AddCustomAttributes(getMethod, prop.CustomAttributes);

                // Clone parameters
                if (getMethod.Parameters.Any())
                {
                    prop.Parameters.AddRange(getMethod.Parameters.Select(x => new NetParameterDefinition(x.Name, x.ParameterType, false)));
                    prop.Name = "this";
                }

                getMethod.Property = prop;

                // Find setter
                var setMethod = FindSetter(getMethod, setters);
                if (setMethod != null)
                {
                    prop.Setter = setMethod;
                    setMethod.Property = prop;

                    setters.Remove(setMethod);
                }

                // Add property
                typeDef.Properties.Add(prop);
            }

            // create properties for lone setters that override a base setter
            foreach (var setMethod in setters.Where(s => s.IsOverride))
            {
                var name = GetPropertyName(setMethod);

                // other clashes must be handled in FixOverrides
                if (setMethod.InterfaceType == null)
                    typeDef.Fields.Where(x => x.Name == name).ForEach(RenameClashingField);

                // Create property
                var prop = new NetPropertyDefinition { Name = name, Setter = setMethod, Description = setMethod.Description };
                setMethod.Property = prop;

                AddCustomAttributes(setMethod, prop.CustomAttributes);

                // Clone parameters
                if (setMethod.Parameters.Skip(1).Any())
                {
                    prop.Parameters.AddRange(setMethod.Parameters.Skip(1).Select(x => new NetParameterDefinition(x.Name, x.ParameterType, false)));
                    prop.Name = "this";
                }

                typeDef.Properties.Add(prop);
            }
        }
Ejemplo n.º 4
0
 private void RemoveProperty(NetPropertyDefinition prop)
 {
     if (prop.Getter != null) prop.Getter.Property = null;
     if (prop.Setter != null) prop.Setter.Property = null;
     typeDef.Properties.Remove(prop);
 }
Ejemplo n.º 5
0
 private static bool IsAnyOverride(NetPropertyDefinition prop)
 {
     return (prop.Getter != null && prop.Getter.IsOverride)
         || (prop.Setter != null && prop.Setter.IsOverride);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Should the given property be excluded from fixup?
 /// </summary>
 private static bool DoNotFixOverridenProperty(NetPropertyDefinition prop)
 {
     return (prop.Name == "Adapter");
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Build properties for the given type
        /// </summary>
        internal void BuildProperties(TargetFramework target, MethodRenamer methodRenamer)
        {
            if (typeDef.IsInterface)
                return;

            var getters = typeDef.Methods.Where(IsGetter).ToList();
            var setters = typeDef.Methods.Where(IsSetter).ToList();
            var generatedNames = new HashSet<string>();

            foreach (var getMethod in getters)
            {
                // Get the name of the property
                var name = GetPropertyName(getMethod);

                // If there are other methods with same name, we do not create a property
                if (typeDef.Methods.Any(x => (x != getMethod) && (x.Name == name)))
                    continue;
                if (typeDef.NestedTypes.Any(x => x.Name == name))
                    continue;
                if (typeDef.Name == name)
                    continue;
                if (typeDef.Fields.Any(x => x.Name == name))
                    continue;
                if (!generatedNames.Add(name + "_" + getMethod.Parameters.Count))
                    continue;

                // Create property
                var prop = new NetPropertyDefinition { Name = name, Getter = getMethod, Description = getMethod.Description };

                AddCustomAttributes(getMethod, prop.CustomAttributes);
                
                // Clone parameters
                if (getMethod.Parameters.Any())
                {
                    prop.Parameters.AddRange(getMethod.Parameters.Select(x => new NetParameterDefinition(x.Name, x.ParameterType, false)));
                    prop.Name = "this";
                }

                // Rename getMethod if needed
                if (getMethod.Name == prop.Name)
                {
                    methodRenamer.Rename(getMethod, "Get" + getMethod.Name);
                }

                // Find setter
                var setMethod = FindSetter(getMethod, setters);
                if (setMethod != null)
                {
                    prop.Setter = setMethod;

                    // Rename setMethod if needed
                    if (setMethod.Name == prop.Name)
                    {
                        methodRenamer.Rename(setMethod, "Set" + setMethod.Name);
                    }
                }

                // Add property
                typeDef.Properties.Add(prop);
            }
        }