public T Copy <T>(IDom part) where T : class { // Copy is an IDom<T> method, and I only have the part as an IDom, thus reflection var method = part.GetType().GetMethod("Copy"); var newItem = method.Invoke(part, null) as T; return(newItem); }
//private Regex matchRegEx = new Regex(@"_xf_(?<part>[_\w]+?)(?<format>_as_\w+)*"); public void DoAlteration(IDom item, MetadataContextStack contextStack) { ReplaceInName(item, contextStack); // TODO: Explore whether to cache this, the same items will be pounded IEnumerable <PropertyInfo> props = item.GetType().GetProperties(); ReplaceInPropertiesNames(item, contextStack, props); ReplaceInText(item, contextStack, props); ReplaceInExpressions(item, contextStack, props); }
public IEnumerable <SyntaxNode> GetSyntaxNodes(IDom item) { if (item == null) { return(new List <SyntaxNode>()); } IRDomFactory factory; if (domTypeLookup.TryGetValue(item.GetType(), out factory)) { var ret = factory.BuildSyntax(item); return(ret); } return(null); }
//public IEnumerable<T> Create<T>(SyntaxNode node, IDom parent, SemanticModel model) // where T : IDom //{ // return FindFactoryAndCreate(typeof(T), explicitNodeLookup, node, parent, model) // .OfType<T>(); //} //private IEnumerable<IDom> FindFactoryAndCreate(Type type, // IDictionary<Type, IRDomFactory> dictionary, // SyntaxNode node, IDom parent, SemanticModel model) //{ // var factory = GetFactory(type, dictionary, node, parent, model); // if (factory == null) // { // return createFromWorker.CreateInvalidMembers(node, parent, model); // } // var items = factory.CreateFrom(node, parent, model, false); // return items.ToList(); //} public IEnumerable <SyntaxNode> GetSyntaxNodes(IDom item) { if (item == null) { return(new List <SyntaxNode>()); } var factory = GetFactory(item.GetType(), domTypeLookup, x => x.CanGetSyntax(item)); if (factory == null) { return(new List <SyntaxNode>()); } var nodes = factory.BuildSyntax(item); return(nodes); }