internal static MemberDefinition AsMemberDeclaration(FieldDefinition definition) { var declaration = new MemberDefinition(definition.Name, new TypeDefinition()); declaration.Type.Namespace = definition.FieldType.Namespace; declaration.Type.Name = definition.FieldType.FullName.Replace(definition.FieldType.Namespace, string.Empty).Trim('.', ' '); declaration.DefaultValue = definition.Constant; if (definition.IsPublic) { declaration.Traits |= Trait.Public; } if (definition.HasConstant) { declaration.Traits |= Trait.Constant; } if (definition.FieldType.IsPrimitive) { declaration.Type.Traits |= Trait.Primitive; } if (definition.FieldType.IsArray || Pattern.EnumerableType.IsMatch(definition.FieldType.FullName)) { declaration.Type.Traits |= Trait.Array; } return(declaration); }
internal static MemberDefinition AsMemberDeclaration(PropertyDefinition definition) { var declaration = new MemberDefinition(definition.Name, new TypeDefinition()); declaration.Type.Namespace = definition.PropertyType.Namespace; declaration.Type.Name = definition.PropertyType.FullName; if (!string.IsNullOrEmpty(declaration.Type.Namespace)) { declaration.Type.Name = definition.PropertyType.Name.Replace(definition.PropertyType.Namespace, string.Empty).Trim('.', ' '); } declaration.DefaultValue = definition.Constant; declaration.Traits |= Trait.Public; if (definition.PropertyType.IsPrimitive) { declaration.Type.Traits |= Trait.Primitive; } if (definition.PropertyType.IsArray || Pattern.EnumerableType.IsMatch(definition.PropertyType.FullName)) { declaration.Type.Traits |= Trait.Array; } if (definition.DeclaringType.HasInterfaces) { foreach (InterfaceImplementation item in definition.DeclaringType.Interfaces) { if (definition.Name.Contains(item.InterfaceType.Name + '.')) { declaration.Traits |= Trait.Interface; } } } return(declaration); }