private void Analyze(BuildField field)
        {
            if (field.IsStatic &&
                field.Name.EndsWith("Property") &&
                IsDependencyPropertyType(field.FieldType))
            {
                field.Rename = false;
                field.Strip  = false;

                var    ownerType = (BuildType)field.GetOwnerType();
                string name      = field.Name.Substring(0, field.Name.Length - 8);            // Remove 'Property' suffix

                // Fix methods used by extension properties
                foreach (BuildMethod method in ownerType.Methods)
                {
                    if ((method.Name == "Get" + name) || (method.Name == "Set" + name))
                    {
                        method.Rename = false;
                        method.Strip  = false;
                    }
                }

                // Fix properties releated to this dependency property
                foreach (BuildProperty property in ownerType.Properties)
                {
                    if (property.Name == name)
                    {
                        property.Rename = false;
                        property.Strip  = false;
                    }
                }
            }
        }
Example #2
0
 public static void Change(BuildField field)
 {
     if (field.NameChanged)
     {
         field.Name = field.NewName;
     }
 }
		private bool Build(ref FieldReference fieldRef, BuildField field)
		{
			bool changed = false;

			// Name
			string name;
			if (field.NameChanged)
			{
				name = field.NewName;
				changed = true;
			}
			else
			{
				name = field.Name;
			}

			// Field type
			var fieldType = fieldRef.FieldType;
			changed |= Build(ref fieldType);

			// Owner
			var owner = fieldRef.Owner;
			changed |= Build(ref owner);

			if (!changed)
				return false;

			fieldRef = new FieldReference(name, fieldType, owner);
			return true;
		}
 private void UnstripAndEnqueue(BuildField field)
 {
     if (field.Strip)
     {
         field.Strip = false;
         Enqueue(field);
     }
 }
 private void Enqueue(BuildField field)
 {
     if (!field.StripProcessed)
     {
         field.StripProcessed = true;
         _queue.Enqueue(field);
     }
 }
 private static void Unmark(BuildField field)
 {
     if (field.Strip)
     {
         field.Rename                    = false;
         field.ObfuscateStrings          = false;
         field.StripObfuscationAttribute = false;
         field.NameChanged               = false;
     }
 }
        private void Process(BuildField field)
        {
            UnstripAndEnqueue((BuildType)field.GetOwnerType());

            // Process references
            var module = field.Module;

            Process(field.FieldType, module);
            Process(field.CustomAttributes, module);
        }
Example #8
0
        private void Analyze(BuildField field)
        {
            var attr = CA.BindableAttribute.FindFirst(field.CustomAttributes);

            if (attr != null && attr.Bindable)
            {
                if (!_renameBindableMembers)
                {
                    field.Rename = false;
                }

                field.Strip = false;
            }
        }
Example #9
0
        private void Analyze(BuildField field, bool serializable)
        {
            LoadSerializableAttributes(ref serializable, field.CustomAttributes);

            if (serializable)
            {
                if (!_renameSerializableMembers)
                {
                    field.Rename = false;
                }

                field.Strip = false;
            }
        }
		private bool MapCustomAttributeFieldArgument(
			ref CustomAttributeNamedArgument argument,
			BuildField field)
		{
			if (!field.NameChanged)
				return false;

			argument = new CustomAttributeNamedArgument(
				field.NewName,
				argument.Type,
				argument.TypedValue);

			return true;
		}
        private void Obfuscate(BuildField field)
        {
            if (!field.ObfuscateStrings)
            {
                return;
            }

            if (!field.DefaultValue.HasValue)
            {
                return;
            }

            var constantInfo = field.DefaultValue.Value;

            if (constantInfo.Type != ConstantType.String)
            {
                return;
            }

            var ownerType = field.GetOwnerType();

            var method = ownerType.Methods.GetOrCreateStaticConstructor();

            if (!MethodBody.IsValid(method))
            {
                return;
            }

            var methodBody = MethodBody.Load(method);

            var instructions = methodBody.Instructions;

            int index = AddString((string)constantInfo.Value);

            instructions.InsertRange(
                0,
                new Instruction[]
            {
                new Instruction(OpCodes.Ldsfld, _stringFieldRef),
                Instruction.GetLdc(index),
                new Instruction(OpCodes.Ldelem_Ref),
                new Instruction(OpCodes.Stsfld, field.ToReference(field.Module)),
            });

            field.IsLiteral    = false;
            field.IsInitOnly   = true;
            field.DefaultValue = null;
        }