- Timestamp:
- 04/28/09 12:45:32 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs
r1679 r1683 53 53 } 54 54 } 55 56 57 [EmptyStorableClass]58 public class StackDecomposer : IDecomposer {59 60 public int Priority {61 get { return 100; }62 }63 64 65 public bool CanDecompose(Type type) {66 return type.IsGenericType &&67 type.GetGenericTypeDefinition() == typeof(Stack<>);68 }69 70 public IEnumerable<Tag> CreateMetaInfo(object o) {71 return new Tag[] { };72 }73 74 public IEnumerable<Tag> Decompose(object obj) {75 foreach (object o in (IEnumerable)obj) {76 yield return new Tag(null, o);77 }78 }79 80 public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) {81 return Activator.CreateInstance(type, true);82 }83 84 public void Populate(object instance, IEnumerable<Tag> tags, Type type) {85 MethodInfo addMethod = type.GetMethod("Push");86 try {87 foreach (var tag in tags)88 addMethod.Invoke(instance, new[] { tag.Value });89 } catch (Exception e) {90 throw new PersistenceException("Exception caught while trying to populate enumerable.", e);91 }92 }93 }94 55 }
Note: See TracChangeset
for help on using the changeset viewer.