private void ProcessRecord(TypeInfoRecord record)
 {
     if (record.TypeFullName.Contains("[["))
     {
         throw new NotImplementedException();
     }
 }
 void AddTypeRenRefs(TypeReference type, TypeReference root, TypeInfoRecord rec)
 {
     if (type is TypeSpecification)
     {
         AddTypeRenRefs((type as TypeSpecification).ElementType, root, rec);
         if (type is RequiredModifierType)
         {
             AddTypeRenRefs((type as RequiredModifierType).ModifierType, root, rec);
         }
         else if (type is OptionalModifierType)
         {
             AddTypeRenRefs((type as OptionalModifierType).ModifierType, root, rec);
         }
         else if (type is GenericInstanceType)
         {
             foreach (var i in (type as GenericInstanceType).GenericArguments)
             {
                 AddTypeRenRefs(i, root, rec);
             }
         }
     }
     else
     {
         TypeDefinition typeDef = type.Resolve();
         if (typeDef != null && (typeDef as IAnnotationProvider).Annotations[RenRef] != null)
         {
             type.Scope = typeDef.Scope;
             ((typeDef as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(new BamlTypeReference(rec, type, root));
         }
     }
 }
Exemple #3
0
        public ResourcePart(DictionaryEntry entry)
        {
            name   = (string)entry.Key;
            stream = (Stream)entry.Value;

            if (Path.GetExtension(name) != ".baml")
            {
                return;
            }

            baml            = BamlReader.ReadDocument(stream);
            stream.Position = 0;

            foreach (BamlRecord record in baml)
            {
                if (record.Type == BamlRecordType.TypeInfo)
                {
                    TypeInfoRecord typeInfo = (TypeInfoRecord)record;

                    typeName = typeInfo.TypeFullName;
                    break;
                }

                if (record.Type == BamlRecordType.ElementStart)
                {
                    break;
                }
            }
        }
 private void ProcessRecord(TypeInfoRecord record, AssemblyDefinition containingAssembly)
 {
     if (record == null)
     {
         return;
     }
     record.TypeFullName = RemoveTypeAssemblyInformation(record.TypeFullName);
 }
Exemple #5
0
        void DisassembleRecord(BamlContext ctx, TypeInfoRecord record)
        {
            WriteText("TypeId=");
            WriteHexNumber(record.TypeId);

            WriteText(", AssemblyId=");
            WriteAssemblyId(ctx, record.AssemblyId);

            WriteText(", TypeFullName=");
            WriteDefinition(record.TypeFullName);
        }
Exemple #6
0
 void AddTypeRenRefs(TypeReference type, TypeReference root, TypeInfoRecord rec)
 {
     if (type is TypeSpecification)
     {
         AddTypeRenRefs((type as TypeSpecification).ElementType, root, rec);
         if (type is RequiredModifierType)
             AddTypeRenRefs((type as RequiredModifierType).ModifierType, root, rec);
         else if (type is OptionalModifierType)
             AddTypeRenRefs((type as OptionalModifierType).ModifierType, root, rec);
         else if (type is GenericInstanceType)
             foreach (var i in (type as GenericInstanceType).GenericArguments)
                 AddTypeRenRefs(i, root, rec);
     }
     else
     {
         TypeDefinition typeDef = type.Resolve();
         if (typeDef != null && (typeDef as IAnnotationProvider).Annotations[RenRef] != null)
         {
             type.Scope = typeDef.Scope;
             ((typeDef as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(new BamlTypeReference(rec, type, root));
         }
     }
 }
Exemple #7
0
 public BAMLTypeReference(TypeSig sig, TypeInfoRecord rec)
 {
     this.sig = sig;
     this.rec = rec;
 }
Exemple #8
0
 private void ProcessRecord(TypeInfoRecord record)
 {
     record.TypeFullName = RemoveTypeAssemblyInformation(record.TypeFullName);
 }
 public BamlTypeReference(TypeInfoRecord typeRec, TypeReference self, TypeReference root)
 {
     this.typeRec = typeRec;
     this.self    = self;
     this.root    = root;
 }
Exemple #10
0
 public BamlTypeReference(TypeInfoRecord typeRec, TypeReference self, TypeReference root)
 {
     this.typeRec = typeRec;
     this.self = self;
     this.root = root;
 }
Exemple #11
0
        private void WalkBaml(ResourcePart part)
        {
            Dictionary <string, string> namespaces = new Dictionary <string, string>();

            foreach (BamlRecord record in part.Baml)
            {
                if (record.Type == BamlRecordType.TypeInfo)
                {
                    TypeInfoRecord typeInfo = (TypeInfoRecord)record;

                    TypeDefinition type;
                    if (typesMap.TryGetValue(typeInfo.TypeFullName, out type))
                    {
                        AddUsedType(type);
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.XmlnsProperty)
                {
                    XmlnsPropertyRecord ns            = (XmlnsPropertyRecord)record;
                    const string        CLR_NAMESPACE = "clr-namespace:";
                    if (ns.XmlNamespace.StartsWith(CLR_NAMESPACE))
                    {
                        namespaces.Add(ns.Prefix, ns.XmlNamespace.Substring(CLR_NAMESPACE.Length));
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.Text)
                {
                    TextRecord textRecord = (TextRecord)record;

                    int index = textRecord.Value.IndexOf(':');
                    if (index == -1)
                    {
                        continue; // not ns reference
                    }
                    string name;
                    if (!namespaces.TryGetValue(textRecord.Value.Substring(0, index), out name))
                    {
                        continue;
                    }

                    name += "." + textRecord.Value.Substring(index + 1);

                    TypeDefinition type;

                    // type as string?
                    if (typesMap.TryGetValue(name, out type))
                    {
                        AddUsedType(type);
                        continue;
                    }

                    index = name.LastIndexOf(".", StringComparison.InvariantCulture);

                    // member?
                    if (typesMap.TryGetValue(name.Substring(0, index), out type))
                    {
                        AddUsedType(type);
                    }

                    continue;
                }

                if (record.Type == BamlRecordType.PropertyWithConverter)
                {
                    PropertyWithConverterRecord propertyInfo = (PropertyWithConverterRecord)record;

                    string resourceName = propertyInfo.Value;

                    if (resourceName.StartsWith(wpfPathPrefix))
                    {
                        resourceName = resourceName.Substring(wpfPathPrefix.Length, resourceName.Length - wpfPathPrefix.Length);
                    }

                    if (resourceName.EndsWith(".xaml", StringComparison.InvariantCultureIgnoreCase))
                    {
                        resourceName = resourceName.Substring(0, resourceName.Length - 4) + "baml";
                    }

                    resourceName = resourceName.ToLower();

                    ResourcePart resourcePart;
                    if (!wpfRootParts.TryGetValue(resourceName, out resourcePart))
                    {
                        continue;
                    }

                    if (resourcePart.Baml != null)
                    {
                        AddUsedBaml(resourcePart);
                    }
                    else
                    {
                        Log($"WPF resource used: {resourceName}");
                        usedWpfResources.Add(resourceName);
                    }
                }
            }
        }
Exemple #12
0
 public BamlTypeReference(TypeInfoRecord typeRec)
 {
     this.typeRec = typeRec;
 }