Inheritance: MemberReference
 public CecilDictionaryEntityNames(PropertyReference property)
     : base(
         property.DeclaringType.Namespace,
         property.DeclaringType.Name,
         property.Name,
         property.DeclaringType.Module.Assembly.Name.Name)
 {
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a new property name mapping.
 /// </summary>
 /// <param name="property">The original property reference.</param>
 /// <param name="obfuscatedPropertyName">Name of the obfuscated property.</param>
 public void AddPropertyMapping(PropertyReference property, string obfuscatedPropertyName)
 {
     if (property == null) throw new ArgumentNullException("property");
     string propertyName = property.Name;
     if (!properties.ContainsKey(propertyName))
     {
         properties.Add(propertyName, new MemberMapping(propertyName, obfuscatedPropertyName));
         obfuscatedProperties.Add(obfuscatedPropertyName, property);
     }
 }
Ejemplo n.º 3
0
        public static bool AreSame(PropertyReference a, PropertyReference b)
        {
            if (a.Name != b.Name)
                return false;

            if (!AreSame(a.PropertyType, b.PropertyType))
                return false;

            if (!AreSame(a.DeclaringType, b.DeclaringType))
                return false;

            if (!AreSame(a.Parameters, b.Parameters))
                return false;

            return true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the converted name of the given property.
 /// </summary>
 public static string GetConvertedName(PropertyReference property)
 {
     var name = property.Name;
     var originalName = name;
     name = name.Replace('<', '_');
     name = name.Replace('>', '_');
     if (name != originalName)
     {
         // Add hash to ensure unique
         name = name + GetHashPostfix(originalName);
     }
     return name;
 }
Ejemplo n.º 5
0
 void addPropertyReference(PropertyReference propertyReference)
 {
     if (propertyReference == null)
         return;
     addMemberReference(propertyReference);
     pushMember(propertyReference.PropertyType);
 }
Ejemplo n.º 6
0
 private static string Format(PropertyReference property)
 {
     var sb = new StringBuilder();
     sb.Append(CecilFormat.GetTypeName(property.DeclaringType));
     sb.Append('.');
     sb.Append(property.Name);
     return sb.ToString();
 }
Ejemplo n.º 7
0
 private void MergeReference(DeepCopier copier, PropertyReference @ref1, PropertyReference @re2)
 {
 }
Ejemplo n.º 8
0
        private static void CreateWellName(PropertyReference pr)
        {
            var name = CleanName(pr.Name);
            var start = name.IndexOf(NONWELLFLAG);
            if (start == -1 && pr.Parameters.Count == 0)
            {
                if (IsNameRepeated(pr.DeclaringType, name)) name += "_" + GetShortName(pr.PropertyType);
            }
            else
            {
                var pd = pr.Resolve();
                if (pd != null)
                {
                    var pdJust = pd;
                    var accessor = pd.GetMethod ?? pd.SetMethod;
                    if (accessor != null && accessor.HasOverrides)
                    {
                        var baseAccessor = accessor.Overrides.First().Resolve();
                        pdJust = baseAccessor.DeclaringType.Properties.First(x => x.GetMethod == baseAccessor || x.SetMethod == baseAccessor);
                        name = baseAccessor.Name.Substring(4);
                        start = name.IndexOf(NONWELLFLAG);
                    }
                    else
                    {
                        // 重载属性,但没有 Overrides ?????
                    }

                    if (pd.HasParameters)
                    {
                        // 将具有参数的缺省属性修改为索引器
                        //[DefaultMember("Item")]
                        //public class MyClass
                        //{
                        //    public double P_1_double
                        //    {
                        //        get { switch (e_1) { …… } }
                        //        set { switch (e_1) { …… } }
                        //    }
                        //    ……
                        //}
                        //====>
                        //public class MyClass
                        //{
                        //    public double this[int e_1]
                        //    {
                        //        get { switch (e_1) { …… } }
                        //        set { switch (e_1) { …… } }
                        //    }
                        //    ……
                        //}
                        pr.mWellName = GetDefaultMemberName(pdJust.DeclaringType) ?? "Item";
                        return;
                    }
                }

                if (start >= 0) name = Replace(name, start, 1, "P") + "_" + GetShortName(pr.PropertyType);
            }
            pr.mWellName = Regex.Replace(name, @"\W", "_");
        }
Ejemplo n.º 9
0
 public PropertyReferenceKey(PropertyReference propRef)
 {
     this.propRef = propRef;
 }
Ejemplo n.º 10
0
 public static bool comparePropertyReference(PropertyReference a, PropertyReference b)
 {
     if (ReferenceEquals(a, b))
         return true;
     if (a == null || b == null)
         return false;
     if ((a.Parameters == null && b.Parameters != null) || (a.Parameters != null && b.Parameters == null))
         return false;
     if (a.Parameters != null) {
         if (a.Parameters.Count != b.Parameters.Count)
             return false;
         for (int i = 0; i < a.Parameters.Count; i++) {
             if (!compareTypes(a.Parameters[i].ParameterType, b.Parameters[i].ParameterType))
                 return false;
         }
     }
     return a.Name == b.Name &&
         compareTypes(a.PropertyType, b.PropertyType);
 }
Ejemplo n.º 11
0
 public override void VisitPropertyReference(PropertyReference property)
 {
     var propertyReference = property;
     var scope = GetAssemblyNameReference(propertyReference.DeclaringType.Scope);
     MapReference(scope, propertyReference);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets the name of the obfuscated property.
 /// </summary>
 /// <param name="property">The original property reference.</param>
 /// <returns></returns>
 public string GetObfuscatedPropertyName(PropertyReference property)
 {
     if (property == null) throw new ArgumentNullException("property");
     if (HasPropertyMapping(property))
     {
         string propertyName = property.Name;
         return properties[propertyName].ObfuscatedMemberName;
     }
     return null;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Determines whether a property mapping exists for the specified property name.
 /// </summary>
 /// <param name="property">The original property reference.</param>
 /// <returns>
 /// 	<c>true</c> if a property mapping exists; otherwise, <c>false</c>.
 /// </returns>
 public bool HasPropertyMapping(PropertyReference property)
 {
     if (property == null) throw new ArgumentNullException("property");
     string propertyName = property.Name;
     return properties.ContainsKey(propertyName);
 }
 protected override string GetPropertyName(PropertyReference property)
 {
     return (writerContext == null || writerContext.ModuleContext.Module == null) ? property.Name : base.GetPropertyName(property);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Are the given properties the same?
 /// </summary>
 public static bool AreSame(this PropertyReference a, PropertyReference b, Func<GenericParameter, TypeReference> genericParamResolver)
 {
     var parametersA = a.Parameters;
     var parametersB = b.Parameters;
     if (parametersA.Count != parametersB.Count) 
         return false; 
     if (a.Name != b.Name)  
         return false; 
     if (!a.PropertyType.AreSame(b.PropertyType, genericParamResolver))  
         return false; 
     if (!parametersA.AreSame(parametersB, genericParamResolver)) 
         return false; 
     return true;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// A cecil property reference will be directed to this method.
 /// </summary>
 /// <param name="item">Cecil reference.</param>
 /// <param name="resolvedItem">Output parameter that will be populated with the resolved cecil definition.</param>
 /// <returns><c>true</c></returns>
 private static bool TryResolve(PropertyReference item, out object resolvedItem)
 {
     resolvedItem = item.Resolve();
     return true;
 }
        public static string Disassemble(DomCecilMethod method, bool markup)
        {
            if (method.MethodDefinition.IsPInvokeImpl)
            {
                return(GettextCatalog.GetString("Method is P/Invoke"));
            }
            if (method.MethodDefinition.Body == null)
            {
                IType type = method.DeclaringType;
                return(type == null ||  type.ClassType == ClassType.Interface ? GettextCatalog.GetString("Interface method") : GettextCatalog.GetString("Abstract method"));
            }

            StringBuilder result = new StringBuilder();

            foreach (Instruction instruction in method.MethodDefinition.Body.Instructions)
            {
                if (markup)
                {
                    result.Append("<b>");
                }
                result.Append(GetInstructionOffset(instruction));
                result.Append(markup ? ":</b> " : ": ");
                result.Append(instruction.OpCode);
                if (markup)
                {
                    result.Append("<i>");
                }
                if (instruction.Operand != null)
                {
                    result.Append(' ');
                    if (instruction.Operand is string)
                    {
                        result.Append('"');
                        result.Append(AssemblyBrowserWidget.FormatText(instruction.Operand.ToString()));
                        result.Append('"');
                    }
                    else if (instruction.Operand is Mono.Cecil.Cil.Instruction)
                    {
                        result.Append(GetInstructionOffset((Mono.Cecil.Cil.Instruction)instruction.Operand));
                    }
                    else if (instruction.Operand is Mono.Cecil.TypeDefinition)
                    {
                        AppendLink(result,
                                   new DomCecilType((Mono.Cecil.TypeDefinition)instruction.Operand).HelpUrl,
                                   instruction.Operand.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.MethodDefinition)
                    {
                        Mono.Cecil.MethodDefinition md = instruction.Operand as Mono.Cecil.MethodDefinition;
                        AppendLink(result,
                                   new DomCecilMethod(md)
                        {
                            DeclaringType = new DomCecilType(md.DeclaringType)
                        }.HelpUrl,
                                   instruction.Operand.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.FieldDefinition)
                    {
                        Mono.Cecil.FieldDefinition fd = instruction.Operand as Mono.Cecil.FieldDefinition;
                        AppendLink(result,
                                   new DomCecilField(fd)
                        {
                            DeclaringType = new DomCecilType(fd.DeclaringType)
                        }.HelpUrl,
                                   instruction.Operand.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.PropertyDefinition)
                    {
                        Mono.Cecil.PropertyDefinition pd = instruction.Operand as Mono.Cecil.PropertyDefinition;
                        AppendLink(result,
                                   new DomCecilProperty(pd)
                        {
                            DeclaringType = new DomCecilType(pd.DeclaringType)
                        }.HelpUrl,
                                   instruction.Operand.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.TypeReference)
                    {
                        AppendLink(result,
                                   "T:" + ((TypeReference)instruction.Operand).FullName,
                                   instruction.Operand.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.MethodReference)
                    {
                        Mono.Cecil.MethodReference mr = instruction.Operand as Mono.Cecil.MethodReference;
                        StringBuilder id            = new StringBuilder(mr.DeclaringType.ToString());
                        bool          isConstructor = mr.Name == ".ctor";
                        if (!isConstructor)
                        {
                            id.Append("." + mr.Name);
                        }
                        id.Append("(");
                        for (int i = 0; i < mr.Parameters.Count; i++)
                        {
                            if (i > 0)
                            {
                                id.Append(',');
                            }
                            id.Append(mr.Parameters[i].ParameterType.FullName);
                        }
                        id.Append(")");
                        AppendLink(result, (isConstructor ? "C:" : "M:") + id, id.ToString());
                    }
                    else if (instruction.Operand is Mono.Cecil.FieldReference)
                    {
                        Mono.Cecil.FieldReference fr = instruction.Operand as Mono.Cecil.FieldReference;
                        string id = fr.DeclaringType + "." + fr.Name;
                        AppendLink(result, "F:" + id, id);
                    }
                    else if (instruction.Operand is Mono.Cecil.PropertyReference)
                    {
                        Mono.Cecil.PropertyReference pr = instruction.Operand as Mono.Cecil.PropertyReference;
                        string id = pr.DeclaringType + "." + pr.Name;
                        AppendLink(result, "P:" + id, id);
                    }
                    else
                    {
                        result.Append(AssemblyBrowserWidget.FormatText(instruction.Operand.ToString()));
                    }
                }
                if (markup)
                {
                    result.Append("</i>");
                }
                result.AppendLine();
            }
            result.AppendLine();
            return(result.ToString());
        }
Ejemplo n.º 18
0
        public static int propertyReferenceHashCode(PropertyReference a)
        {
            if (a == null)
                return 0;
            int res = 0;

            if (a.Parameters != null) {
                res += a.Parameters.Count.GetHashCode();
                foreach (var param in a.Parameters)
                    res += typeHashCode(param.ParameterType);
            }

            res += a.Name.GetHashCode();
            res += typeHashCode(a.PropertyType);
            return res;
        }
		public PropertyReferenceExpression (Expression target, PropertyReference property)
		{
			_target = target;
			_property = property;
		}
Ejemplo n.º 20
0
 public ScopeAndTokenKey(PropertyReference prop)
     : this(prop.DeclaringType == null ? null : prop.DeclaringType.Scope, prop.MetadataToken.ToInt32())
 {
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Mark all eachable items in argument as such.
        /// </summary>
        private static void Walk(ReachableContext context, PropertyReference prop)
        {
            prop.PropertyType.MarkReachable(context);

            // Parameters
            if (prop.Parameters.Count > 0)
            {
                foreach (ParameterDefinition param in prop.Parameters)
                {
                    Walk(context, (ParameterReference)param);
                }
            }

            var propDef = prop as PropertyDefinition;
            if (propDef != null)
            {
                // DO NOT AUTOMATICALLY MAKE GET and SET REACHABLE.
                //propDef.GetMethod.MarkReachable(context);
                //propDef.SetMethod.MarkReachable(context);

                // Custom attributes
                Walk(context, (ICustomAttributeProvider)propDef);
            }
            else
            {
                // Try to resolve
                prop.Resolve(context).MarkReachable(context);
            }
        }
Ejemplo n.º 22
0
 public virtual TypeReference Import(PropertyReference property)
 {
     return AssemblyDefinition.MainModule.Import(property.PropertyType);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Mark all reachable items in argument as such.
        /// </summary>
        private static void Walk(ReachableContext context, PropertyReference prop)
        {
            prop.PropertyType.MarkReachable(context, prop.IsUsedInSerialization);

            // Parameters
            if (prop.Parameters.Count > 0)
            {
                foreach (ParameterDefinition param in prop.Parameters)
                {
                    Walk(context, (ParameterReference)param);
                }
            }

            var propDef = prop as PropertyDefinition;
            if (propDef != null)
            {
                // DO NOT AUTOMATICALLY MAKE GET and SET REACHABLE.
                // (but do so for attributes, so that they can 
                //  be properly stored and loaded)
                if (prop.DeclaringType.Resolve().IsAttribute())
                {
                    propDef.GetMethod.MarkReachable(context);
                    propDef.SetMethod.MarkReachable(context);
                }
                else if (prop.IsUsedInSerialization || propDef.IsUsedInSerialization)
                {
                    propDef.GetMethod.MarkReachable(context);
                    propDef.SetMethod.MarkReachable(context);
                }
                // Custom attributes
                Walk(context, (ICustomAttributeProvider)propDef);
            }
            else
            {
                // Try to resolve
                prop.Resolve(context).MarkReachable(context, prop.IsUsedInSerialization);
            }
        }
 private IEnumerable<ProjectReference> GetPropertyParametersReferences(
     PropertyReference propertyReference, AuditEntryParameters parameters)
 {
     foreach(var projectReference in GetTypeReferences(propertyReference.PropertyType, parameters))
         yield return projectReference;
     foreach (var paramDefinition in propertyReference.Parameters)
     {
         foreach(var projectReference in
                 GetTypeReferences(paramDefinition.ParameterType, parameters))
             yield return projectReference;
     }
 }
Ejemplo n.º 25
0
 public static PropertyReference GetTypePropertyDef(TypeDefinition destType, PropertyReference origProperty)
 {
     return GetTypePropertyDef(destType, origProperty.Name, origProperty.PropertyType.FullName);
 }
Ejemplo n.º 26
0
 public PropertyRef(PropertyReference propertyReference, TypeDef owner, int index)
     : base(propertyReference, owner, index)
 {
 }
        internal PropertyInfo ResolveProperty(PropertyReference reference)
        {
            Type returnType = ResolveType(reference.PropertyType);
            Type[] parameterTypes = ResolveParameterTypes(reference.Parameters);

            Type type = ResolveType(reference.DeclaringType);
            return GetProperty(type, reference.Name, returnType, parameterTypes);
        }
Ejemplo n.º 28
0
 public PropertyDef findAny(PropertyReference pr)
 {
     return properties.findAny(pr);
 }
		public PropertyReferenceExpression (Expression target, PropertyReference property)
		{
			this.target = target;
			this.property = property;
		}
        protected virtual string GetPropertyName(PropertyReference property)
        {
            PropertyDefinition propertyDefinition = property.Resolve();

            if (propertyDefinition != null && propertyDefinition.Module.FilePath == this.ModuleContext.Module.FilePath)
            {
                try
                {
                    return this.ModuleContext.RenamedMembersMap[propertyDefinition.MetadataToken.ToUInt32()];
                }
                catch (Exception ex)
                {
                    Write(propertyDefinition.MetadataToken.ToUInt32().ToString());
                    WriteLine();
                    Write(ModuleContext.RenamedMembersMap.Count.ToString());
                    WriteLine();
                    foreach (KeyValuePair<uint, string> pair in ModuleContext.RenamedMembersMap)
                    {
                        Write(pair.Key.ToString() + " " + pair.Value);
                        WriteLine();
                    }
                    throw ex;
                }
            }

            return Utilities.EscapeName(GenericHelper.GetNonGenericName(property.Name), this.Language);
        }
Ejemplo n.º 31
0
 public static PropertyDefinition TryResolve(this ModuleDefinition scope, PropertyReference propertyRef)
 {
     var matchingType = TryResolve(scope, propertyRef.DeclaringType);
     if (matchingType == null) {
         return null;
     }
     return matchingType.Properties.FirstOrDefault(e => e.Name == propertyRef.Name);
 }