private static IGeometryBuilderRenderer Renderer(IGeometryBuilder builder) { var builderType = builder.GetType(); var rendererTypes = typeof(IGeometryBuilderRenderer).Implementors(); foreach (var rendererType in rendererTypes) { var customRenderer = rendererType.Attribute <CustomRenderer>(); if (null == customRenderer) { continue; } if (customRenderer.Type == builderType) { try { var customRendererInstance = (IGeometryBuilderRenderer)Activator.CreateInstance(rendererType); return(customRendererInstance); } catch { Debug.LogError(string.Format( "Could not instantiate custom IGeometryBuilderRenderer {0}. Does it have a public default constructor?", rendererType)); break; } } } return(new StandardGeometryBuilderRenderer()); }
private static string Description(IGeometryBuilder builder) { var builderType = builder.GetType(); var customName = builderType.Attribute <DescriptionAttribute>(); if (null != customName) { return(customName.Description); } return("[No description]"); }
private static string Name(IGeometryBuilder builder) { var builderType = builder.GetType(); var customName = builderType.Attribute <DisplayNameAttribute>(); if (null != customName) { return(customName.DisplayName); } return(builderType.Name); }
/// <summary> /// Retrieves a factory. /// </summary> /// <param name="builder"></param> /// <param name="factories"></param> /// <returns></returns> private static MethodInfo Factory( IGeometryBuilder builder, MethodInfo[] factories) { foreach (var method in factories) { var attribute = method.Attribute <CustomFactory>(); if (null != attribute && attribute.Type == builder.GetType()) { return(method); } } return(typeof(GeometryProvider).GetMethod( "DefaultFactory", BindingFlags.Static | BindingFlags.NonPublic)); }